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
28d0ba0b
Commit
28d0ba0b
authored
Jan 21, 2017
by
Edward Thomson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
symbolic ref target validation: fixups
Fixups requested in #3912.
parent
452bf57c
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
19 additions
and
41 deletions
+19
-41
include/git2/common.h
+8
-10
src/refs.c
+9
-29
src/refs.h
+1
-1
src/settings.c
+1
-1
No files found.
include/git2/common.h
View file @
28d0ba0b
...
...
@@ -157,7 +157,7 @@ typedef enum {
GIT_OPT_SET_SSL_CERT_LOCATIONS
,
GIT_OPT_SET_USER_AGENT
,
GIT_OPT_ENABLE_STRICT_OBJECT_CREATION
,
GIT_OPT_ENABLE_S
YMBOLIC_REF_TARGET_VALID
ATION
,
GIT_OPT_ENABLE_S
TRICT_SYMBOLIC_REF_CRE
ATION
,
GIT_OPT_SET_SSL_CIPHERS
,
GIT_OPT_GET_USER_AGENT
,
}
git_libgit2_opt_t
;
...
...
@@ -272,16 +272,14 @@ typedef enum {
* > will be validated when creating a new commit. This defaults
* > to disabled.
*
* * opts(GIT_OPT_ENABLE_S
YMBOLIC_REF_TARGET_VALID
ATION, int enabled)
* * opts(GIT_OPT_ENABLE_S
TRICT_SYMBOLIC_REF_CRE
ATION, int enabled)
*
* > Validate the target of a symbolic ref when creating it.
* > For example, 'foobar' is not a valid ref,
* > therefore 'foobar' is not a valid target
* > for a symbolic ref by default,
* > where as 'refs/heads/foobar' is.
* > Disabling this bypasses validation so that an arbitrary
* > strings such as 'foobar' can be used for a symbolic ref target.
* > This defaults to enabled.
* > Validate the target of a symbolic ref when creating it. For
* > example, `foobar` is not a valid ref, therefore `foobar` is
* > not a valid target for a symbolic ref by default, whereas
* > `refs/heads/foobar` is. Disabling this bypasses validation
* > so that an arbitrary strings such as `foobar` can be used
* > for a symbolic ref target. This defaults to enabled.
*
* * opts(GIT_OPT_SET_SSL_CIPHERS, const char *ciphers)
*
...
...
src/refs.c
View file @
28d0ba0b
...
...
@@ -177,7 +177,7 @@ int git_reference_name_to_id(
return
0
;
}
static
int
reference_
_
normalize_for_repo
(
static
int
reference_normalize_for_repo
(
git_refname_t
out
,
git_repository
*
repo
,
const
char
*
name
,
...
...
@@ -190,29 +190,12 @@ static int reference__normalize_for_repo(
precompose
)
flags
|=
GIT_REF_FORMAT__PRECOMPOSE_UNICODE
;
if
(
!
validate
)
{
flags
|=
GIT_REF_VALIDATION_DISABLE
;
}
if
(
!
validate
)
flags
|=
GIT_REF_FORMAT__VALIDATION_DISABLE
;
return
git_reference_normalize_name
(
out
,
GIT_REFNAME_MAX
,
name
,
flags
);
}
static
int
reference_normalize_for_repo
(
git_refname_t
out
,
git_repository
*
repo
,
const
char
*
name
)
{
return
reference__normalize_for_repo
(
out
,
repo
,
name
,
true
);
}
static
int
reference_normalize_for_repo_without_validation
(
git_refname_t
out
,
git_repository
*
repo
,
const
char
*
name
)
{
return
reference__normalize_for_repo
(
out
,
repo
,
name
,
false
);
}
int
git_reference_lookup_resolved
(
git_reference
**
ref_out
,
git_repository
*
repo
,
...
...
@@ -236,7 +219,7 @@ int git_reference_lookup_resolved(
scan_type
=
GIT_REF_SYMBOLIC
;
if
((
error
=
reference_normalize_for_repo
(
scan_name
,
repo
,
name
))
<
0
)
if
((
error
=
reference_normalize_for_repo
(
scan_name
,
repo
,
name
,
true
))
<
0
)
return
error
;
if
((
error
=
git_repository_refdb__weakptr
(
&
refdb
,
repo
))
<
0
)
...
...
@@ -406,7 +389,7 @@ static int reference__create(
if
(
ref_out
)
*
ref_out
=
NULL
;
error
=
reference_normalize_for_repo
(
normalized
,
repo
,
name
);
error
=
reference_normalize_for_repo
(
normalized
,
repo
,
name
,
true
);
if
(
error
<
0
)
return
error
;
...
...
@@ -427,11 +410,8 @@ static int reference__create(
}
else
{
git_refname_t
normalized_target
;
if
(
git_reference__enable_symbolic_ref_target_validation
)
{
error
=
reference_normalize_for_repo
(
normalized_target
,
repo
,
symbolic
);
}
else
{
error
=
reference_normalize_for_repo_without_validation
(
normalized_target
,
repo
,
symbolic
);
}
error
=
reference_normalize_for_repo
(
normalized_target
,
repo
,
symbolic
,
git_reference__enable_symbolic_ref_target_validation
);
if
(
error
<
0
)
return
error
;
...
...
@@ -612,7 +592,7 @@ static int reference__rename(git_reference **out, git_reference *ref, const char
assert
(
ref
&&
new_name
&&
signature
);
if
((
error
=
reference_normalize_for_repo
(
normalized
,
git_reference_owner
(
ref
),
new_nam
e
))
<
0
)
normalized
,
git_reference_owner
(
ref
),
new_name
,
tru
e
))
<
0
)
return
error
;
...
...
@@ -905,7 +885,7 @@ int git_reference__normalize_name(
int
segment_len
,
segments_count
=
0
,
error
=
GIT_EINVALIDSPEC
;
unsigned
int
process_flags
;
bool
normalize
=
(
buf
!=
NULL
);
bool
validate
=
(
flags
&
GIT_REF_VALIDATION_DISABLE
)
==
0
;
bool
validate
=
(
flags
&
GIT_REF_
FORMAT__
VALIDATION_DISABLE
)
==
0
;
#ifdef GIT_USE_ICONV
git_path_iconv_t
ic
=
GIT_PATH_ICONV_INIT
;
...
...
src/refs.h
View file @
28d0ba0b
...
...
@@ -55,7 +55,7 @@ extern bool git_reference__enable_symbolic_ref_target_validation;
#define GIT_REFS_STASH_FILE GIT_REFS_DIR GIT_STASH_FILE
#define GIT_REF_FORMAT__PRECOMPOSE_UNICODE (1u << 16)
#define GIT_REF_VALIDATION_DISABLE (1u << 15)
#define GIT_REF_
FORMAT__
VALIDATION_DISABLE (1u << 15)
#define GIT_REFNAME_MAX 1024
...
...
src/settings.c
View file @
28d0ba0b
...
...
@@ -192,7 +192,7 @@ int git_libgit2_opts(int key, ...)
git_object__strict_input_validation
=
(
va_arg
(
ap
,
int
)
!=
0
);
break
;
case
GIT_OPT_ENABLE_S
YMBOLIC_REF_TARGET_VALID
ATION
:
case
GIT_OPT_ENABLE_S
TRICT_SYMBOLIC_REF_CRE
ATION
:
git_reference__enable_symbolic_ref_target_validation
=
(
va_arg
(
ap
,
int
)
!=
0
);
break
;
...
...
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