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
fd74bd08
Commit
fd74bd08
authored
Oct 29, 2015
by
Carlos Martín Nieto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3486 from srajko/reflog-segfault-fix
Fix segfault when reading reflog with extra newlines
parents
1b4449b4
335c9e2f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
1 deletions
+44
-1
src/refdb_fs.c
+1
-1
tests/refs/reflog/reflog.c
+43
-0
No files found.
src/refdb_fs.c
View file @
fd74bd08
...
...
@@ -1464,7 +1464,7 @@ static int reflog_parse(git_reflog *log, const char *buf, size_t buf_size)
entry
=
git__calloc
(
1
,
sizeof
(
git_reflog_entry
));
GITERR_CHECK_ALLOC
(
entry
);
entry
->
committer
=
git__
malloc
(
sizeof
(
git_signature
));
entry
->
committer
=
git__
calloc
(
1
,
sizeof
(
git_signature
));
GITERR_CHECK_ALLOC
(
entry
->
committer
);
if
(
git_oid_fromstrn
(
&
entry
->
oid_old
,
buf
,
GIT_OID_HEXSZ
)
<
0
)
...
...
tests/refs/reflog/reflog.c
View file @
fd74bd08
...
...
@@ -154,6 +154,49 @@ void test_refs_reflog_reflog__reading_the_reflog_from_a_reference_with_no_log_re
git_buf_free
(
&
subtrees_log_path
);
}
void
test_refs_reflog_reflog__reading_a_reflog_with_invalid_format_returns_error
(
void
)
{
git_reflog
*
reflog
;
const
git_error
*
error
;
const
char
*
refname
=
"refs/heads/newline"
;
const
char
*
refmessage
=
"Reflog*message with a newline and enough content after it to pass the GIT_REFLOG_SIZE_MIN check inside reflog_parse."
;
git_reference
*
ref
;
git_oid
id
;
git_buf
logpath
=
GIT_BUF_INIT
,
logcontents
=
GIT_BUF_INIT
;
char
*
star
;
git_oid_fromstr
(
&
id
,
current_master_tip
);
/* create a new branch */
cl_git_pass
(
git_reference_create
(
&
ref
,
g_repo
,
refname
,
&
id
,
1
,
refmessage
));
/* corrupt the branch reflog by introducing a newline inside the reflog message (we replace '*' with '\n') */
git_buf_join_n
(
&
logpath
,
'/'
,
3
,
git_repository_path
(
g_repo
),
GIT_REFLOG_DIR
,
refname
);
cl_git_pass
(
git_futils_readbuffer
(
&
logcontents
,
git_buf_cstr
(
&
logpath
)));
cl_assert
((
star
=
strchr
(
git_buf_cstr
(
&
logcontents
),
'*'
))
!=
NULL
);
*
star
=
'\n'
;
cl_git_rewritefile
(
git_buf_cstr
(
&
logpath
),
git_buf_cstr
(
&
logcontents
));
/* confirm that the file was rewritten successfully and now contains a '\n' in the expected location */
cl_git_pass
(
git_futils_readbuffer
(
&
logcontents
,
git_buf_cstr
(
&
logpath
)));
cl_assert
(
strstr
(
git_buf_cstr
(
&
logcontents
),
"Reflog
\n
message"
)
!=
NULL
);
/* clear the error state so we can capture the error generated by git_reflog_read */
giterr_clear
();
cl_git_fail
(
git_reflog_read
(
&
reflog
,
g_repo
,
refname
));
error
=
giterr_last
();
cl_assert
(
error
!=
NULL
);
cl_assert_equal_s
(
"Unable to parse OID - contains invalid characters"
,
error
->
message
);
git_reference_free
(
ref
);
git_buf_free
(
&
logpath
);
git_buf_free
(
&
logcontents
);
}
void
test_refs_reflog_reflog__cannot_write_a_moved_reflog
(
void
)
{
git_reference
*
master
,
*
new_master
;
...
...
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