Skip to content

Commit 020456c

Browse files
rscharfegitster
authored andcommitted
receive-pack: use find_commit_header() in check_nonce()
Use the public function find_commit_header() and remove find_header(), as it becomes unused. This is safe and appropriate because we pass the NUL-terminated payload buffer to check_nonce() instead of its start and length. The underlying strbuf push_cert cannot contain NULs, as it is built using strbuf_addstr(), only. We no longer need to call strlen(), as find_commit_header() returns the length of nonce already. Signed-off-by: René Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f51d790 commit 020456c

File tree

1 file changed

+7
-23
lines changed

1 file changed

+7
-23
lines changed

builtin/receive-pack.c

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -593,21 +593,6 @@ static char *prepare_push_cert_nonce(const char *path, timestamp_t stamp)
593593
return strbuf_detach(&buf, NULL);
594594
}
595595

596-
static char *find_header(const char *msg, size_t len, const char *key,
597-
const char **next_line)
598-
{
599-
size_t out_len;
600-
const char *val = find_header_mem(msg, len, key, &out_len);
601-
602-
if (!val)
603-
return NULL;
604-
605-
if (next_line)
606-
*next_line = val + out_len + 1;
607-
608-
return xmemdupz(val, out_len);
609-
}
610-
611596
/*
612597
* Return zero if a and b are equal up to n bytes and nonzero if they are not.
613598
* This operation is guaranteed to run in constant time to avoid leaking data.
@@ -622,13 +607,14 @@ static int constant_memequal(const char *a, const char *b, size_t n)
622607
return res;
623608
}
624609

625-
static const char *check_nonce(const char *buf, size_t len)
610+
static const char *check_nonce(const char *buf)
626611
{
627-
char *nonce = find_header(buf, len, "nonce", NULL);
612+
size_t noncelen;
613+
const char *found = find_commit_header(buf, "nonce", &noncelen);
614+
char *nonce = found ? xmemdupz(found, noncelen) : NULL;
628615
timestamp_t stamp, ostamp;
629616
char *bohmac, *expect = NULL;
630617
const char *retval = NONCE_BAD;
631-
size_t noncelen;
632618

633619
if (!nonce) {
634620
retval = NONCE_MISSING;
@@ -670,7 +656,6 @@ static const char *check_nonce(const char *buf, size_t len)
670656
goto leave;
671657
}
672658

673-
noncelen = strlen(nonce);
674659
expect = prepare_push_cert_nonce(service_dir, stamp);
675660
if (noncelen != strlen(expect)) {
676661
/* This is not even the right size. */
@@ -732,9 +717,8 @@ static int check_cert_push_options(const struct string_list *push_options)
732717
buf = option + optionlen + 1;
733718
options_seen++;
734719
if (options_seen > push_options->nr
735-
|| strncmp(push_options->items[options_seen - 1].string,
736-
option, optionlen)
737-
|| push_options->items[options_seen - 1].string[optionlen])
720+
|| xstrncmpz(push_options->items[options_seen - 1].string,
721+
option, optionlen))
738722
return 0;
739723
}
740724

@@ -767,7 +751,7 @@ static void prepare_push_cert_sha1(struct child_process *proc)
767751
check_signature(&sigcheck, push_cert.buf + bogs,
768752
push_cert.len - bogs);
769753

770-
nonce_status = check_nonce(push_cert.buf, bogs);
754+
nonce_status = check_nonce(sigcheck.payload);
771755
}
772756
if (!is_null_oid(&push_cert_oid)) {
773757
strvec_pushf(&proc->env, "GIT_PUSH_CERT=%s",

0 commit comments

Comments
 (0)