Skip to content

Commit

Permalink
Merge branch 'feature/fix-unquoted-patch-file-paths-with-space' into …
Browse files Browse the repository at this point in the history
…libgit-next-1.7.2
  • Loading branch information
zawata committed Feb 7, 2024
2 parents 31aad4e + 3023c79 commit a9d63bf
Show file tree
Hide file tree
Showing 7 changed files with 539 additions and 24 deletions.
13 changes: 11 additions & 2 deletions src/libgit2/diff_print.c
Original file line number Diff line number Diff line change
Expand Up @@ -441,10 +441,19 @@ int git_diff_delta__format_file_header(
if (!id_strlen)
id_strlen = GIT_ABBREV_DEFAULT;

/*
Additional layer of protection against NULL pathnames in addition to the
fix in 'patch_parse.c:check_filenames()' that prevents any of the sides
from having a NULL pathname.
*/
if ((error = diff_delta_format_path(
&old_path, oldpfx, delta->old_file.path)) < 0 ||
&old_path,
oldpfx,
!delta->old_file.path ? delta->new_file.path : delta->old_file.path)) < 0 ||
(error = diff_delta_format_path(
&new_path, newpfx, delta->new_file.path)) < 0)
&new_path,
newpfx,
!delta->new_file.path ? delta->old_file.path : delta->new_file.path)) < 0)
goto done;

git_str_clear(out);
Expand Down
24 changes: 24 additions & 0 deletions src/libgit2/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,30 @@ void git_parse_ctx_clear(git_parse_ctx *ctx)
ctx->content = "";
}

long git_parse_unescaped_char_offset_in_line(
git_parse_ctx *ctx,
char char_to_search_for)
{
return git_parse_unescaped_char_offset_in_str(
ctx->line,
ctx->line_len,
char_to_search_for);
}

long git_parse_unescaped_char_offset_in_str(const char *base, size_t len, char char_to_search_for)
{
bool after_escaping_backslash = false;
long offset;

for (offset = 0; (size_t)offset < len; offset++) {
if (!after_escaping_backslash && base[offset] == char_to_search_for) {
return offset;
}
after_escaping_backslash = (!after_escaping_backslash && base[offset] == '\\');
}
return -1;
}

void git_parse_advance_line(git_parse_ctx *ctx)
{
ctx->line += ctx->line_len;
Expand Down
8 changes: 8 additions & 0 deletions src/libgit2/parse.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ typedef struct {
int git_parse_ctx_init(git_parse_ctx *ctx, const char *content, size_t content_len);
void git_parse_ctx_clear(git_parse_ctx *ctx);

long git_parse_unescaped_char_offset_in_line(
git_parse_ctx *ctx,
char char_to_search_for);
long git_parse_unescaped_char_offset_in_str(
const char *base,
size_t len,
char char_to_search_for);

#define git_parse_ctx_contains_s(ctx, str) \
git_parse_ctx_contains(ctx, str, sizeof(str) - 1)

Expand Down
Loading

0 comments on commit a9d63bf

Please sign in to comment.