From patchwork Fri Aug 2 04:10:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kyle Lippincott X-Patchwork-Id: 13751077 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EC405A955 for ; Fri, 2 Aug 2024 04:10:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722571859; cv=none; b=gAtxJstDwX8OgNtxmg0xvMAq2sQNQ4R/oOMrnL6AuRTbPaL7aOfpt+tVOabBGK280PI5gcMFS5OcF6FLZahNTWDmT2iRawdWVS3MfmEXrQ0aAPDmoq1KVQ2XfCfCUnvLry8RcFp4Rt1YvJxf69X9WjKBgDJN5A7XDPsRnB0H13o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722571859; c=relaxed/simple; bh=R9C9JOqxtsAXJmX1E1KNE9t9idwSw8TxOfDQjFbVCy0=; h=Message-Id:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=LE3PLRt4/ppnYw60vMIawI+uGW7yu3Bcw/SYvYP/zsL/4Y0yV0Ria5AVXDNM7d0wNBRovimHMwMWTs9XtE4lMlTdr35TC2a5stfl+/A39I7YL1Vph2I43uws/S70E7LB0ekL+wei7+0204AMcyRAb6XZLNjdiXzay+oa7jJlDEQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=dzG3H1wI; arc=none smtp.client-ip=209.85.128.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dzG3H1wI" Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-428163f7635so50063165e9.2 for ; Thu, 01 Aug 2024 21:10:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722571856; x=1723176656; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=frlPs7B5IIEUAoWJSbJI83ThdVbBlcNMBDICca+av6w=; b=dzG3H1wI0yl8O4tqzwnRYoH6s+BcqES8KmbLX2KmGEOk9XiLjpWc8Z78KfOp9jQtcy KTNdMyPv0OZIPje8zXfn1dXyvId0e6nkpw/MGu9pyz8MZdshwr28TiHhCDtDC04GasTe CV1wbM1g6KYwJ8l6lbgCuubPB1ipckkM39l67aToYhBe6wg20WZXzhhwShzJZOEBUCUn 4Ys29SrapNhVpM/cSm/qfxNINYoH7NDpzkW+ECOAOOdvzEF9QhJ0S+MycR4HVQRm4FUR 62r4ABYVYMOTBHKF6zrYSx7Kq8IOkDLbWUDbl+d5NZxrJ3oX3TKa0ucignNAr0BfEvrG r/OQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722571856; x=1723176656; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=frlPs7B5IIEUAoWJSbJI83ThdVbBlcNMBDICca+av6w=; b=SIICXip596A9wGcsHojLLvNJkw8sstju7xPvRIz7iyU/pbVOZCRrbvqMD5fBnX329h E6mU4ic1h/0r0QN6U0Nrnx3M/gAZVD7G66IATMWBG4A1bx02cg2JfdJQhcMQCmsoZRRH lnQS2k6TRxTkaJm4DmZnlAbZK2s7m602DchkFm1rYaX5QVC9Ki8iTTx9MDHKa+rd0Fe4 RJcEUylTwpBZmFIprYturhtVuchGku4wGsFQzJlSPD0vLVacZISJMl67Cdt1N5FPlz9P 2gpBncRxYFUZGL7tV2qlnXcCg9KpQS93zIylFCdW3p+Kd+DxwNe6ZyJBDAgzReaZL0Fo y9eQ== X-Gm-Message-State: AOJu0Yx7B7MNJgrvnhQSD31hl3+V+oyqOwmr3cGTk53Vh//xLVX6veLm O/6O+SEpGDA4FFOpO1HZEbVmMdCo0pNVF+ueuzDxZCnlPE0kRmNU/JyZ0g== X-Google-Smtp-Source: AGHT+IFQjJqspyls547okSNfVVjXf0xl8vp1iTkXpZre0UeCBd5sVAppEL0dXC+Eb8Je7VtpYglGQw== X-Received: by 2002:a05:600c:5489:b0:426:5983:ed0a with SMTP id 5b1f17b1804b1-428e6b78e24mr11641935e9.30.1722571855465; Thu, 01 Aug 2024 21:10:55 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-428ea7dc80asm5990705e9.37.2024.08.01.21.10.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Aug 2024 21:10:55 -0700 (PDT) Message-Id: <4dbd0bec40a0f9fd715e07a56bc6f12c4b29a83c.1722571853.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 02 Aug 2024 04:10:51 +0000 Subject: [PATCH 1/3] set errno=0 before strtoX calls Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: Kyle Lippincott , Kyle Lippincott From: Kyle Lippincott From: Kyle Lippincott To detect conversion failure after calls to functions like `strtod`, one can check `errno == ERANGE`. These functions are not guaranteed to set `errno` to `0` on successful conversion, however. Manual manipulation of `errno` can likely be avoided by checking that the output pointer differs from the input pointer, but that's not how other locations, such as parse.c:139, handle this issue; they set errno to 0 prior to executing the function. For every place I could find a strtoX function with an ERANGE check following it, set `errno = 0;` prior to executing the conversion function. Signed-off-by: Kyle Lippincott --- builtin/get-tar-commit-id.c | 1 + ref-filter.c | 1 + t/helper/test-json-writer.c | 2 ++ t/helper/test-trace2.c | 1 + 4 files changed, 5 insertions(+) diff --git a/builtin/get-tar-commit-id.c b/builtin/get-tar-commit-id.c index 66a7389f9f4..7195a072edc 100644 --- a/builtin/get-tar-commit-id.c +++ b/builtin/get-tar-commit-id.c @@ -35,6 +35,7 @@ int cmd_get_tar_commit_id(int argc, const char **argv UNUSED, const char *prefix if (header->typeflag[0] != TYPEFLAG_GLOBAL_HEADER) return 1; + errno = 0; len = strtol(content, &end, 10); if (errno == ERANGE || end == content || len < 0) return 1; diff --git a/ref-filter.c b/ref-filter.c index 8c5e673fc0a..54880a2497a 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -1628,6 +1628,7 @@ static void grab_date(const char *buf, struct atom_value *v, const char *atomnam timestamp = parse_timestamp(eoemail + 2, &zone, 10); if (timestamp == TIME_MAX) goto bad; + errno = 0; tz = strtol(zone, NULL, 10); if ((tz == LONG_MIN || tz == LONG_MAX) && errno == ERANGE) goto bad; diff --git a/t/helper/test-json-writer.c b/t/helper/test-json-writer.c index ed52eb76bfc..a288069b04c 100644 --- a/t/helper/test-json-writer.c +++ b/t/helper/test-json-writer.c @@ -415,6 +415,7 @@ static void get_i(struct line *line, intmax_t *s_in) get_s(line, &s); + errno = 0; *s_in = strtol(s, &endptr, 10); if (*endptr || errno == ERANGE) die("line[%d]: invalid integer value", line->nr); @@ -427,6 +428,7 @@ static void get_d(struct line *line, double *s_in) get_s(line, &s); + errno = 0; *s_in = strtod(s, &endptr); if (*endptr || errno == ERANGE) die("line[%d]: invalid float value", line->nr); diff --git a/t/helper/test-trace2.c b/t/helper/test-trace2.c index cd955ec63e9..c588c273ce7 100644 --- a/t/helper/test-trace2.c +++ b/t/helper/test-trace2.c @@ -26,6 +26,7 @@ static int get_i(int *p_value, const char *data) if (!data || !*data) return MyError; + errno = 0; *p_value = strtol(data, &endptr, 10); if (*endptr || errno == ERANGE) return MyError; From patchwork Fri Aug 2 04:10:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kyle Lippincott X-Patchwork-Id: 13751078 Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A2B88211C for ; Fri, 2 Aug 2024 04:10:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722571860; cv=none; b=NxVmsRLdpPvGqEApjU1id5avEAmqQoKaIzRjOlk/ZQDX42B+xW7Awecl0sf6RdXEYkdVAkb9h8gqzW714rootlEXSUgyqHwsLw/XLp/XF6F13HBS5Nsivk+sX4l06LL8bNjCFjy8xlvxg7cJ/N3Z+/6mmpP1EQ2P80Fdk66haUk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722571860; c=relaxed/simple; bh=LCQfj3yvljHS4ZQEAU/Dd+Azf/aRhLAvu6JOZ0jt9GI=; h=Message-Id:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=WTqKT84k7cdeNunSNnq2Ie1Csn0hmr6q/75dFSN0/YBchGYkGmtGS93H09suEVAvcXz0T/LBeBJUiEQgQue5y8wMIYflNDOHgIkTjkN712bFaTGR4fCRAe1hZhpq7+xH5ZFEVncht9vNssJaSGB31M0fM8x3TDrvVg/P+ODOwZQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=RMGy0Gm+; arc=none smtp.client-ip=209.85.221.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="RMGy0Gm+" Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-3687ea0521cso4999001f8f.1 for ; Thu, 01 Aug 2024 21:10:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722571856; x=1723176656; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=6q9jWaEEVSHSpUVon8iuemQjMxj0VGUTacBAHshjoh0=; b=RMGy0Gm+NWjvE28JNqDyYxgn17X2WGlYKqSCZIIyCz7HbCKpVgbmJkxfFWPiHGgN8r JKQkAO9qMuGMvkf3qszAJ+Yq43dG1/Ga9dnjoYXZ+hg6GaBrxCC3m6hc5q4u20ur8U+1 xtIKCD6XCOQI+TliSQEOc9MdNrsow2ySjFMZQqdWfOnx0BOlYQ/l9j7kVel/Ubjggh7H D8BvJJSi/HT1L2cE61UaQ4NqtiRso1tG4//AGsjNe6l9MSt2v0Xdx639ml0sfIDL3Xvn f6OP3muq4V8OQ+/0T86WJrhRN+rfL5YqvS5IhruL9AHB8IiEKmW6rCppNmAptGeZmTnz eLKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722571856; x=1723176656; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6q9jWaEEVSHSpUVon8iuemQjMxj0VGUTacBAHshjoh0=; b=Z7RBlhmUU5X8htedyJ96bkf/pkUitAibQa3munnwPN/fe3TkMMfdPJxTvzi7vDkTs9 kYL3weHb8K2JXU8dDCS3JJfeD0LuPDbrYFvDU375srHxFmZ2v3VmEqoXWEyZwYjY/svN Ol7MP+Rt3awiCeDU5araNSrCpb1rtYOZhUJ4UuVUuDMN9cVKAsFXrm3v4LwmNyN1BqOK ov/ElzN9WrbFVgz4/Cn0f3k3biI4nzlynk2OuiQICB5ZVbATGGwfSUikbasD712++51x 6y07Vok0eggdg04xymMU9pXPzRBODh034hAVaO71uqVAJgs4YdfkDaGHiiD8SQKgNZfU 2+Cw== X-Gm-Message-State: AOJu0YwbDVAsOnWx5LaKk6MDvSqo2ITMHCMj/0yV1LF3ti1iucPaWenQ VcKfBs1/yXX3xDjwmlKDyPFl3eR4Abq8nw48GRpr8jQ3yu+yWBfdv8gFCw== X-Google-Smtp-Source: AGHT+IFnLmNYO/U1sFuBvVk8gorkrnijHR4GBhByVrRfKK+it/kkdXpCWDxmQ7Fcd9O5AXemmEPn9A== X-Received: by 2002:a05:6000:1c6:b0:364:ee85:e6e4 with SMTP id ffacd0b85a97d-36bbc1c49a3mr1468885f8f.53.1722571856268; Thu, 01 Aug 2024 21:10:56 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-428e08012d7sm47911795e9.22.2024.08.01.21.10.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Aug 2024 21:10:55 -0700 (PDT) Message-Id: <0ed09e9abb85e73a80d044c1ddaed303517752ac.1722571853.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 02 Aug 2024 04:10:52 +0000 Subject: [PATCH 2/3] strbuf: set errno to 0 after strbuf_getcwd Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: Kyle Lippincott , Kyle Lippincott From: Kyle Lippincott From: Kyle Lippincott If the loop executes more than once due to cwd being longer than 128 bytes, then `errno = ERANGE` might persist outside of this function. This technically shouldn't be a problem, as all locations where the value in `errno` is tested should either (a) call a function that's guaranteed to set `errno` to 0 on success, or (b) set `errno` to 0 prior to calling the function that only conditionally sets errno, such as the `strtod` function. In the case of functions in category (b), it's easy to forget to do that. Set `errno = 0;` prior to exiting from `strbuf_getcwd` successfully. This matches the behavior in functions like `run_transaction_hook` (refs.c:2176) and `read_ref_internal` (refs/files-backend.c:564). Signed-off-by: Kyle Lippincott --- strbuf.c | 1 + 1 file changed, 1 insertion(+) diff --git a/strbuf.c b/strbuf.c index 3d2189a7f64..b94ef040ab0 100644 --- a/strbuf.c +++ b/strbuf.c @@ -601,6 +601,7 @@ int strbuf_getcwd(struct strbuf *sb) strbuf_grow(sb, guessed_len); if (getcwd(sb->buf, sb->alloc)) { strbuf_setlen(sb, strlen(sb->buf)); + errno = 0; return 0; } From patchwork Fri Aug 2 04:10:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kyle Lippincott X-Patchwork-Id: 13751079 Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4B5D31803E for ; Fri, 2 Aug 2024 04:10:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722571860; cv=none; b=ruyQHoXwUlSFO8/qmFNLkkpWbQ2QLQ5B5qKVzPCgWXMdfF2uv46+E1SZYbFJlh//Gj73ntqhFYkBmk6q/spzoiGE48Z4/ZJtrf/DVPbQSX5lMLo9jnJ+lLYrB8ZAiExVSJlDuvXqb4ogf6eTOcZh8mJPUz2gkJ5LSVmkGhqBkiQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722571860; c=relaxed/simple; bh=Q2smOYn/9nwE/XI4uFvTO23fO5od+fDsa6rANj3VeGM=; h=Message-Id:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=vCOqGXBP0yAvUnXRFuUWrKq6Tf0uB2jO79BXFK8nMPyQB5ipGzTsLLfp860EuZxG2LxIbyQRWcVLfOy+Chx4zXLfrDS/j7p9ad++c21t8e8deXzOqfFzYyx1HYpIdb+zKylQlfLxLEBuzhSkLNgGYwLrcxnUPSFEZjmUwN7Fjvg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=d0MzceUg; arc=none smtp.client-ip=209.85.128.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="d0MzceUg" Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-4281faefea9so39318915e9.2 for ; Thu, 01 Aug 2024 21:10:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722571857; x=1723176657; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=xPgymNSFqMGy8q4Q/d74fEzd02s89rlrkqP+PWUZPdA=; b=d0MzceUg6vWgHh6ucJcdEVzkjYuxCt2DJ0XBi5DJm5Hkt8DL88WpIIXC/KsKXaHVFR eyijaZSXxtY+tQ9BnfxQFGzsE/bVo/JDWwMH/SytlErVQ4oRS9Tq/N3U2Jxw4XuJ1Di7 efMsEXcLd+qscuIsQXH8FcmgOppH5VI2DV7Sh7Z2vgOTQRL5LNzpptBc5MblGJ8fb4fb qAbpXhHO/gk8OMfwwZk+bSlkP1j6QzOxIDCZPg2g150dQeBTiMaI1+KCemeX+TtOwXDb 2gtmsaL+LNiCeNWqxv0iGHhEJvSVqvm1SdSKu03P+6j/sipdHjnvnnzJibUkUVjDHd1x sNnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722571857; x=1723176657; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xPgymNSFqMGy8q4Q/d74fEzd02s89rlrkqP+PWUZPdA=; b=WAlOFt2OFHHWYMpMuOIOh0kd1XKrXSI5ldTVnD5f65RxwgUGTiUFnPQ0cWQrsLy7b7 VfvKPYo6Mq5D8y0tY1j0qjrV/GVJOvBCFyL8x33zvfoyg/RUn3imx+oCuEsp5bpSuq4c GrkQ23K5ouVVt/OM2jWxi5XxYLTdKKjzAaKKPDwnGUsMX61JzM7aACY6fHQXNFCmsPDn HMLY6ajq4OYVc74rzXC6GZkA/WPiv7uH5fMQ8rJnQIw2s+YotC+uSRRlO0FUDeOoF/U1 io9KaLAalme//atARK/OYYmrSNapPnqgMr+0+6KOCixC4qDg77e7Ba7AS2thjnm+5VUz v6pw== X-Gm-Message-State: AOJu0YxSyRi2gACnL2479uc93KOfzyid0kcGo5/PXn6JZokQpNjIDIfw 9YLBuJpXNCNHT9R68Hgvh6bh2WWRO2fnU20Ifwn5j+I4ZzsUePllPQSXHA== X-Google-Smtp-Source: AGHT+IHq0sXsW8xtpgp1vEq+h7LVuJsYObslkvhh3hdKeVUFBryOCGfvdmkJSWnKLtmwSTh+mtIAag== X-Received: by 2002:a5d:4844:0:b0:368:7fca:9040 with SMTP id ffacd0b85a97d-36bbc1bcbedmr1143287f8f.39.1722571856974; Thu, 01 Aug 2024 21:10:56 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-36bbd26f9c2sm904633f8f.116.2024.08.01.21.10.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Aug 2024 21:10:56 -0700 (PDT) Message-Id: <6c08b8ceb2b87671a3e57c09e4e45170eaac37fc.1722571853.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 02 Aug 2024 04:10:53 +0000 Subject: [PATCH 3/3] t6421: fix test to work when repo dir contains d0 Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: Kyle Lippincott , Kyle Lippincott From: Kyle Lippincott From: Kyle Lippincott The `grep` statement in this test looks for `d0.*`, attempting to filter to only show lines that had tabular output where the 2nd column had `d0` and the final column had a substring of [`git -c `]`fetch.negotiationAlgorithm`. These lines also have `child_start` in the 4th column, but this isn't part of the condition. A subsequent line will have `d1` in the 2nd column, `start` in the 4th column, and `/path/to/git/git -c fetch.negotiationAlgorihm` in the final column. If `/path/to/git/git` contains the substring `d0`, then this line is included by `grep` as well as the desired line, leading to an effective doubling of the number of lines, and test failures. Tighten the grep expression to require `d0` to be surrounded by spaces, and to have the `child_start` label. Signed-off-by: Kyle Lippincott --- t/t6421-merge-partial-clone.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/t/t6421-merge-partial-clone.sh b/t/t6421-merge-partial-clone.sh index 711b709e755..0f312ac93dc 100755 --- a/t/t6421-merge-partial-clone.sh +++ b/t/t6421-merge-partial-clone.sh @@ -231,7 +231,7 @@ test_expect_merge_algorithm failure success 'Objects downloaded for single relev test_cmp expect actual && # Check the number of fetch commands exec-ed - grep d0.*fetch.negotiationAlgorithm trace.output >fetches && + grep " d0 .* child_start .*fetch.negotiationAlgorithm" trace.output >fetches && test_line_count = 2 fetches && git rev-list --objects --all --missing=print | @@ -319,7 +319,7 @@ test_expect_merge_algorithm failure success 'Objects downloaded when a directory test_cmp expect actual && # Check the number of fetch commands exec-ed - grep d0.*fetch.negotiationAlgorithm trace.output >fetches && + grep " d0 .* child_start .*fetch.negotiationAlgorithm" trace.output >fetches && test_line_count = 1 fetches && git rev-list --objects --all --missing=print | @@ -423,7 +423,7 @@ test_expect_merge_algorithm failure success 'Objects downloaded with lots of ren test_cmp expect actual && # Check the number of fetch commands exec-ed - grep d0.*fetch.negotiationAlgorithm trace.output >fetches && + grep " d0 .* child_start .*fetch.negotiationAlgorithm" trace.output >fetches && test_line_count = 4 fetches && git rev-list --objects --all --missing=print |