From patchwork Fri Feb 9 20:36:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ren=C3=A9_Scharfe?= X-Patchwork-Id: 13551789 Received: from mout.web.de (mout.web.de [217.72.192.78]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1270ACA66 for ; Fri, 9 Feb 2024 20:37:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.72.192.78 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707511024; cv=none; b=CrA2jeQeEhcyXUxFQC1X9oj/+mv+klLRNbdC37kqPD5TVFsIFdUhyTRnZb+waiNgkkgGG8IAIEoWi9IBmlv2mWofg61GZv6Yzuw/hrz6Vn+difFXwKsUK5zrUt4NlCHgkSYCKV/ikg+HQInx4uEgrbgc9dqSEh9GUfx0J8Ofonc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707511024; c=relaxed/simple; bh=fM0GTAsgMbg4fQ7aGF72rrfpV0dIpdySiFKqjnEl9gg=; h=Message-ID:Date:MIME-Version:To:Cc:From:Subject:Content-Type; b=opJC9zGnrdhSYAvikMUjI/YKNyFhvtYsOvZuvLk2NaHdoXRrFf5UUMs1wGrUMR/rd/hOP3DCRoX/EtnZhxNlvaWf7FYvCmBYA3HbjTggQXBF/lB0knrYHdfAsQCzqjoHhuNEYyak2M9XsWJ3uTx7QCOBjJ8JoGwLI3Zw59tco18= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=web.de; spf=pass smtp.mailfrom=web.de; dkim=pass (2048-bit key) header.d=web.de header.i=l.s.r@web.de header.b=hktkhEYj; arc=none smtp.client-ip=217.72.192.78 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=web.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=web.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=web.de header.i=l.s.r@web.de header.b="hktkhEYj" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1707511001; x=1708115801; i=l.s.r@web.de; bh=fM0GTAsgMbg4fQ7aGF72rrfpV0dIpdySiFKqjnEl9gg=; h=X-UI-Sender-Class:Date:To:Cc:From:Subject; b=hktkhEYjHy9jOF2iTiVJXO2F5HwGVv94H0i4PcS420Sy0FrfEG+WrlnS2aeVwKod sC/oQDBZK7vqf5rH+x/c7AoAZjLHGgOpj0Tx8eVdu6ont7q5M41q34KY04087cK/y er0gsG9UIdVAbaTbRo+PHFtYar2GnnAABWILHeKpYPoBQTAZPqJ+rRzeS9I3H9oTg 5ZluvFHj8aqsy2BeI0Bu1djQG6iDewlz/TZxrhA0Vhe7KizemTMWSlMZAekVicutn Osn2rsKZp9sSRU3P2I65ffLbCt4Zecx2kE5ZyajdZvkGdxtm6xv1GSRuxMyjOzKgf JaZVA466FXfY4QIKVg== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from [192.168.178.29] ([79.203.17.81]) by smtp.web.de (mrweb105 [213.165.67.124]) with ESMTPSA (Nemesis) id 1MPrPV-1rL9is2bBb-00MsVA; Fri, 09 Feb 2024 21:36:41 +0100 Message-ID: Date: Fri, 9 Feb 2024 21:36:40 +0100 Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: Git List Cc: Chandra Pratap , Chandra Pratap , Jeff King , Kyle Lippincott , John Cai , Junio C Hamano From: =?utf-8?q?Ren=C3=A9_Scharfe?= Subject: [PATCH 1/2] receive-pack: use find_commit_header() in check_cert_push_options() X-Provags-ID: V03:K1:rbjvgsWTxCk5BzuevGjz0+OHxiftrDNsWtxQZxEmRyYEZ6bnXFD 8Bn/1ipexNU0TpY1/OxCo09IIDkkme2i327D+tKG8dwy80o06DOp1ldPvwUL7oQVwc8X3+q BCfgWsUf8AkzaAdOR2w0iSmXdTm2TJGuCd5tN4Gc6IOOouLTtIO0KYY5hlIIWygTQJYmDt9 Af0XWQ0sHfMGxKI6cgnRA== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:EpnHZpVT+Eg=;3KEZT4Wdi+v7qxXX4A1SgRFkyKI C6zbCbOx9qGeWemd5OdrT98Mv3FgymyIOjfpnsZ/nVqczWP/50Id/z+CmuUZKJtB9+EDWjsnE lpUVGpNpRhEzjNpCcEoVAYtdcUyqTkMVmxA0hsm5MhRjV7qn/myrw2TL2v5U2nuwqwWcEBD/b L/JT9fB7buXV7SwsEKPq/2n6p7boQB9p+XOcaPFme3DPHX2jrQw5zaNMFWyWFzJn0n1A6oaiK EZrJGduj6YLfDLVLbp1bT7e4FDeRbgymkjL6UwfrX/VZq6k6YlTcKhyF/eUKZUBrMnezM13Gw SXAWpYCrxC+rKm28Z/UR2RBZ0xZKzoZEanOvOcA+eWeihjrL3Xy9LvcEWNJd+1TrjSz6tyIVr oTzIxzR+fmydgZC+8Eh5WAe6943w8w9qvMd2OIQ53lNaJqAnX60KnXnq0mdcV5+lpItY2tmLw z3mP5DWhuDatpQuD8F1Q/j+/oNVH3DtQSwMaeKakmHyqnYhpT41z1FzAN6uhAN/w4eIuG9I0r akL4KKowDiIoMyrfUVhnlScrEkuL8wVRL2C2qsYFWqbL67CM2lt+10jnx/CH88qGZN5lohUtp HH4fvPElxV8R6xpmgTmyOTWBrIPosFYFGFbNWwJlqkOG1bkBIoHRGY66arWgtdwk3l9ffaVKW ilj00fZHHnK3UpfFMdaeWuXcHGy22SQ6HFgexluVrQzNxjpZnxgXjvD6JBu4n7i8TIU7yHCN0 OARhx/PHUceXLU33bmuMr2LyLttqGq3Bg56PPs/VuwyY+LkO1kHfIv3WNa5KP78QyJkgvAOyX M6+Zrrbg+BSs09uKed5xmMNTuAzK+aPiaEd+p4t63jps8= 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 --- builtin/receive-pack.c | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) -- 2.43.0 diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index e36b1d619f..8ebb3a872f 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -718,35 +718,29 @@ static const char *check_nonce(const char *buf, size_t len) static int check_cert_push_options(const struct string_list *push_options) { const char *buf = push_cert.buf; - int len = push_cert.len; - char *option; - const char *next_line; + const char *option; + size_t optionlen; int options_seen = 0; int retval = 1; - if (!len) + if (!*buf) return 1; - while ((option = find_header(buf, len, "push-option", &next_line))) { - len -= (next_line - buf); - buf = next_line; + while ((option = find_commit_header(buf, "push-option", &optionlen))) { + buf = option + optionlen + 1; options_seen++; if (options_seen > push_options->nr - || strcmp(option, - push_options->items[options_seen - 1].string)) { - retval = 0; - goto leave; - } - free(option); + || strncmp(push_options->items[options_seen - 1].string, + option, optionlen) + || push_options->items[options_seen - 1].string[optionlen]) + return 0; } if (options_seen != push_options->nr) retval = 0; -leave: - free(option); return retval; } From patchwork Fri Feb 9 20:41:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ren=C3=A9_Scharfe?= X-Patchwork-Id: 13551804 Received: from mout.web.de (mout.web.de [212.227.17.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D87F263A7 for ; Fri, 9 Feb 2024 20:42:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=212.227.17.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707511329; cv=none; b=qBtumt3Tg8TdUvLBb8592njlekagVE71xh03X6AFPNBWavFV0W+zhdpdQ9vjBGpX+v1PpH+9KHYSkSlDXhPxnp7yNbxvEqWVwvbp5f39+oF2FrYMMx610BT+ek86qCb5N8yX0q8OMcKBjG8AwQsEmaFXu5zh4maNysD79nz2scg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707511329; c=relaxed/simple; bh=cJ00YPPfc+eeUDmaJyV8HOAl1hXzny9bwtSSDE2qBS8=; h=Message-ID:Date:MIME-Version:Subject:From:To:Cc:References: In-Reply-To:Content-Type; b=Q4fUKmz8pjNiEFWNnwAudf6ZFc8pxrZ+OhV4PMBo8VrauV/kMRSXa+D3KmvBJcbmF3e7F4XzPe7k95RtrH6Ljv1da0v32cnO2Kvf7czlefoJr9aQboi/k5GVSNDfEJaJRulm3jyQEhXe1Hfb7aVjAMHb36uFiQ/WZkWh97DTj1Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=web.de; spf=pass smtp.mailfrom=web.de; dkim=pass (2048-bit key) header.d=web.de header.i=l.s.r@web.de header.b=LdykzOQM; arc=none smtp.client-ip=212.227.17.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=web.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=web.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=web.de header.i=l.s.r@web.de header.b="LdykzOQM" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1707511308; x=1708116108; i=l.s.r@web.de; bh=cJ00YPPfc+eeUDmaJyV8HOAl1hXzny9bwtSSDE2qBS8=; h=X-UI-Sender-Class:Date:Subject:From:To:Cc:References: In-Reply-To; b=LdykzOQMmJngygFlLqcUEOkqhEKL4JWSp12Scr5jGVjixOuERDgFsicZgWfIWTq3 6xKAaeBxG4w6LCTr0lZBVntRfjZso4utBCyS1m0++0iV4kU9vxuffJgPJv5pyeCm4 lZ5VhmhY3m57zpbr8BaDD9U7H/EdV+GuLLnbzDmOrhxaeAFsSzxJ+Yvfp9jJFkTwn Ulr7oPtPxBbpZLCKfgrcEeNP0gnxk1FaZrRuYXrHY4eouJDcS7+MT4rNthH+q4PKD K2GPk9+eADCk8Htjv709UrcvSpSi18NcDqJKQPpXOdgFuF0vVsFeaxGkOOzo7cFvs d5VMUs3coav8TkbUdw== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from [192.168.178.29] ([79.203.17.81]) by smtp.web.de (mrweb105 [213.165.67.124]) with ESMTPSA (Nemesis) id 1MC0PP-1rijuI3gNB-00CS4a; Fri, 09 Feb 2024 21:41:47 +0100 Message-ID: <8b350cae-2180-4ac7-a911-d40043576445@web.de> Date: Fri, 9 Feb 2024 21:41:47 +0100 Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH 2/2] receive-pack: use find_commit_header() in check_nonce() Content-Language: en-US From: =?utf-8?q?Ren=C3=A9_Scharfe?= To: Git List Cc: Chandra Pratap , Chandra Pratap , Jeff King , Kyle Lippincott , John Cai , Junio C Hamano References: In-Reply-To: X-Provags-ID: V03:K1:uZpbQwgqWu4xYiKuy0rmUePUZXCpIzAe5YGCEWAzGITLjmQfKTB oznsvfb1rZe2x5CEXSL5UkPezS16T9Gd9IJNagP3n1IE8Rcl9JBNLw7Ljwp0MU7vJ3+hQxO 3ONtpgOfTJXB7lF+xm9Mx9HUish8pr5V18gFr/CY5Cl10Xc2tRWNiN0ZAF0vtjklknwk52T kiEH7EZ7RvWxL07F676tw== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:xeRzycT1sW4=;9t2P4fbdKxHd/itXMYh/XaAvrrC +1crT2TyHOY8QqMlM8rMmF7oJBn6LPoEDy9/IWFuIBKD0PvWsVKWFGgymcbWkhme4nqd5zWCw 9/8Bg76ufuOabq9RKjxCAu3EnAPMWOJl6zL8Jz+tSCCVOikIfUDBPe25HWToldyW+jVkEbpan DSQGPWlCUKH0cpfiHj8gSXuLlqv0zHf3axeLIm+EznXnJ3a/s+2aHMCM6/aBrNbDMLTAucg9G AtduhvSp+eErRAu/3MXB2/ukmuD7Sv6kgYoI9rx8g991Kan9iGbWhSPrzlfT+GPTWCS9n52RF lh+7zC7KWCthZx6YPBbUHlBnA27SOTtju5MSGfo+jVw/6JAj3r9i5BK9gqrMJuUyebtt0lK/j 6uHNF5dUxlFEtKPqTb+cEhYc5/x7YZCkYhQAm887b3+7xbT9CDpG2EKu/dGmvEXO4ZxOPI0Yb YOhHgsaAeayABgEEgFaeObEVe7XI7aR86f0ZzXiWVLGoltM6ioQSZe/WSj4HOj3FZoakRN4xt H/gvQVUYu4xajxxGH3/OdCM5MsqJXSY+tDwSgmxx+GncPLyy8KnCmLsjuN4qjM4SKrGyjnYTP o1+3U/TOF3lC8/zNHwmflRTzw8KXSh2Y4GnfHlhHdvYZ2JE19a7ZoLK7e5LsFQF0F7zxT/7WT CaJB/z3Okel2dVsN90rz15T8Hz4Tt0elzeg27UctPNIeWlgLxlv4Ct7JM8sd+ow+/H0sA3H7t kxXskQEyUrV7OyD10xDwnY5Zps2NitrdfHNxD1Yvpa+mXfvKPNIuyVx8xoHOUcNcMAgPCJrqE VLt1or8Qoo969ilRtRVhqkiPaMjr4+ZF4kHADbFdHDlrg= 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 --- Formatted with -U5 for easier review. Removing find_header_mem(), which basically becomes unused, left as an exercise for the reader. ;) builtin/receive-pack.c | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-) -- 2.43.0 diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index 8ebb3a872f..dbee508775 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -591,25 +591,10 @@ static char *prepare_push_cert_nonce(const char *path, timestamp_t stamp) /* RFC 2104 5. HMAC-SHA1 or HMAC-SHA256 */ strbuf_addf(&buf, "%"PRItime"-%.*s", stamp, (int)the_hash_algo->hexsz, hash_to_hex(hash)); return strbuf_detach(&buf, NULL); } -static char *find_header(const char *msg, size_t len, const char *key, - const char **next_line) -{ - size_t out_len; - const char *val = find_header_mem(msg, len, key, &out_len); - - if (!val) - return NULL; - - if (next_line) - *next_line = val + out_len + 1; - - return xmemdupz(val, out_len); -} - /* * Return zero if a and b are equal up to n bytes and nonzero if they are not. * This operation is guaranteed to run in constant time to avoid leaking data. */ static int constant_memequal(const char *a, const char *b, size_t n) @@ -620,17 +605,18 @@ static int constant_memequal(const char *a, const char *b, size_t n) for (i = 0; i < n; i++) res |= a[i] ^ b[i]; return res; } -static const char *check_nonce(const char *buf, size_t len) +static const char *check_nonce(const char *buf) { - char *nonce = find_header(buf, len, "nonce", NULL); + size_t noncelen; + const char *found = find_commit_header(buf, "nonce", &noncelen); + char *nonce = found ? xmemdupz(found, noncelen) : NULL; timestamp_t stamp, ostamp; char *bohmac, *expect = NULL; const char *retval = NONCE_BAD; - size_t noncelen; if (!nonce) { retval = NONCE_MISSING; goto leave; } else if (!push_cert_nonce) { @@ -668,11 +654,10 @@ static const char *check_nonce(const char *buf, size_t len) if (bohmac == nonce || bohmac[0] != '-') { retval = NONCE_BAD; goto leave; } - noncelen = strlen(nonce); expect = prepare_push_cert_nonce(service_dir, stamp); if (noncelen != strlen(expect)) { /* This is not even the right size. */ retval = NONCE_BAD; goto leave; @@ -765,11 +750,11 @@ static void prepare_push_cert_sha1(struct child_process *proc) sigcheck.payload = xmemdupz(push_cert.buf, bogs); sigcheck.payload_len = bogs; check_signature(&sigcheck, push_cert.buf + bogs, push_cert.len - bogs); - nonce_status = check_nonce(push_cert.buf, bogs); + nonce_status = check_nonce(sigcheck.payload); } if (!is_null_oid(&push_cert_oid)) { strvec_pushf(&proc->env, "GIT_PUSH_CERT=%s", oid_to_hex(&push_cert_oid)); strvec_pushf(&proc->env, "GIT_PUSH_CERT_SIGNER=%s", From patchwork Wed Jun 19 17:13:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ren=C3=A9_Scharfe?= X-Patchwork-Id: 13704312 Received: from mout.web.de (mout.web.de [212.227.17.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 40190155744 for ; Wed, 19 Jun 2024 17:13:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=212.227.17.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718817217; cv=none; b=UHtWPDYnWO3EWu0o48NfkFdsm9FojDr8TbKRmim4z0nTOkwYPjBQb7Zqi/t31n5xQUwGVhLUnzF5Fbdyh6i35S9U2UOm7M6sMH2VB/rpu/hmUdckK4QF5Ack2/Zvv5R4gQ8j6S5Sv3K+VzlasaBdT5CVae9WQBZHhMX9vGE6PA0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718817217; c=relaxed/simple; bh=JzBEFEUnR8As3RhIvcBB4ZvUgueYTN/7Xwr+alSwOMI=; h=Message-ID:Date:MIME-Version:Subject:From:To:Cc:References: In-Reply-To:Content-Type; b=jPLrZixnoC7FBYWARmukdwO6/QER/yLmXsCOX+VMAqvbCQ7oCXJSh2CpxX3TvAAiEFszRuyChVYVmCIqskw/Nev3E+3w3pb/lDUeVQQMZZgH0cT5oxYGL7MD3r6cM40tkdHYbvkXExXgGxPt6w5LLHPPqG94FhBWGhWl5/FYhDg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=web.de; spf=pass smtp.mailfrom=web.de; dkim=pass (2048-bit key) header.d=web.de header.i=l.s.r@web.de header.b=CRyxv4F9; arc=none smtp.client-ip=212.227.17.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=web.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=web.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=web.de header.i=l.s.r@web.de header.b="CRyxv4F9" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=web.de; s=s29768273; t=1718817200; x=1719422000; i=l.s.r@web.de; bh=GdZMsX8Mg5zgDf5BYdU0wibjZaV17STZPzNsEuIoJuk=; h=X-UI-Sender-Class:Message-ID:Date:MIME-Version:Subject:From:To: Cc:References:In-Reply-To:Content-Type:Content-Transfer-Encoding: cc:content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=CRyxv4F9DcsMrXTGaz2YCKccFWf3pTXFjVZpamQH5Cm6PQH5XCsf1phgtEj7Z2/W q0IEPlDmubTubwHIU6xheXloc2s+AT0B7PAn8cTzApPz4vGc/454x/pfYHX328Qan vH700AHcLSIgryRBwxndtYRvxvmyNYTQgC2ivIShFgF2fryo7QX+FCa/qCTMK0gCN S1ss3j0pjDSo6Zo0P2ipfYKZbRFT4X+W5cZ1Whc18qEq2Wn9UHBSMSiH6Xgam2Qlu L/6H0TCZquQWxxT5Rhpm4wDFDrkWLVl+vploGq3pismDUn0Ma3mtjFjF+Vp6cczpH /RShYrNPsjtA7ycdVQ== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from [192.168.178.29] ([91.47.153.5]) by smtp.web.de (mrweb105 [213.165.67.124]) with ESMTPSA (Nemesis) id 1N0Igv-1sXeJ63lkF-013nzH; Wed, 19 Jun 2024 19:13:19 +0200 Message-ID: <0d85712c-5beb-4a64-a7f4-797782c26694@web.de> Date: Wed, 19 Jun 2024 19:13:19 +0200 Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH 3/2] commit: remove find_header_mem() From: =?utf-8?q?Ren=C3=A9_Scharfe?= To: Git List Cc: Chandra Pratap , Chandra Pratap , Jeff King , Kyle Lippincott , John Cai , Junio C Hamano References: <8b350cae-2180-4ac7-a911-d40043576445@web.de> Content-Language: en-US In-Reply-To: <8b350cae-2180-4ac7-a911-d40043576445@web.de> X-Provags-ID: V03:K1:a1cE0dxix7oEXPbQDBJkl/xLSS/SvzJonp9/VqvWPhl0PqrMYhF MYZuZQ9kUC+TGkl9lAsjzuOw+2V6CDi+NiDJAVt6cora34f4X/qbh8tS7YjTpErsbrnNTB5 6V28gUWU1wqsSUrCYhQMG9AGqr9BHhBZjELG94nnUMo4eM2cZPvFYA+eEl7XC7kcJYXGkdK Q9wQ7jweqIDoXLYhFM5pg== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:5KAdszFmKag=;gUaaC3v79i2pS7nQfR0oCQI2uYh F5sLanaUal0wt7jwR4IbSvpwEZcaLQqZxSUkiAc4I7SWIOI0PST9ILGyGO/6B36irq3ESebnq iNhN3AcaJWMu4LMco4/fMvSKG8pQI6Iq2VLCTAf6kl8vNuYMbQ+h4s7KgGu5gqIOUpV7PrAIw 8S1Hax5WB49pg7/ndIlHPGv7NGH6Xk55EZzcU0wRQg3piYvlVmzzSLyurinK8/mC4y3cGG50/ cm7gwL59+ZWN+6NIS5xhi8Sqyd8oEOW3/pYUWLodU/Xth+yGbp3YeQGpQWyRVoC3u873QtUqD zSKrxmYYircNM/seGRpOXK0+GJuixrPUmeBxV5KXBYVb6KlfMY5+Ij7LY0fMrNfM2mI2r5t64 +peJEImyI2hajy3E8XzvvfGODKC6yQTAs2UudsAskw7fs8LT8TFFkutpn9WGCEooOSl3qMLVK yyG/ZkKhuaHZndUJapnB8CCXpA6qmKbDi1cHq2FBZsZdMYTVTUBd+OaPMzepj3WQvaJBLBJYb 8EjiGCAGBqWWH97sn/extkDJuPZmrbZO0zP/z0Yry58QX/Kg9lNKPxNXXuIwX56dqI6T+vaTd /s5MDQbX7+b4ZLdwsH6YwOSGwrO0xFTUZ7TrqEwSpfqfE7BacweeQR9925ijp64nSw6wLmd/V SmPGv0eo2jsFp0iLi3V8Oj4WY0onjCsifnTRlKmtENsRYlb0jblNR9Xop+wr3YFNykQq7cbmF rMozIOe/PF/2HhCnCkTRSOBsT6QCxTlnFwRnRCVRbbjVHJZXg7d7wkCqNTlsIv8Xo94xfL1Ut 0Z8sU5wXHctmjqQZwAsxbmWRXHGNC0162q18dL5Agpuaw= cfc5cf428b (receive-pack.c: consolidate find header logic, 2022-01-06) introduced find_header_mem() and turned find_commit_header() into a thin wrapper. Since then, the latter has become the last remaining caller of the former. Remove it to restore find_commit_header() to the state before cfc5cf428b, get rid of a strlen(3) call and resolve a NEEDSWORK note in the process. Signed-off-by: René Scharfe --- commit.c | 16 ++-------------- commit.h | 5 ----- 2 files changed, 2 insertions(+), 19 deletions(-) -- 2.45.2 diff --git a/commit.c b/commit.c index 1d08951007..aacc401e72 100644 --- a/commit.c +++ b/commit.c @@ -1870,20 +1870,12 @@ struct commit_list **commit_list_append(struct commit *commit, return &new_commit->next; } -const char *find_header_mem(const char *msg, size_t len, - const char *key, size_t *out_len) +const char *find_commit_header(const char *msg, const char *key, size_t *out_len) { int key_len = strlen(key); const char *line = msg; - /* - * 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) { + while (line) { const char *eol = strchrnul(line, '\n'); if (line == eol) @@ -1900,10 +1892,6 @@ const char *find_header_mem(const char *msg, size_t 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 diff --git a/commit.h b/commit.h index 62fe0d77a7..3084f591fd 100644 --- a/commit.h +++ b/commit.h @@ -280,17 +280,12 @@ void free_commit_extra_headers(struct commit_extra_header *extra); /* * Search the commit object contents given by "msg" for the header "key". - * Reads up to "len" bytes of "msg". * Returns a pointer to the start of the header contents, or NULL. The length * of the header, up to the first newline, is returned via out_len. * * Note that some headers (like mergetag) may be multi-line. It is the caller's * responsibility to parse further in this case! */ -const char *find_header_mem(const char *msg, size_t len, - const char *key, - size_t *out_len); - const char *find_commit_header(const char *msg, const char *key, size_t *out_len);