diff options
author | Patrick Steinhardt <ps@pks.im> | 2019-11-05 22:44:27 +0100 |
---|---|---|
committer | Patrick Steinhardt <ps@pks.im> | 2019-11-05 22:50:41 +0100 |
commit | de543e297d85f1ac700c2e5a83e70b1bd32b9518 (patch) | |
tree | ff3c74bd2c255a4bacaf91e665f24611086d49fa /tests/patch/patch_common.h | |
parent | 5d773a1833ef6d0fb2093e00b1cf9bfb668a1ffc (diff) | |
download | libgit2-de543e297d85f1ac700c2e5a83e70b1bd32b9518.tar.gz |
patch_parse: fix segfault when header path contains whitespace only
When parsing header paths from a patch, we reject any patches with empty
paths as malformed patches. We perform the check whether a path is empty
before sanitizing it, though, which may lead to a path becoming empty
after the check, e.g. if we have trimmed whitespace. This may lead to a
segfault later when any part of our patching logic actually references
such a path, which may then be a `NULL` pointer.
Fix the issue by performing the check after sanitizing. Add tests to
catch the issue as they would have produced a segfault previosuly.
Diffstat (limited to 'tests/patch/patch_common.h')
-rw-r--r-- | tests/patch/patch_common.h | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/tests/patch/patch_common.h b/tests/patch/patch_common.h index 153bab57f..4f2141dbe 100644 --- a/tests/patch/patch_common.h +++ b/tests/patch/patch_common.h @@ -912,6 +912,18 @@ "+++ \n" \ "Binary files " +#define PATCH_BINARY_FILE_WITH_WHITESPACE_PATHS \ + "diff --git a/file b/file\n" \ + "--- \n" \ + "+++ \n" \ + "Binary files " + +#define PATCH_BINARY_FILE_WITH_QUOTED_EMPTY_PATHS \ + "diff --git a/file b/file\n" \ + "--- \"\"\n" \ + "+++ \"\"\n" \ + "Binary files " + #define PATCH_MULTIPLE_OLD_PATHS \ "diff --git \n" \ "--- \n" \ |