Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
91246ee5
Commit
91246ee5
authored
Nov 01, 2021
by
Edward Thomson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
path: use new length validation functions
parent
1728e27c
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
36 additions
and
20 deletions
+36
-20
src/attrcache.c
+7
-2
src/checkout.c
+3
-3
src/filter.c
+2
-1
src/ignore.c
+3
-2
src/iterator.c
+12
-5
src/mailmap.c
+2
-1
src/refdb_fs.c
+1
-1
src/repository.c
+3
-3
src/submodule.c
+1
-1
src/worktree.c
+2
-1
No files found.
src/attrcache.c
View file @
91246ee5
...
...
@@ -12,6 +12,7 @@
#include "config.h"
#include "sysdir.h"
#include "ignore.h"
#include "path.h"
GIT_INLINE
(
int
)
attr_cache_lock
(
git_attr_cache
*
cache
)
{
...
...
@@ -43,6 +44,7 @@ int git_attr_cache__alloc_file_entry(
const
char
*
path
,
git_pool
*
pool
)
{
git_str
fullpath_str
=
GIT_STR_INIT
;
size_t
baselen
=
0
,
pathlen
=
strlen
(
path
);
size_t
cachesize
=
sizeof
(
git_attr_file_entry
)
+
pathlen
+
1
;
git_attr_file_entry
*
ce
;
...
...
@@ -66,7 +68,10 @@ int git_attr_cache__alloc_file_entry(
}
memcpy
(
&
ce
->
fullpath
[
baselen
],
path
,
pathlen
);
if
(
git_fs_path_validate_workdir_with_len
(
repo
,
ce
->
fullpath
,
pathlen
+
baselen
)
<
0
)
fullpath_str
.
ptr
=
ce
->
fullpath
;
fullpath_str
.
size
=
pathlen
+
baselen
;
if
(
git_path_validate_str_length
(
repo
,
&
fullpath_str
)
<
0
)
return
-
1
;
ce
->
path
=
&
ce
->
fullpath
[
baselen
];
...
...
@@ -173,7 +178,7 @@ static int attr_cache_lookup(
git_str
*
p
=
attr_session
?
&
attr_session
->
tmp
:
&
path
;
if
(
git_str_joinpath
(
p
,
source
->
base
,
source
->
filename
)
<
0
||
git_
fs_path_validate_workdir_buf
(
repo
,
p
)
<
0
)
git_
path_validate_str_length
(
repo
,
p
)
<
0
)
return
-
1
;
filename
=
p
->
ptr
;
...
...
src/checkout.c
View file @
91246ee5
...
...
@@ -329,7 +329,7 @@ static int checkout_target_fullpath(
if
(
path
&&
git_str_puts
(
&
data
->
target_path
,
path
)
<
0
)
return
-
1
;
if
(
git_
fs_path_validate_workdir_buf
(
data
->
repo
,
&
data
->
target_path
)
<
0
)
if
(
git_
path_validate_str_length
(
data
->
repo
,
&
data
->
target_path
)
<
0
)
return
-
1
;
*
out
=
&
data
->
target_path
;
...
...
@@ -2035,7 +2035,7 @@ static int checkout_merge_path(
int
error
=
0
;
if
((
error
=
git_str_joinpath
(
out
,
data
->
opts
.
target_directory
,
result
->
path
))
<
0
||
(
error
=
git_
fs_path_validate_workdir_buf
(
data
->
repo
,
out
))
<
0
)
(
error
=
git_
path_validate_str_length
(
data
->
repo
,
out
))
<
0
)
return
error
;
/* Most conflicts simply use the filename in the index */
...
...
@@ -2338,7 +2338,7 @@ static int validate_target_directory(checkout_data *data)
{
int
error
;
if
((
error
=
git_
fs_path_validate_workdir
(
data
->
repo
,
data
->
opts
.
target_directory
))
<
0
)
if
((
error
=
git_
path_validate_length
(
data
->
repo
,
data
->
opts
.
target_directory
))
<
0
)
return
error
;
if
(
git_fs_path_isdir
(
data
->
opts
.
target_directory
))
...
...
src/filter.c
View file @
91246ee5
...
...
@@ -18,6 +18,7 @@
#include "blob.h"
#include "attr_file.h"
#include "array.h"
#include "path.h"
struct
git_filter_source
{
git_repository
*
repo
;
...
...
@@ -1095,7 +1096,7 @@ int git_filter_list_stream_file(
if
((
error
=
stream_list_init
(
&
stream_start
,
&
filter_streams
,
filters
,
target
))
<
0
||
(
error
=
git_fs_path_join_unrooted
(
&
abspath
,
path
,
base
,
NULL
))
<
0
||
(
error
=
git_
fs_path_validate_workdir_buf
(
repo
,
&
abspath
))
<
0
)
(
error
=
git_
path_validate_str_length
(
repo
,
&
abspath
))
<
0
)
goto
done
;
initialized
=
1
;
...
...
src/ignore.c
View file @
91246ee5
...
...
@@ -13,6 +13,7 @@
#include "fs_path.h"
#include "config.h"
#include "wildmatch.h"
#include "path.h"
#define GIT_IGNORE_INTERNAL "[internal]exclude"
...
...
@@ -320,14 +321,14 @@ int git_ignore__for_path(
(
error
=
git_fs_path_resolve_relative
(
&
local
,
0
))
<
0
||
(
error
=
git_fs_path_to_dir
(
&
local
))
<
0
||
(
error
=
git_str_joinpath
(
&
ignores
->
dir
,
workdir
,
local
.
ptr
))
<
0
||
(
error
=
git_
fs_path_validate_workdir_buf
(
repo
,
&
ignores
->
dir
))
<
0
)
{
(
error
=
git_
path_validate_str_length
(
repo
,
&
ignores
->
dir
))
<
0
)
{
/* Nothing, we just want to stop on the first error */
}
git_str_dispose
(
&
local
);
}
else
{
if
(
!
(
error
=
git_str_joinpath
(
&
ignores
->
dir
,
path
,
""
)))
error
=
git_
fs_path_validate_filesystem
(
ignores
->
dir
.
ptr
,
ignores
->
dir
.
size
);
error
=
git_
path_validate_str_length
(
NULL
,
&
ignores
->
dir
);
}
if
(
error
<
0
)
...
...
src/iterator.c
View file @
91246ee5
...
...
@@ -9,6 +9,7 @@
#include "tree.h"
#include "index.h"
#include "path.h"
#define GIT_ITERATOR_FIRST_ACCESS (1 << 15)
#define GIT_ITERATOR_HONOR_IGNORES (1 << 16)
...
...
@@ -1279,7 +1280,7 @@ static int filesystem_iterator_entry_hash(
iter
->
base
.
repo
,
entry
->
path
,
GIT_OBJECT_BLOB
,
NULL
);
if
(
!
(
error
=
git_str_joinpath
(
&
fullpath
,
iter
->
root
,
entry
->
path
))
&&
!
(
error
=
git_
fs_path_validate_workdir_buf
(
iter
->
base
.
repo
,
&
fullpath
)))
!
(
error
=
git_
path_validate_str_length
(
iter
->
base
.
repo
,
&
fullpath
)))
error
=
git_odb_hashfile
(
&
entry
->
id
,
fullpath
.
ptr
,
GIT_OBJECT_BLOB
);
git_str_dispose
(
&
fullpath
);
...
...
@@ -1361,7 +1362,7 @@ static int filesystem_iterator_frame_push(
git_str_puts
(
&
root
,
iter
->
root
);
if
(
git_str_oom
(
&
root
)
||
git_
fs_path_validate_workdir_buf
(
iter
->
base
.
repo
,
&
root
)
<
0
)
{
git_
path_validate_str_length
(
iter
->
base
.
repo
,
&
root
)
<
0
)
{
error
=
-
1
;
goto
done
;
}
...
...
@@ -1389,10 +1390,16 @@ static int filesystem_iterator_frame_push(
while
((
error
=
git_fs_path_diriter_next
(
&
diriter
))
==
0
)
{
iterator_pathlist_search_t
pathlist_match
=
ITERATOR_PATHLIST_FULL
;
git_str
path_str
=
GIT_STR_INIT
;
bool
dir_expected
=
false
;
if
((
error
=
git_fs_path_diriter_fullpath
(
&
path
,
&
path_len
,
&
diriter
))
<
0
||
(
error
=
git_fs_path_validate_workdir_with_len
(
iter
->
base
.
repo
,
path
,
path_len
))
<
0
)
if
((
error
=
git_fs_path_diriter_fullpath
(
&
path
,
&
path_len
,
&
diriter
))
<
0
)
goto
done
;
path_str
.
ptr
=
(
char
*
)
path
;
path_str
.
size
=
path_len
;
if
((
error
=
git_path_validate_str_length
(
iter
->
base
.
repo
,
&
path_str
))
<
0
)
goto
done
;
GIT_ASSERT
(
path_len
>
iter
->
root_len
);
...
...
@@ -1565,7 +1572,7 @@ static int filesystem_iterator_is_dir(
}
if
((
error
=
git_str_joinpath
(
&
fullpath
,
iter
->
root
,
entry
->
path
))
<
0
||
(
error
=
git_
fs_path_validate_workdir_buf
(
iter
->
base
.
repo
,
&
fullpath
))
<
0
||
(
error
=
git_
path_validate_str_length
(
iter
->
base
.
repo
,
&
fullpath
))
<
0
||
(
error
=
p_stat
(
fullpath
.
ptr
,
&
st
))
<
0
)
goto
done
;
...
...
src/mailmap.c
View file @
91246ee5
...
...
@@ -16,6 +16,7 @@
#include "git2/revparse.h"
#include "blob.h"
#include "parse.h"
#include "path.h"
#define MM_FILE ".mailmap"
#define MM_FILE_CONFIG "mailmap.file"
...
...
@@ -331,7 +332,7 @@ static int mailmap_add_file_ondisk(
if
(
error
<
0
)
goto
cleanup
;
error
=
git_
fs_path_validate_workdir_buf
(
repo
,
&
fullpath
);
error
=
git_
path_validate_str_length
(
repo
,
&
fullpath
);
if
(
error
<
0
)
goto
cleanup
;
...
...
src/refdb_fs.c
View file @
91246ee5
...
...
@@ -1362,7 +1362,7 @@ static int refdb_fs_backend__prune_refs(
git_str_cstr
(
&
relative_path
));
if
(
!
error
)
error
=
git_
fs_path_validate_filesystem
(
base_path
.
ptr
,
base_path
.
size
);
error
=
git_
path_validate_str_length
(
NULL
,
&
base_path
);
if
(
error
<
0
)
goto
cleanup
;
...
...
src/repository.c
View file @
91246ee5
...
...
@@ -32,7 +32,7 @@
#include "annotated_commit.h"
#include "submodule.h"
#include "worktree.h"
#include "path.h"
#include "strmap.h"
#ifdef GIT_WIN32
...
...
@@ -2662,7 +2662,7 @@ int git_repository_workdir_path(
}
if
(
!
(
error
=
git_str_joinpath
(
out
,
repo
->
workdir
,
path
)))
error
=
git_
fs_path_validate_workdir_buf
(
repo
,
out
);
error
=
git_
path_validate_str_length
(
repo
,
out
);
return
error
;
}
...
...
@@ -2858,7 +2858,7 @@ int git_repository_hashfile(
GIT_ASSERT_ARG
(
repo
);
if
((
error
=
git_fs_path_join_unrooted
(
&
full_path
,
path
,
workdir
,
NULL
))
<
0
||
(
error
=
git_
fs_path_validate_workdir_buf
(
repo
,
&
full_path
))
<
0
)
(
error
=
git_
path_validate_str_length
(
repo
,
&
full_path
))
<
0
)
return
error
;
/*
...
...
src/submodule.c
View file @
91246ee5
...
...
@@ -386,7 +386,7 @@ int git_submodule__lookup_with_cache(
if
(
git_str_join3
(
&
path
,
'/'
,
git_repository_workdir
(
repo
),
name
,
DOT_GIT
)
<
0
||
git_
fs_path_validate_workdir_buf
(
NULL
,
&
path
)
<
0
)
git_
path_validate_str_length
(
NULL
,
&
path
)
<
0
)
return
-
1
;
if
(
git_fs_path_exists
(
path
.
ptr
))
...
...
src/worktree.c
View file @
91246ee5
...
...
@@ -9,6 +9,7 @@
#include "buf.h"
#include "repository.h"
#include "path.h"
#include "git2/branch.h"
#include "git2/commit.h"
...
...
@@ -136,7 +137,7 @@ static int open_worktree_dir(git_worktree **out, const char *parent, const char
goto
out
;
}
if
((
error
=
git_
fs_path_validate_workdir
(
NULL
,
dir
))
<
0
)
if
((
error
=
git_
path_validate_length
(
NULL
,
dir
))
<
0
)
goto
out
;
if
((
wt
=
git__calloc
(
1
,
sizeof
(
*
wt
)))
==
NULL
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment