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
d4b24101
Commit
d4b24101
authored
Jan 09, 2015
by
Carlos Martín Nieto
Browse files
Options
Browse Files
Download
Plain Diff
Merge commit '
4b1018d2
'
Fix crash in free() when git_buf_grow() fails.
parents
fe8399fe
4b1018d2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
1 deletions
+33
-1
src/buffer.c
+2
-1
tests/buf/oom.c
+31
-0
No files found.
src/buffer.c
View file @
d4b24101
...
...
@@ -67,7 +67,8 @@ int git_buf_try_grow(
if
(
!
new_ptr
)
{
if
(
mark_oom
)
{
if
(
buf
->
ptr
)
git__free
(
buf
->
ptr
);
if
(
buf
->
ptr
&&
(
buf
->
ptr
!=
git_buf__initbuf
))
git__free
(
buf
->
ptr
);
buf
->
ptr
=
git_buf__oom
;
}
return
-
1
;
...
...
tests/buf/oom.c
0 → 100644
View file @
d4b24101
#include "clar_libgit2.h"
#include "buffer.h"
#if defined(GIT_ARCH_64)
#define TOOBIG 0xffffffffffffff00
#else
#define TOOBIG 0xffffff00
#endif
/**
* If we make a ridiculously large request the first time we
* actually allocate some space in the git_buf, the realloc()
* will fail. And because the git_buf_grow() wrapper always
* sets mark_oom, the code in git_buf_try_grow() will free
* the internal buffer and set it to git_buf__oom.
*
* We initialized the internal buffer to (the static variable)
* git_buf__initbuf. The purpose of this test is to make sure
* that we don't try to free the static buffer.
*/
void
test_buf_oom__grow
(
void
)
{
git_buf
buf
=
GIT_BUF_INIT
;
git_buf_clear
(
&
buf
);
cl_assert
(
git_buf_grow
(
&
buf
,
TOOBIG
)
==
-
1
);
cl_assert
(
git_buf_oom
(
&
buf
));
git_buf_free
(
&
buf
);
}
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