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
554b3b9a
Unverified
Commit
554b3b9a
authored
Feb 21, 2019
by
Patrick Steinhardt
Committed by
GitHub
Feb 21, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4996 from eaigner/master
Prevent reading out of bounds memory
parents
6eb4947d
966b9440
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
1 deletions
+35
-1
AUTHORS
+1
-0
src/apply.c
+1
-1
tests/apply/fromdiff.c
+33
-0
No files found.
AUTHORS
View file @
554b3b9a
...
...
@@ -23,6 +23,7 @@ Dmitry Kovega
Emeric Fermas
Emmanuel Rodriguez
Eric Myhre
Erik Aigner
Florian Forster
Holger Weiss
Ingmar Vanhassel
...
...
src/apply.c
View file @
554b3b9a
...
...
@@ -59,7 +59,7 @@ static int patch_image_init_fromstr(
git_pool_init
(
&
out
->
pool
,
sizeof
(
git_diff_line
));
for
(
start
=
in
;
start
<
in
+
in_len
;
start
=
end
)
{
end
=
memchr
(
start
,
'\n'
,
in_len
);
end
=
memchr
(
start
,
'\n'
,
in_len
-
(
start
-
in
)
);
if
(
end
==
NULL
)
end
=
in
+
in_len
;
...
...
tests/apply/fromdiff.c
View file @
554b3b9a
...
...
@@ -333,3 +333,36 @@ void test_apply_fromdiff__binary_delete(void)
NULL
,
NULL
,
NULL
,
&
binary_opts
));
}
void
test_apply_fromdiff__patching_correctly_truncates_source
(
void
)
{
git_buf
original
=
GIT_BUF_INIT
,
patched
=
GIT_BUF_INIT
;
git_patch
*
patch
;
unsigned
int
mode
;
char
*
path
;
cl_git_pass
(
git_patch_from_buffers
(
&
patch
,
"foo
\n
bar"
,
7
,
"file.txt"
,
"foo
\n
foo"
,
7
,
"file.txt"
,
NULL
));
/*
* Previously, we would fail to correctly truncate the source buffer if
* the source has more than one line and ends with a non-newline
* character. In the following call, we thus truncate the source string
* in the middle of the second line. Without the bug fixed, we would
* successfully apply the patch to the source and return success. With
* the overflow being fixed, we should return an error.
*/
cl_git_fail_with
(
GIT_EAPPLYFAIL
,
git_apply__patch
(
&
patched
,
&
path
,
&
mode
,
"foo
\n
bar
\n
"
,
5
,
patch
,
NULL
));
/* Verify that the patch succeeds if we do not truncate */
cl_git_pass
(
git_apply__patch
(
&
patched
,
&
path
,
&
mode
,
"foo
\n
bar
\n
"
,
7
,
patch
,
NULL
));
git_buf_dispose
(
&
original
);
git_buf_dispose
(
&
patched
);
git_patch_free
(
patch
);
git__free
(
path
);
}
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