From patchwork Mon Aug 5 17:10:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kyle Lippincott X-Patchwork-Id: 13753871 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (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 31FB415E5BA for ; Mon, 5 Aug 2024 17:10:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722877813; cv=none; b=tYKrzWDJLXkKoJ/FunzSuythQaFQ6iGAL3HyjsszIL/3u7kd9gw2050TmfKLFVXLQJSM87c1lslRMnOfbTN46eN23rikV6KrIAgefnZgwB3SR6CMkuBw8tqxgckJmLDoeePUNKzsoMHyj++ijG6z/Y6EfUdRFqdDF7xpSuHL9p0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722877813; c=relaxed/simple; bh=R9C9JOqxtsAXJmX1E1KNE9t9idwSw8TxOfDQjFbVCy0=; h=Message-Id:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=u1KFM6+XbL7CsfennZyWikGx87kCf+gscxRPIyAym1/u3AIXc1p1tkBmqwhDRWhC2MR+f+neJ17VTFaXWlP2Bm/JUjFic6VrgItqrunwp2LPvC411ViXtkfrAs/WE/25cN+av9gCMqSOGDIpSqmeFTgkFQmXzhgNv4lhHQgrLOQ= 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=EwNQLo6r; arc=none smtp.client-ip=209.85.128.48 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="EwNQLo6r" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-4281faefea9so61782975e9.2 for ; Mon, 05 Aug 2024 10:10:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722877810; x=1723482610; 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=EwNQLo6rRJs0AQLkgF06gc0yah7Oa1y3UtZJXVPbuTqWKlZoij40h9Ky08r62sfsUd JWiDROKOnsFvqJ2jgPZBKlLwZjKx7ORO1licLM5ZR8UsOIvs4hulqC5qCD1ttW+q363U 6ao4brT/fFQJliG6H26Mmusj0iYDuoi7BO0Ay48bm8ztAe5eNJS522m3RI7kxtv+Sjjy O/hjb0Na96p6ZX8OMN14L2w/cNXXUWeNbeNOYNC7ttv6T2Ca/DHdmEwZIAgdR7U3FqL8 pyHHwJZMKhHmWNO1XREid3UaAQyVmvcCLkzydfQ71cFqrSm0Lq/V6cKa4a9JemxM03zL 0BwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722877810; x=1723482610; 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=bfcCbZocZ5tYyAxoS5K9III7R1bvJzlJm7UJ+DJ6f7Eu+jSI3T96p/2TBctel/rYiR CC15ZbbOcQSQLXcyElMkeW+gj3FJ/53tGWGs9A+A2V1ti6WTCUervGR0Wd4JxK1xo0SZ a720CjyHLzRhY2pmCcxZuCklXboXzbgGH8peyY1sXWKXI9E14oUyEhbxM+6b9PkwP6gQ GH34Qw/PFJ/WvZMVikzoIrtTWX3I0JSl1dyW3ZWZBHVYOfS1lZZ3ETCuEAmJ4YhhDplf rxnO5xvV8sJMvPjkQ1GLKdqhcRrO2dLioIvyb2YocbMfUZsiT21IzOYThucIRc/EzPWJ yvxw== X-Gm-Message-State: AOJu0YzccRnP/TY4e6+eS6kB5a2SYfTio1ZTjrWrT0kkorFPmC/HwDch 7+mDBoICxDDJmalO8dnSiMRoAJiUoXc8rYZUQG55Mr9SGSbExZoh4wY8vA== X-Google-Smtp-Source: AGHT+IGmvtADSn+98ANfnQ8Pr/JFzkP2rQLNdJbMgE+h2mF8D89nE2rD1PA2FftI7A2ObWbp1hDi3g== X-Received: by 2002:a05:600c:1f92:b0:426:6f62:3bc1 with SMTP id 5b1f17b1804b1-428e6af23f4mr69669025e9.5.1722877809956; Mon, 05 Aug 2024 10:10:09 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-428e6e9c9fdsm147168855e9.41.2024.08.05.10.10.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Aug 2024 10:10:09 -0700 (PDT) Message-Id: <4dbd0bec40a0f9fd715e07a56bc6f12c4b29a83c.1722877808.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 05 Aug 2024 17:10:07 +0000 Subject: [PATCH v3 1/2] 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: Patrick Steinhardt , Eric Sunshine , 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 Mon Aug 5 17:10:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kyle Lippincott X-Patchwork-Id: 13753872 Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) (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 1CF9015EFAA for ; Mon, 5 Aug 2024 17:10:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722877814; cv=none; b=mBxPnxBeI+Wz9K6nICnVQ48v1F6dQhNwLGXbjrqKCf8C61lZMscYWdB3hZkXccJww7If5RPHjinCZNCzGI6+1GBewkuo4D8UYUPQb6Vt3PvJDXp4LviNrEfju0QcALPuVVu63v+zQ5RXQoaNY/25+f/0dWd85CWJ4ph8jdilKiE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722877814; c=relaxed/simple; bh=cpHQERrBy/e+QlEOrk1xWanbWtQ6/SnI7s2Iub2Ue+Y=; h=Message-Id:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=IrBOKX5DSYs6enO9XMZHKrnEtqjU6BlWkaY06Ib3rqLL5b7eB3wCk5viF/Rvh3Ni9iqskjmuob4jpwwhm3cMpvwnP01Cr0kHuBZl2fbsxRj75zIaStFEFyvcCYNe3jG/SlDzbvjYL2bEZroQ6a41g4VpK4q3da8OUEh49ottBPM= 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=iAB1GWGC; arc=none smtp.client-ip=209.85.221.47 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="iAB1GWGC" Received: by mail-wr1-f47.google.com with SMTP id ffacd0b85a97d-3685b9c8998so5205724f8f.0 for ; Mon, 05 Aug 2024 10:10:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722877811; x=1723482611; 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=/HQe48C7retWVgU11VG8KpaLIFiEtdB+eb7jfq+1CxM=; b=iAB1GWGCzpmO+z+IIPtaMS2H4+vVOeqcMuHX6UZgcZCNrxoJu7KrMtWrT9XxhMuit1 VadfRxgWKCdwKLs2XM76INxiSOwG1uFggjvr4/nb9dcpBUcynsF3bgmXnXhF0/o1Gi7c 8PTAGdnT47eAsu+e7UjAOyz+0uLo6sf9chjGNEshk+IqtJ+nfcKHCXAOkli9nHqeU0/J Acmn0wVtkko/4MX/BZU9va+d3BCGyPzkO9Y+Qy18oHwnooTuZGOrSjq5EmDG+aGpOr2t qol1UQMpMrc4tJ+a9Hdcm/rugYTdGjUiWEFm8uQyOE5DxekHQKAJYWGKkjiRRk4IXisO d6Iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722877811; x=1723482611; 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=/HQe48C7retWVgU11VG8KpaLIFiEtdB+eb7jfq+1CxM=; b=Y+zB1A1hy8pzMtYoaB4e6y1AxC1h7Vnpt2Eg4TKAMq9PEixi6dZ7scsCW4m7W/DaT/ w2S4/sAcPzDYsrzvv+VwaihnxVfruz5d1YwuaTvQ/3sw7ripFn449C5VCm+dLrhWH69R wQKBVVuWylodo26CBF+b6oO5nVzI2ZJx4ZEYMUqcqCeAu2wxROUXpxFgplz3+fdB5Mqv NRfV5vbPCaB8HfDUK+KDb1oV5wtmFoW4uCjQGMUcrXlBHqgWNa+fLmGKMFNGOb7+hsFE exz05j99DfpUCwS6LDihtJnUlZru7IiV7E7E+u6H+ygzp+JDjFsiveE6U2i0gnTkidtj 7WPg== X-Gm-Message-State: AOJu0YwYt5DDdpeHGYPn+zaIrhXkm+6LXBwdG7cvBquXfxO9+/p2cmyA EA2GqLvmN3ixpmVpZqfo2rQH2svNYpowA2ngF+gWnam1leO5o5r83DBC1A== X-Google-Smtp-Source: AGHT+IEVu76mYzZXK5/WoYVuAGbEZDz4HAvS+EmbGVS6EivjVAqYoyJrAdBbuOi8AZ0Pi6N6TvG5VA== X-Received: by 2002:a05:6000:8:b0:368:747c:5a04 with SMTP id ffacd0b85a97d-36bbc10f6c5mr6599813f8f.25.1722877810716; Mon, 05 Aug 2024 10:10:10 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-36bbd0269ffsm10522412f8f.58.2024.08.05.10.10.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Aug 2024 10:10:10 -0700 (PDT) Message-Id: <96984c4a15e3b587cf8d590f5311a1abe1f63e28.1722877808.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 05 Aug 2024 17:10:08 +0000 Subject: [PATCH v3 2/2] 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: Patrick Steinhardt , Eric Sunshine , 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 | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/t/t6421-merge-partial-clone.sh b/t/t6421-merge-partial-clone.sh index 711b709e755..b99f29ef9ba 100755 --- a/t/t6421-merge-partial-clone.sh +++ b/t/t6421-merge-partial-clone.sh @@ -230,8 +230,9 @@ test_expect_merge_algorithm failure success 'Objects downloaded for single relev grep fetch_count trace.output | cut -d "|" -f 9 | tr -d " ." >actual && test_cmp expect actual && - # Check the number of fetch commands exec-ed - grep d0.*fetch.negotiationAlgorithm trace.output >fetches && + # Check the number of fetch commands exec-ed by filtering trace to + # child_start events by the top-level program (2nd field == d0) + grep " d0 .* child_start .*fetch.negotiationAlgorithm" trace.output >fetches && test_line_count = 2 fetches && git rev-list --objects --all --missing=print | @@ -318,8 +319,9 @@ test_expect_merge_algorithm failure success 'Objects downloaded when a directory grep fetch_count trace.output | cut -d "|" -f 9 | tr -d " ." >actual && test_cmp expect actual && - # Check the number of fetch commands exec-ed - grep d0.*fetch.negotiationAlgorithm trace.output >fetches && + # Check the number of fetch commands exec-ed by filtering trace to + # child_start events by the top-level program (2nd field == d0) + grep " d0 .* child_start .*fetch.negotiationAlgorithm" trace.output >fetches && test_line_count = 1 fetches && git rev-list --objects --all --missing=print | @@ -422,8 +424,9 @@ test_expect_merge_algorithm failure success 'Objects downloaded with lots of ren grep fetch_count trace.output | cut -d "|" -f 9 | tr -d " ." >actual && test_cmp expect actual && - # Check the number of fetch commands exec-ed - grep d0.*fetch.negotiationAlgorithm trace.output >fetches && + # Check the number of fetch commands exec-ed by filtering trace to + # child_start events by the top-level program (2nd field == d0) + grep " d0 .* child_start .*fetch.negotiationAlgorithm" trace.output >fetches && test_line_count = 4 fetches && git rev-list --objects --all --missing=print |