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
f19304d2
Commit
f19304d2
authored
Dec 24, 2012
by
nulltoken
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remote: Prevent create() from blindly overwriting
parent
ae35aa07
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
6 deletions
+17
-6
include/git2/remote.h
+1
-1
src/remote.c
+5
-5
tests-clar/network/remotes.c
+11
-0
No files found.
include/git2/remote.h
View file @
f19304d2
...
...
@@ -41,7 +41,7 @@ typedef int (*git_remote_rename_problem_cb)(const char *problematic_refspec, voi
* @param repo the repository in which to create the remote
* @param name the remote's name
* @param url the remote's url
* @return 0, GIT_EINVALIDSPEC or an error code
* @return 0, GIT_EINVALIDSPEC
, GIT_EEXISTS
or an error code
*/
GIT_EXTERN
(
int
)
git_remote_create
(
git_remote
**
out
,
...
...
src/remote.c
View file @
f19304d2
...
...
@@ -106,11 +106,6 @@ static int create_internal(git_remote **out, git_repository *repo, const char *n
GITERR_CHECK_ALLOC
(
remote
->
url
);
if
(
name
!=
NULL
)
{
if
((
error
=
ensure_remote_name_is_valid
(
name
))
<
0
)
{
error
=
GIT_EINVALIDSPEC
;
goto
on_error
;
}
remote
->
name
=
git__strdup
(
name
);
GITERR_CHECK_ALLOC
(
remote
->
name
);
}
...
...
@@ -135,6 +130,8 @@ on_error:
return
error
;
}
extern
int
ensure_remote_doesnot_exist
(
git_repository
*
repo
,
const
char
*
name
);
int
git_remote_create
(
git_remote
**
out
,
git_repository
*
repo
,
const
char
*
name
,
const
char
*
url
)
{
git_buf
buf
=
GIT_BUF_INIT
;
...
...
@@ -143,6 +140,9 @@ int git_remote_create(git_remote **out, git_repository *repo, const char *name,
if
((
error
=
ensure_remote_name_is_valid
(
name
))
<
0
)
return
error
;
if
((
error
=
ensure_remote_doesnot_exist
(
repo
,
name
))
<
0
)
return
error
;
if
(
git_buf_printf
(
&
buf
,
"+refs/heads/*:refs/remotes/%s/*"
,
name
)
<
0
)
return
-
1
;
...
...
tests-clar/network/remotes.c
View file @
f19304d2
...
...
@@ -346,3 +346,14 @@ void test_network_remotes__check_structure_version(void)
err
=
giterr_last
();
cl_assert_equal_i
(
GITERR_INVALID
,
err
->
klass
);
}
void
test_network_remotes__cannot_create_a_remote_which_name_conflicts_with_an_existing_remote
(
void
)
{
git_remote
*
remote
=
NULL
;
cl_assert_equal_i
(
GIT_EEXISTS
,
git_remote_create
(
&
remote
,
_repo
,
"test"
,
"git://github.com/libgit2/libgit2"
));
cl_assert_equal_p
(
remote
,
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