Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cavaquinho/patch unquoted path w space fix 6294 #6295

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/libgit2/diff_print.c
Original file line number Diff line number Diff line change
Expand Up @@ -422,10 +422,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 @@ -31,6 +31,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