Unverified Commit 606afeda by Edward Thomson Committed by GitHub

Merge pull request #6244 from jorio/fix-diff_delta_format_path-crash

Fix crash when regenerating a patch with unquoted spaces in filename
parents 2fc0fcb5 71bb92b5
...@@ -316,6 +316,11 @@ static int diff_print_oid_range( ...@@ -316,6 +316,11 @@ static int diff_print_oid_range(
static int diff_delta_format_path( static int diff_delta_format_path(
git_str *out, const char *prefix, const char *filename) git_str *out, const char *prefix, const char *filename)
{ {
if (!filename) {
/* don't prefix "/dev/null" */
return git_str_puts(out, "/dev/null");
}
if (git_str_joinpath(out, prefix, filename) < 0) if (git_str_joinpath(out, prefix, filename) < 0)
return -1; return -1;
......
...@@ -431,6 +431,32 @@ void test_diff_parse__new_file_with_space(void) ...@@ -431,6 +431,32 @@ void test_diff_parse__new_file_with_space(void)
git_diff_free(diff); git_diff_free(diff);
} }
void test_diff_parse__new_file_with_space_and_regenerate_patch(void)
{
const char *content = PATCH_ORIGINAL_NEW_FILE_WITH_SPACE;
git_diff *diff = NULL;
git_buf buf = GIT_BUF_INIT;
cl_git_pass(git_diff_from_buffer(&diff, content, strlen(content)));
cl_git_pass(git_diff_to_buf(&buf, diff, GIT_DIFF_FORMAT_PATCH));
git_buf_dispose(&buf);
git_diff_free(diff);
}
void test_diff_parse__delete_file_with_space_and_regenerate_patch(void)
{
const char *content = PATCH_DELETE_FILE_WITH_SPACE;
git_diff *diff = NULL;
git_buf buf = GIT_BUF_INIT;
cl_git_pass(git_diff_from_buffer(&diff, content, strlen(content)));
cl_git_pass(git_diff_to_buf(&buf, diff, GIT_DIFF_FORMAT_PATCH));
git_buf_dispose(&buf);
git_diff_free(diff);
}
void test_diff_parse__crlf(void) void test_diff_parse__crlf(void)
{ {
const char *text = PATCH_CRLF; const char *text = PATCH_CRLF;
......
...@@ -933,6 +933,15 @@ ...@@ -933,6 +933,15 @@
"@@ -0,0 +1 @@\n" \ "@@ -0,0 +1 @@\n" \
"+a\n" "+a\n"
#define PATCH_DELETE_FILE_WITH_SPACE \
"diff --git a/sp ace.txt b/sp ace.txt\n" \
"deleted file mode 100644\n" \
"index 789819226..000000000\n" \
"--- a/sp ace.txt\n" \
"+++ /dev/null\n" \
"@@ -1 +0,0 @@\n" \
"-a\n"
#define PATCH_CRLF \ #define PATCH_CRLF \
"diff --git a/test-file b/test-file\r\n" \ "diff --git a/test-file b/test-file\r\n" \
"new file mode 100644\r\n" \ "new file mode 100644\r\n" \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment