summaryrefslogtreecommitdiff
path: root/commit.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2022-02-05 09:42:29 -0800
committerJunio C Hamano <gitster@pobox.com>2022-02-05 09:42:29 -0800
commit492261a6def32669ddea7103ceb4d18c9b80903f (patch)
tree0671872002d2bf49d3094c966a588de16e72a4e6 /commit.c
parent7a9ae6d0d9cf979a2b1a018135370dd6331e505c (diff)
parentcfc5cf428bcc8ff31748bba97baee31f529a30ea (diff)
Merge branch 'jc/find-header'
Code clean-up. * jc/find-header: receive-pack.c: consolidate find header logic
Diffstat (limited to 'commit.c')
-rw-r--r--commit.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/commit.c b/commit.c
index a348f085b2..28391c3468 100644
--- a/commit.c
+++ b/commit.c
@@ -1631,12 +1631,20 @@ struct commit_list **commit_list_append(struct commit *commit,
return &new_commit->next;
}
-const char *find_commit_header(const char *msg, const char *key, size_t *out_len)
+const char *find_header_mem(const char *msg, size_t len,
+ const char *key, size_t *out_len)
{
int key_len = strlen(key);
const char *line = msg;
- while (line) {
+ /*
+ * NEEDSWORK: It's possible for strchrnul() to scan beyond the range
+ * given by len. However, current callers are safe because they compute
+ * len by scanning a NUL-terminated block of memory starting at msg.
+ * Nonetheless, it would be better to ensure the function does not look
+ * at msg beyond the len provided by the caller.
+ */
+ while (line && line < msg + len) {
const char *eol = strchrnul(line, '\n');
if (line == eol)
@@ -1653,6 +1661,10 @@ const char *find_commit_header(const char *msg, const char *key, size_t *out_len
return NULL;
}
+const char *find_commit_header(const char *msg, const char *key, size_t *out_len)
+{
+ return find_header_mem(msg, strlen(msg), key, out_len);
+}
/*
* Inspect the given string and determine the true "end" of the log message, in
* order to find where to put a new Signed-off-by trailer. Ignored are