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
5d91bea2
Commit
5d91bea2
authored
May 28, 2014
by
Vicent Marti
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2380 from libgit2/cmn/index-add-modes
index: check for valid filemodes on add
parents
a470a5c7
052a2ffd
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
0 deletions
+29
-0
src/index.c
+14
-0
tests/index/filemodes.c
+15
-0
No files found.
src/index.c
View file @
5d91bea2
...
...
@@ -1104,6 +1104,15 @@ int git_index_remove_bypath(git_index *index, const char *path)
return
0
;
}
static
bool
valid_filemode
(
const
int
filemode
)
{
return
(
filemode
==
GIT_FILEMODE_BLOB
||
filemode
==
GIT_FILEMODE_BLOB_EXECUTABLE
||
filemode
==
GIT_FILEMODE_LINK
||
filemode
==
GIT_FILEMODE_COMMIT
);
}
int
git_index_add
(
git_index
*
index
,
const
git_index_entry
*
source_entry
)
{
git_index_entry
*
entry
=
NULL
;
...
...
@@ -1111,6 +1120,11 @@ int git_index_add(git_index *index, const git_index_entry *source_entry)
assert
(
index
&&
source_entry
&&
source_entry
->
path
);
if
(
!
valid_filemode
(
source_entry
->
mode
))
{
giterr_set
(
GITERR_INDEX
,
"invalid filemode"
);
return
-
1
;
}
if
((
ret
=
index_entry_dup
(
&
entry
,
source_entry
))
<
0
||
(
ret
=
index_insert
(
index
,
&
entry
,
1
))
<
0
)
return
ret
;
...
...
tests/index/filemodes.c
View file @
5d91bea2
...
...
@@ -152,3 +152,18 @@ void test_index_filemodes__trusted(void)
git_index_free
(
index
);
}
void
test_index_filemodes__invalid
(
void
)
{
git_index
*
index
;
git_index_entry
entry
;
cl_git_pass
(
git_repository_index
(
&
index
,
g_repo
));
entry
.
path
=
"foo"
;
entry
.
mode
=
GIT_OBJ_BLOB
;
cl_git_fail
(
git_index_add
(
index
,
&
entry
));
entry
.
mode
=
GIT_FILEMODE_BLOB
;
cl_git_pass
(
git_index_add
(
index
,
&
entry
));
}
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