Skip to content

Commit a9d63bf

Browse files
committed
Merge branch 'feature/fix-unquoted-patch-file-paths-with-space' into libgit-next-1.7.2
2 parents 31aad4e + 3023c79 commit a9d63bf

File tree

7 files changed

+539
-24
lines changed

7 files changed

+539
-24
lines changed

src/libgit2/diff_print.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,10 +441,19 @@ int git_diff_delta__format_file_header(
441441
if (!id_strlen)
442442
id_strlen = GIT_ABBREV_DEFAULT;
443443

444+
/*
445+
Additional layer of protection against NULL pathnames in addition to the
446+
fix in 'patch_parse.c:check_filenames()' that prevents any of the sides
447+
from having a NULL pathname.
448+
*/
444449
if ((error = diff_delta_format_path(
445-
&old_path, oldpfx, delta->old_file.path)) < 0 ||
450+
&old_path,
451+
oldpfx,
452+
!delta->old_file.path ? delta->new_file.path : delta->old_file.path)) < 0 ||
446453
(error = diff_delta_format_path(
447-
&new_path, newpfx, delta->new_file.path)) < 0)
454+
&new_path,
455+
newpfx,
456+
!delta->new_file.path ? delta->old_file.path : delta->new_file.path)) < 0)
448457
goto done;
449458

450459
git_str_clear(out);

src/libgit2/parse.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,30 @@ void git_parse_ctx_clear(git_parse_ctx *ctx)
3232
ctx->content = "";
3333
}
3434

35+
long git_parse_unescaped_char_offset_in_line(
36+
git_parse_ctx *ctx,
37+
char char_to_search_for)
38+
{
39+
return git_parse_unescaped_char_offset_in_str(
40+
ctx->line,
41+
ctx->line_len,
42+
char_to_search_for);
43+
}
44+
45+
long git_parse_unescaped_char_offset_in_str(const char *base, size_t len, char char_to_search_for)
46+
{
47+
bool after_escaping_backslash = false;
48+
long offset;
49+
50+
for (offset = 0; (size_t)offset < len; offset++) {
51+
if (!after_escaping_backslash && base[offset] == char_to_search_for) {
52+
return offset;
53+
}
54+
after_escaping_backslash = (!after_escaping_backslash && base[offset] == '\\');
55+
}
56+
return -1;
57+
}
58+
3559
void git_parse_advance_line(git_parse_ctx *ctx)
3660
{
3761
ctx->line += ctx->line_len;

src/libgit2/parse.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ typedef struct {
2828
int git_parse_ctx_init(git_parse_ctx *ctx, const char *content, size_t content_len);
2929
void git_parse_ctx_clear(git_parse_ctx *ctx);
3030

31+
long git_parse_unescaped_char_offset_in_line(
32+
git_parse_ctx *ctx,
33+
char char_to_search_for);
34+
long git_parse_unescaped_char_offset_in_str(
35+
const char *base,
36+
size_t len,
37+
char char_to_search_for);
38+
3139
#define git_parse_ctx_contains_s(ctx, str) \
3240
git_parse_ctx_contains(ctx, str, sizeof(str) - 1)
3341

0 commit comments

Comments
 (0)