Skip to content

Commit f51d790

Browse files
rscharfegitster
authored andcommitted
receive-pack: use find_commit_header() in check_cert_push_options()
Use the public function find_commit_header() instead of find_header() to simplify the code. This is possible and safe because we're operating on a strbuf, which is always NUL-terminated, so there is no risk of running over the end of the buffer. It cannot contain NUL within the buffer, as it is built using strbuf_addstr(), only. The string comparison becomes more complicated because we need to check for NUL explicitly after comparing the length-limited option, but on the flip side we don't need to clean up allocations or track the remaining buffer length. Signed-off-by: René Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3526e67 commit f51d790

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

builtin/receive-pack.c

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -718,35 +718,29 @@ static const char *check_nonce(const char *buf, size_t len)
718718
static int check_cert_push_options(const struct string_list *push_options)
719719
{
720720
const char *buf = push_cert.buf;
721-
int len = push_cert.len;
722721

723-
char *option;
724-
const char *next_line;
722+
const char *option;
723+
size_t optionlen;
725724
int options_seen = 0;
726725

727726
int retval = 1;
728727

729-
if (!len)
728+
if (!*buf)
730729
return 1;
731730

732-
while ((option = find_header(buf, len, "push-option", &next_line))) {
733-
len -= (next_line - buf);
734-
buf = next_line;
731+
while ((option = find_commit_header(buf, "push-option", &optionlen))) {
732+
buf = option + optionlen + 1;
735733
options_seen++;
736734
if (options_seen > push_options->nr
737-
|| strcmp(option,
738-
push_options->items[options_seen - 1].string)) {
739-
retval = 0;
740-
goto leave;
741-
}
742-
free(option);
735+
|| strncmp(push_options->items[options_seen - 1].string,
736+
option, optionlen)
737+
|| push_options->items[options_seen - 1].string[optionlen])
738+
return 0;
743739
}
744740

745741
if (options_seen != push_options->nr)
746742
retval = 0;
747743

748-
leave:
749-
free(option);
750744
return retval;
751745
}
752746

0 commit comments

Comments
 (0)