From patchwork Tue May 24 00:23:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12859593 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 94C68C433F5 for ; Tue, 24 May 2022 00:23:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230383AbiEXAX1 (ORCPT ); Mon, 23 May 2022 20:23:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44166 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232372AbiEXAXQ (ORCPT ); Mon, 23 May 2022 20:23:16 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E2558A314 for ; Mon, 23 May 2022 17:23:10 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id r23so23524059wrr.2 for ; Mon, 23 May 2022 17:23:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=aRwHZX8lhlkBqqYp0nk9o1igfA9fQ8ZPDtMgHEJ9wj8=; b=giZKKQAUVWt1NWFUlwjtwGU80yRGqEi1+NFzYhv9n4LJuXGq82x/+dg8svQp5pApga zA3cUOI31ZixA5D3sQKltmyRqz3jn0pQbAss8hddi8D4wUFzLMORm0SWahQE2RhrEz0U X0CAfBjwZdzNVw++IEBhbGgdyo9jlP25scIGvN1EgLqa+8h9VX1ic/7qXDSaXPlyKQma cFJcCpOWLSaOYSZW0fpngBMTBFusNUr/0DV4iEfe2eyty7gRBt7l5sKO1fqruCjyDTZ3 2UncFjAa9DYNfcCPEyFlvRvYvjW1dZE7gIkEewJBnRK0p1jrdzcCrpxwj2oq+rqTiXpL L3Iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=aRwHZX8lhlkBqqYp0nk9o1igfA9fQ8ZPDtMgHEJ9wj8=; b=o8RCRcVWTYpDx09zaRXHJ87YYaW7ad2I7WQyv7L+0fFsA79HAln1OBxylv5bQBOnaV TUP4k8hg1/5UKm4WV784tschVNimw89pWcJvBM8lULSiwN9ztL8ZEGHArZNd+IdFQWNs wEfHqHMmXUeYF6g755lasNSeqLMR3ZUaOVr933yoqmhM9B0PoBXbJmZJKk8ajRH8KFOT HOPUjoXbj7/sLO4Mmb5NCpwFxD9iIWzJe87pSMSP8Jb8+a6lhhz10zTTjI7iN3KGhu21 zIr8jZ2Y4bdWhiUR9kcD3aWA5fdCCdyJ7ccIsMtyn5b0juq1PIlQHDtfK+m3l+Hw9sl/ PrwQ== X-Gm-Message-State: AOAM532XgwwUlOZEevuEo9qH4UQ0t5BXtVSyDUz3QLQIKTa53H3xZL+9 XLO409nHwgXph5vZoS6Mq7bMo0IYSpY= X-Google-Smtp-Source: ABdhPJxkuLkMcVr/bqW/fFMwkPchVrxcY76tkx7rKohD/+81CK36TpBQ8+JAC4ZUbGITXS+tzy8X4A== X-Received: by 2002:adf:d1cf:0:b0:20f:d7f1:9b49 with SMTP id b15-20020adfd1cf000000b0020fd7f19b49mr7146451wrd.369.1653351788608; Mon, 23 May 2022 17:23:08 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id o30-20020a05600c511e00b00394351e35edsm600164wms.26.2022.05.23.17.23.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 May 2022 17:23:08 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Tue, 24 May 2022 00:23:03 +0000 Subject: [PATCH 1/4] compat/win32/syslog: fix use-after-realloc Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin Git for Windows' SDK recently upgraded to GCC v12.x which points out that the `pos` variable might be used even after the corresponding memory was `realloc()`ed and therefore potentially no longer valid. Since a subset of this SDK is used in Git's CI/PR builds, we need to fix this to continue to be able to benefit from the CI/PR runs. Note: This bug has been with us since 2a6b149c64f6 (mingw: avoid using strbuf in syslog, 2011-10-06), and while it looks tempting to replace the hand-rolled string manipulation with a `strbuf`-based one, that commit's message explains why we cannot do that: The `syslog()` function is called as part of the function in `daemon.c` which is set as the `die()` routine, and since `strbuf_grow()` can call that function if it runs out of memory, this would cause a nasty infinite loop that we do not want to re-introduce. Signed-off-by: Johannes Schindelin --- compat/win32/syslog.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/compat/win32/syslog.c b/compat/win32/syslog.c index 161978d720a..1f8d8934cc9 100644 --- a/compat/win32/syslog.c +++ b/compat/win32/syslog.c @@ -43,6 +43,7 @@ void syslog(int priority, const char *fmt, ...) va_end(ap); while ((pos = strstr(str, "%1")) != NULL) { + size_t offset = pos - str; char *oldstr = str; str = realloc(str, st_add(++str_len, 1)); if (!str) { @@ -50,6 +51,7 @@ void syslog(int priority, const char *fmt, ...) warning_errno("realloc failed"); return; } + pos = str + offset; memmove(pos + 2, pos + 1, strlen(pos)); pos[1] = ' '; } From patchwork Tue May 24 00:23:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12859594 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D21BAC433F5 for ; Tue, 24 May 2022 00:23:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231915AbiEXAXb (ORCPT ); Mon, 23 May 2022 20:23:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232482AbiEXAXR (ORCPT ); Mon, 23 May 2022 20:23:17 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73D388FF88 for ; Mon, 23 May 2022 17:23:11 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id s28so23348629wrb.7 for ; Mon, 23 May 2022 17:23:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=GSbQJfRRqim6nWjo1GXuQLxg0XtiVzvnROdzieiNBWY=; b=A/ZoI/fVICkwzElyBKh9+rAB9xvPo0IczwwJCDqqY34hQGqrQTDRpyLafLIIpFAqtl Pa4nefFQHMOwFRDJf8dT16Gk+QV7PTw1rBMNIrOhhxP6zUgM+lcm5PvcelIVAv8u5Ala pw4xHy3h1fx0zwRgYkjkjkVrIUvRo0NEg4Rgm3tOz0nGWSYI1pisMAYSSPKsvqzNGNSa FRHRfovGKBEk9jdVd1hqpT1qrp1Q/GzwdGRAqsABZPx7Ts4/rlNif1CXi3Y8Rxh7P0eu EKKOJv1E/H+7hAdcFdLZpNq+EyG1UacgtYmtpfEBGW+3nYPWMCXn8HovCxobEgl0bWVF gDnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=GSbQJfRRqim6nWjo1GXuQLxg0XtiVzvnROdzieiNBWY=; b=P7YXjFghzfYfqBv/20Kcf+b8bFofSOnfOqkbJ8QkLDqOJv4PaS+JyPQ/xxmeMp3PrA Tn53PvJGUmIQ/nC4dtCBlj7kdz37tbLBlhQy2WYzQ2SWusEteObODF9/BEC3xGc8JiRQ tiR5mhhV7KurhGJ9S7SpkTcltUKzX/9rad2Xp3Pj0F62HJZuxVkXhtQDh6NjTPgF1D+8 5IHQx6no3ufwQ1IlaYM22OsoenZhEhvdCfkhrUxtWAbd8id3+jk7keZ3JYKrNvWbtGVu G+WJ3fDbGV4AW2xIwrSGxsgUUO4mK9hAUqqvEnwrV8MRWnpo2kLEDhHjePhlhBzWge1S izjg== X-Gm-Message-State: AOAM53143weU2sgW+QFSW8TkzeyCV68ospNvhMRl6xtQbj+d38pNipvm m7ChpCa9Gn2QUMq0FYMZevJiZCEuX4M= X-Google-Smtp-Source: ABdhPJx1jIpvb2j9BrLbs3Obsls9M2eRdNM8WdlCa7LbT5RaYn/XWOtPUw/All+Pi5a3hoEt67KKwQ== X-Received: by 2002:adf:d1ef:0:b0:20e:79af:7701 with SMTP id g15-20020adfd1ef000000b0020e79af7701mr15729133wrd.486.1653351789621; Mon, 23 May 2022 17:23:09 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id c8-20020a05600c0ac800b0039729309a84sm568687wmr.20.2022.05.23.17.23.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 May 2022 17:23:09 -0700 (PDT) Message-Id: <8963c6fa625bbaf5153990939ea06742304ddcd2.1653351786.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 24 May 2022 00:23:04 +0000 Subject: [PATCH 2/4] nedmalloc: avoid new compile error Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin GCC v12.x complains thusly: compat/nedmalloc/nedmalloc.c: In function 'DestroyCaches': compat/nedmalloc/nedmalloc.c:326:12: error: the comparison will always evaluate as 'true' for the address of 'caches' will never be NULL [-Werror=address] 326 | if(p->caches) | ^ compat/nedmalloc/nedmalloc.c:196:22: note: 'caches' declared here 196 | threadcache *caches[THREADCACHEMAXCACHES]; | ^~~~~~ ... and it is correct, of course. Signed-off-by: Johannes Schindelin --- compat/nedmalloc/nedmalloc.c | 1 - 1 file changed, 1 deletion(-) diff --git a/compat/nedmalloc/nedmalloc.c b/compat/nedmalloc/nedmalloc.c index edb438a7776..2c0ace7075a 100644 --- a/compat/nedmalloc/nedmalloc.c +++ b/compat/nedmalloc/nedmalloc.c @@ -323,7 +323,6 @@ static NOINLINE void RemoveCacheEntries(nedpool *p, threadcache *tc, unsigned in } static void DestroyCaches(nedpool *p) THROWSPEC { - if(p->caches) { threadcache *tc; int n; From patchwork Tue May 24 00:23:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12859595 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 05666C433EF for ; Tue, 24 May 2022 00:23:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232607AbiEXAXi (ORCPT ); Mon, 23 May 2022 20:23:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232495AbiEXAXR (ORCPT ); Mon, 23 May 2022 20:23:17 -0400 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74EE4915B5 for ; Mon, 23 May 2022 17:23:12 -0700 (PDT) Received: by mail-wm1-x330.google.com with SMTP id m32-20020a05600c3b2000b0039756bb41f2so486051wms.3 for ; Mon, 23 May 2022 17:23:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=RQJVlgGN1lDBj4q0oaaU8S4Vs8blkBvpHuAU/1V7eog=; b=Vpz/T+yKd7Fs1d2BwwHJoMeKRiSWLLdCRtgzO1cL4oDv8xN2KIvcFEvew5WRMqoEYd PUA2cdbLvipbZaVoT9hJSInPhNeq67hEyXilVK4inI/fyrUugDL6mjUriWjPFsRHtn2R 38MPkXVPbNvQSuQ71dHF7kk9uOoqAeIE8kSGgZxbQgOQt2AsVvbFpKmDuoX3Iz55zZ9j 0W4hsFnSBIivuaI01cqgQW2qne2O8Hp8AQKrGHhOH8+LkN8sMnJxUhUu/muZceu1ggmR geCt15CabdjTU0A81TlOXQ/OCpTE353xtIDy+nIPOvEvlKVh2KzwVPc5eV5LvT8GO8BA GkOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=RQJVlgGN1lDBj4q0oaaU8S4Vs8blkBvpHuAU/1V7eog=; b=aQ3rICG9j6GSgAcp0lZT84/38VeKp+Kvl2/FG3YWwnsfSoNvNNXl/XRkeyG9ahszDa oPE3QVfQWQZoeUWCxaNrfX/d2q+7MKsqn6L8ai1J++4ULYqdKPR1SlZ5LBv+LtN9qs81 FW5VHvVsgHQc5faDQBWYp21FGx5madqjnaq4J+5EA7IrLvUyOVGjHDL9FGHiwyoV+Ina ufjGW+3v/7ELbX392KsfUJ4EAKYiHUJCb+EbDE9+VWuY11L/3GL/QkUglk5SjLdr0R29 ig91GkO/MPLcLmz9Y1cA5C1zH2nUo6gqKaPHHIjLCJ0fjXLPkTuW9vyQKEJOcm0A2cT6 tcmw== X-Gm-Message-State: AOAM530OxBHbvK3mkhWkThyVuezcIrbpzwH1LLnC39v/UM6dOg4U01Ok AjbALuVfWT88uhbuFcx4ZEi5hUTmBxk= X-Google-Smtp-Source: ABdhPJxuwPKZbmUFNa7gYaN6QvWuT3Yn+SCKRwkQaEp0W77dXyjVZeArK2P/2ervHbjVy9cleyQorQ== X-Received: by 2002:a05:600c:4ed3:b0:394:789b:913 with SMTP id g19-20020a05600c4ed300b00394789b0913mr1238575wmq.175.1653351790599; Mon, 23 May 2022 17:23:10 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id g24-20020adfa498000000b0020c5253d90csm11273089wrb.88.2022.05.23.17.23.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 May 2022 17:23:10 -0700 (PDT) Message-Id: <4a4e0aa0a49a54eea88f9c2d8e1db6a697012718.1653351786.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 24 May 2022 00:23:05 +0000 Subject: [PATCH 3/4] http.c: avoid danging pointer to local variable `finished` Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin In http.c, the run_active_slot() function allows the given "slot" to make progress by calling step_active_slots() in a loop repeatedly, and the loop is not left until the request held in the slot completes. Ages ago, we used to use the slot->in_use member to get out of the loop, which misbehaved when the request in "slot" completes (at which time, the result of the request is copied away from the slot, and the in_use member is cleared, making the slot ready to be reused), and the "slot" gets reused to service a different request (at which time, the "slot" becomes in_use again, even though it is for a different request). The loop terminating condition mistakenly thought that the original request has yet to be completed. Today's code, after baa7b67d (HTTP slot reuse fixes, 2006-03-10) fixed this issue, uses a separate "slot->finished" member that is set in run_active_slot() to point to an on-stack variable, and the code that completes the request in finish_active_slot() clears the on-stack variable via the pointer to signal that the particular request held by the slot has completed. It also clears the in_use member (as before that fix), so that the slot itself can safely be reused for an unrelated request. One thing that is not quite clean in this arrangement is that, unless the slot gets reused, at which point the finished member is reset to NULL, the member keeps the value of &finished, which becomes a dangling pointer into the stack when run_active_slot() returns. Let's drop that local variable and introduce a new flag in the slot that is used to indicate that even while the slot is no longer in use, it is still reserved until further notice. It is the responsibility of `run_active_slot()` to clear that flag once it is done with that slot. Initial-patch-by: Junio C Hamano Signed-off-by: Johannes Schindelin --- http-walker.c | 4 ---- http.c | 15 +++++++-------- http.h | 2 +- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/http-walker.c b/http-walker.c index 910fae539b8..5cc369dea85 100644 --- a/http-walker.c +++ b/http-walker.c @@ -225,13 +225,9 @@ static void process_alternates_response(void *callback_data) alt_req->url->buf); active_requests++; slot->in_use = 1; - if (slot->finished != NULL) - (*slot->finished) = 0; if (!start_active_slot(slot)) { cdata->got_alternates = -1; slot->in_use = 0; - if (slot->finished != NULL) - (*slot->finished) = 1; } return; } diff --git a/http.c b/http.c index f92859f43fa..00206676597 100644 --- a/http.c +++ b/http.c @@ -197,8 +197,7 @@ static void finish_active_slot(struct active_request_slot *slot) closedown_active_slot(slot); curl_easy_getinfo(slot->curl, CURLINFO_HTTP_CODE, &slot->http_code); - if (slot->finished != NULL) - (*slot->finished) = 1; + slot->in_use = 0; /* Store slot results so they can be read after the slot is reused */ if (slot->results != NULL) { @@ -1176,13 +1175,14 @@ struct active_request_slot *get_active_slot(void) process_curl_messages(); } - while (slot != NULL && slot->in_use) + while (slot != NULL && (slot->in_use || slot->reserved_for_use)) slot = slot->next; if (slot == NULL) { newslot = xmalloc(sizeof(*newslot)); newslot->curl = NULL; newslot->in_use = 0; + newslot->reserved_for_use = 0; newslot->next = NULL; slot = active_queue_head; @@ -1204,7 +1204,6 @@ struct active_request_slot *get_active_slot(void) active_requests++; slot->in_use = 1; slot->results = NULL; - slot->finished = NULL; slot->callback_data = NULL; slot->callback_func = NULL; curl_easy_setopt(slot->curl, CURLOPT_COOKIEFILE, curl_cookie_file); @@ -1296,7 +1295,7 @@ void fill_active_slots(void) } while (slot != NULL) { - if (!slot->in_use && slot->curl != NULL + if (!slot->in_use && !slot->reserved_for_use && slot->curl && curl_session_count > min_curl_sessions) { curl_easy_cleanup(slot->curl); slot->curl = NULL; @@ -1327,10 +1326,9 @@ void run_active_slot(struct active_request_slot *slot) fd_set excfds; int max_fd; struct timeval select_timeout; - int finished = 0; - slot->finished = &finished; - while (!finished) { + slot->reserved_for_use = 1; + while (slot->in_use) { step_active_slots(); if (slot->in_use) { @@ -1367,6 +1365,7 @@ void run_active_slot(struct active_request_slot *slot) select(max_fd+1, &readfds, &writefds, &excfds, &select_timeout); } } + slot->reserved_for_use = 0; } static void release_active_slot(struct active_request_slot *slot) diff --git a/http.h b/http.h index df1590e53a4..3b2f6da570c 100644 --- a/http.h +++ b/http.h @@ -22,9 +22,9 @@ struct slot_results { struct active_request_slot { CURL *curl; int in_use; + int reserved_for_use; CURLcode curl_result; long http_code; - int *finished; struct slot_results *results; void *callback_data; void (*callback_func)(void *data); From patchwork Tue May 24 00:23:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12859596 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4C8CFC433EF for ; Tue, 24 May 2022 00:24:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230058AbiEXAX7 (ORCPT ); Mon, 23 May 2022 20:23:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232484AbiEXAXR (ORCPT ); Mon, 23 May 2022 20:23:17 -0400 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73A9E91544 for ; Mon, 23 May 2022 17:23:12 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id p10so4857834wrg.12 for ; Mon, 23 May 2022 17:23:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=eQdJCtDFR9doZyW52z0K1w/pSMu2CHvIZxY29p/x23k=; b=XHVWAf5Z681kOAwaSIl1x3FZk2/oYu76pfmdafmFS1LP/tLHheAmipB88QanqeL96M 3armT0DyOOuOT2cqCmVmixiEKEcyJE5/rG5nEcm82MUCGXPDW8Qj9H9MiEoUwjUbY6Mv MgdCU0wk1yjyvZHdYefJhrv5Ejs3D78v/HAOGISXR+RfBn+fsYnjeNfHdklIrQ0DkfMZ 9hYVryzxjnXyy77SB7X0ZSYJ1t1J2p76dNhMly4rMWKZ3OAxC7sodJZMJoUN62bjdgUB F9DtJpAKFIXAhCUA+bHF8oEOTHZOJfqlWXsf55wGslWjzbI8PmypucaYJ3pE4LrDbwFO aw6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=eQdJCtDFR9doZyW52z0K1w/pSMu2CHvIZxY29p/x23k=; b=8PfZrpTk2yMnCuof56a1FQPgQjYLLACrv23SPTVElvIdsQoRjUFKOIZnStzVitKK/W b5Bm8ViKut1EsFaynkGDXw6/ZrGlLAOAaZtVLfKnWKRL/x8O3duCV2IuBwJ839GhTJU+ qR5Lp4DcEbu3i2lztvA45cgXrgzgdWDDNz99JZG8urkf7JehkG7n4hmO1bb5N7iGX7FS q19aZWHdfCvI8yYvAGxOzGyk7/a7Nczo0b3/GrRJIlkLYikR8sFd5z0xaL4a9cLVxl4b sL4/xOw+NM2vMhsOvC6g0jpGeAcYAJ/eVWuOEM5y7fM5SDsCZusdMXT5lm5Sbk7ZYjq5 OQ/w== X-Gm-Message-State: AOAM530WXE7yQfwoHu447quYcf3CUdamedAK22aKr+25dsjm3L/jPxG3 okqCvPdrq7JKnWb08COGWyqEEVHlE+0= X-Google-Smtp-Source: ABdhPJwSXvfQouG2Frx9ewGflcZ96yNu5UGdRyvunzrqKxo47QNwcqptoRqkd8x5U72akT/BepiOiw== X-Received: by 2002:a5d:4b81:0:b0:20e:5a3a:e8ed with SMTP id b1-20020a5d4b81000000b0020e5a3ae8edmr20419156wrt.413.1653351791640; Mon, 23 May 2022 17:23:11 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id p13-20020adfba8d000000b0020cdcb0efa2sm11464287wrg.34.2022.05.23.17.23.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 May 2022 17:23:11 -0700 (PDT) Message-Id: <365889ee96e37dc9dcbe60d98880eb256dae90ee.1653351786.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 24 May 2022 00:23:06 +0000 Subject: [PATCH 4/4] dir.c: avoid "exceeds maximum object size" error with GCC v12.x Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin Technically, the pointer difference `end - start` _could_ be negative, and when cast to an (unsigned) `size_t` that would cause problems. In this instance, the symptom is: dir.c: In function 'git_url_basename': dir.c:3087:13: error: 'memchr' specified bound [9223372036854775808, 0] exceeds maximum object size 9223372036854775807 [-Werror=stringop-overread] CC ewah/bitmap.o 3087 | if (memchr(start, '/', end - start) == NULL | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ While it is a bit far-fetched to think that `end` (which is defined as `repo + strlen(repo)`) and `start` (which starts at `repo` and never steps beyond the NUL terminator) could result in such a negative difference, GCC has no way of knowing that. See also https://gcc.gnu.org/bugzilla//show_bug.cgi?id=85783. Let's just add a safety check, primarily for GCC's benefit. Signed-off-by: Johannes Schindelin --- dir.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/dir.c b/dir.c index 5aa6fbad0b7..ea78f606230 100644 --- a/dir.c +++ b/dir.c @@ -3076,6 +3076,15 @@ char *git_url_basename(const char *repo, int is_bundle, int is_bare) end--; } + /* + * It should not be possible to overflow `ptrdiff_t` by passing in an + * insanely long URL, but GCC does not know that and will complain + * without this check. + */ + if (end - start < 0) + die(_("No directory name could be guessed.\n" + "Please specify a directory on the command line")); + /* * Strip trailing port number if we've got only a * hostname (that is, there is no dir separator but a