From patchwork Wed Jun 15 23:35:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12883069 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 916A6C43334 for ; Wed, 15 Jun 2022 23:35:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350807AbiFOXf4 (ORCPT ); Wed, 15 Jun 2022 19:35:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350716AbiFOXfx (ORCPT ); Wed, 15 Jun 2022 19:35:53 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B6D81B79C for ; Wed, 15 Jun 2022 16:35:52 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id u8so17231221wrm.13 for ; Wed, 15 Jun 2022 16:35:52 -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=qBjidiBbz4KE8io84npexzOnVy4jwiKJwPoV0MiFkOg=; b=JTT1/iGTbHzgAf7ajRnAC2QyJWduRQYrgliny7aNAniQ+rQC+y/OQH03nkCQD2y7kl EWZK5ZfBDnJvN40bsB0UDqhSTK9UqOsuITRQR0kVR2IT5sY79TCClDVqzQnlpzwUAfXZ qDGvNo+yYaFP0iWkfJGsEGE1JcxAnt8Yx/ou4Tl+e/v7/QvUZS5Ibo3NiwLpJdVX6kHk unYaIhx99j4NJdMEqhCAHJvyVpG3SGihpN+iBJmmNeCza3X0Vne8inezLVYGzNgeH/kC qWewGGyBzO3b5PFXI16pCP3xGGUQT7GVmcweFWjDssd2lwMucMwXrjKz+EWVo3+9VB0l wOvQ== 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=qBjidiBbz4KE8io84npexzOnVy4jwiKJwPoV0MiFkOg=; b=8RVSgQ0lSyvx3bb1PJZMuZbsKNm1dZsphmmh0rLk0fAQK4lfkiyNpng10A1y2lWNSC z3cik31U0VXiwtbWmBTIlZ+bzDiz87+BxNQu2gCHSy+O517aTUHoQgu0GOkmjfol4ZdT kBaKnnc5vtaLXG93VoUZnFM/WfCB1ysBMJs0GY9PTIlApYXX+qztwFJavQU2dMWHnlmp 2NHWxY/kKZpTnpnogEqjZuyPCPLp2wr7JOrRguhXj1VZh5YN/Ln2bDwZxTM47zfwaAQx 6XbZaySTm62Vky2WguOVyDVQMg3qf+PHY+llNo1O0yQPRmmPNNwG8N40ShwBfHy8fYhS nVmQ== X-Gm-Message-State: AJIora8p7nfBxc5XCRJpBfs6fv6i1oy8LNtDSKXGXSAiM0OxqU0l08rv /Q8L4HV7J0b2AxLkLKJxC2kMawdM6zVxPA== X-Google-Smtp-Source: AGRyM1t8O0mW7CbdTy0N/OHRCpf6EgQsPSppAAIBNZq3ow2xHl17CaW3LVC9K2+PLdRfaiCl4SUe/w== X-Received: by 2002:a05:6000:178d:b0:20f:e84c:2f46 with SMTP id e13-20020a056000178d00b0020fe84c2f46mr2025887wrg.646.1655336150243; Wed, 15 Jun 2022 16:35:50 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id r64-20020a1c4443000000b003942a244f39sm4998909wma.18.2022.06.15.16.35.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jun 2022 16:35:49 -0700 (PDT) Message-Id: <679ea7421f73ce41515aca549982233f88bcefef.1655336146.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 15 Jun 2022 23:35:35 +0000 Subject: [PATCH 01/11] mingw: avoid accessing uninitialized memory in `is_executable()` 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 On Windows, we open files we suspect might be scripts, read the first two bytes, and see whether they indicate a hash-bang line. We do not initialize the byte _after_ those two bytes, therefore `strcmp()` is inappropriate here. Reported by Coverity. Signed-off-by: Johannes Schindelin --- run-command.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run-command.c b/run-command.c index 14f17830f51..2ba38850b4d 100644 --- a/run-command.c +++ b/run-command.c @@ -154,7 +154,7 @@ int is_executable(const char *name) n = read(fd, buf, 2); if (n == 2) /* look for a she-bang */ - if (!strcmp(buf, "#!")) + if (!memcmp(buf, "#!", 2)) st.st_mode |= S_IXUSR; close(fd); } From patchwork Wed Jun 15 23:35:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12883070 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 DE721C433EF for ; Wed, 15 Jun 2022 23:35:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350885AbiFOXf5 (ORCPT ); Wed, 15 Jun 2022 19:35:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350721AbiFOXfy (ORCPT ); Wed, 15 Jun 2022 19:35:54 -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 154DC1A077 for ; Wed, 15 Jun 2022 16:35:53 -0700 (PDT) Received: by mail-wm1-x330.google.com with SMTP id i81-20020a1c3b54000000b0039c76434147so1962108wma.1 for ; Wed, 15 Jun 2022 16:35:53 -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=zDNeHA/m3I9ZBVTe9fpqf5UB3mPXA5PuTEuAdJuXb3E=; b=l7d66ux8hIf5SeqNMyR6ppv8xvqF5sSrh6FiwRePAY1M2VELNcqNOtkG+bZkgY1w4l VE9MPdW2vlQZ4+0i5jmTUItq9Ew+h+I9HCg4Xqysv79BcVMRXT1ZJmvFO70G+CHjatnh MQ1VlXpnJaP5VaDeoqR48bSYcjB9zQymDAMPe3qqOL3i5zPO5/7p8PNbghmJNrd0clLB 5Yo7bqdFSSkq5XXBsNHtWBIg6IZgl9qz9sHXK0E7PLZDAn8D/w/yLS9gd44MvMRF27Rd z7piQsLwud7wgz8W9kKwprUjh6XNui7NZt7Anl/GUKZq1dKu2a0C9L3xwEdC5gjenPtv KAtA== 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=zDNeHA/m3I9ZBVTe9fpqf5UB3mPXA5PuTEuAdJuXb3E=; b=1Op1ex01u/3DJDChQIdGOrG65wzQs9Fc4Nq4p39q5Dx+8+j0Cj0A8Uxr6D2M4weAin s20LRfU4GcE0Kclg/08dr4ajQymWzJ79wqC//i+01aznlsGWKvShUxJWdhE0WRM0MRKV 9Teu+bnw8yI96ufwHjm5+SKRrX4UYrW88c8u+CDzK0lG0Cezi8QXznq+hWwwFQLLRe9L JiFA5V6FGrUBR5MbmFsQK9+VKEC9TY6CZPFD6aqNJofteZdG5wc/JkgoUb9/7XXh9ioR AfpNFZNMA8kE4b9gIwvBtDWJambO2r1uO6XgvDJqlneaq7utJvfL3BX94NfSjlDMFoo1 KB7w== X-Gm-Message-State: AJIora8v74DOD2RfaKhqLo9wfWulUWZZhNMqN+792wsf4RrLkBZi8Dly tKc08Awdjme/JgtGsLazgwfbeIedJQVJxA== X-Google-Smtp-Source: AGRyM1sd3F6BtG7EeV/TCcHZ0tX40K74tfVcePi/cuG89qwfjxZ1nTIM2U/oy4ANKoSXiNkw//6FDQ== X-Received: by 2002:a05:600c:4f95:b0:39c:7bd0:d47d with SMTP id n21-20020a05600c4f9500b0039c7bd0d47dmr1890573wmq.17.1655336152370; Wed, 15 Jun 2022 16:35:52 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id l1-20020a1c2501000000b0039747cf8354sm294717wml.39.2022.06.15.16.35.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jun 2022 16:35:51 -0700 (PDT) Message-Id: <6d409ad45867aa5193c15828614e865e53ac0c57.1655336146.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 15 Jun 2022 23:35:36 +0000 Subject: [PATCH 02/11] fsmonitor: avoid memory leak in `fsm_settings__get_incompatible_msg()` 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 Reported by Coverity. Signed-off-by: Johannes Schindelin --- fsmonitor-settings.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/fsmonitor-settings.c b/fsmonitor-settings.c index 658cb79da01..464424a1e92 100644 --- a/fsmonitor-settings.c +++ b/fsmonitor-settings.c @@ -202,11 +202,15 @@ char *fsm_settings__get_incompatible_msg(const struct repository *r, case FSMONITOR_REASON_OK: goto done; - case FSMONITOR_REASON_BARE: + case FSMONITOR_REASON_BARE: { + char *cwd = xgetcwd(); + strbuf_addf(&msg, _("bare repository '%s' is incompatible with fsmonitor"), - xgetcwd()); + cwd); + free(cwd); goto done; + } case FSMONITOR_REASON_ERROR: strbuf_addf(&msg, From patchwork Wed Jun 15 23:35:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12883071 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 356EAC43334 for ; Wed, 15 Jun 2022 23:36:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351538AbiFOXgD (ORCPT ); Wed, 15 Jun 2022 19:36:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50346 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350852AbiFOXf5 (ORCPT ); Wed, 15 Jun 2022 19:35:57 -0400 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 797E51B79C for ; Wed, 15 Jun 2022 16:35:55 -0700 (PDT) Received: by mail-wm1-x32c.google.com with SMTP id n185so7069607wmn.4 for ; Wed, 15 Jun 2022 16:35:55 -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=XiVF6nIhCq/TCqZicNwCBbpD/oTYFMdBLjrfs+dbp60=; b=aVCK/yG8xDekyK2fP9/2nlggV4CQ/8DTJjBGKIsBjuXqOUFgSeVFuchWepnknEJbDL 2nDmSSs80E0YPLTHIhkECTpSr8WP+5oaC6HEyzk0esx/hGpW+LJJ5e1mhPRASH2rsUZT TEKzQucEM2IA+rVCUN5JLk+TLYQDYhHr9kcsHoPg/ZbLkfHtGZu9FKbPry+ATZeP6Jgi vF0yrKh4FF8yB2K/sQfJmyVrCruARnQZuRpPM6A1+PtKUR6hwXgXN/dxQjlTEJFtsarU vLDMNs5yuGIDrJFEdacGR6o3rr4fw3HFB9Rz0GAUkQoCtkopskw7EFhaO5iZ4LcTMJhf vE7A== 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=XiVF6nIhCq/TCqZicNwCBbpD/oTYFMdBLjrfs+dbp60=; b=Kkzw0UTbeUJJZaxdDGLjJuVtVNnJ8YONbgiHdwV+l0nZdqHt/y3/yLLc2HHIU8QBGc XxBiFaDKsB2FXC7oJ2aqc5Mxn6yVmtiJRS61lZe90p7h0h4CQPxsI5lFnFi+ldYUNFcR p9qTKs06CNPEOM0jQV97ooheSJqwCOfAPqTolSS+p/tQ4nw2k4uixVRoVTjH8R5Bhr9S sT8rjHvCxAGQWUg49Nkt0u6szSUu1P71EoHydC2mTiXqik4sQbjZXkOcJ74lC5nY7JaZ yb7UB64DwGzQPNDRO6QhrDahmDbSfm6N4dDvdTV6nOrAtGJ3DJ9YgImiuid4vGqLE+l5 9xuQ== X-Gm-Message-State: AOAM5322cAQvcZc2MxJYt3EUebC7STMEczwxNpCWnviiACxeW9V7pSTT loRVBZhfi/rAKQWCmCwBkK67uHOZfXTrHA== X-Google-Smtp-Source: ABdhPJwyCPRNZZfa8Hq489t4MGMF+ZP4ZYNm8Bg7JYs1tx+MXHlnJhQP/spNNdW0xBqWl3UoyZI3PA== X-Received: by 2002:a7b:c777:0:b0:39c:4e1d:fd27 with SMTP id x23-20020a7bc777000000b0039c4e1dfd27mr12307993wmk.1.1655336153768; Wed, 15 Jun 2022 16:35:53 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id n4-20020a05600c4f8400b003971fc23185sm4386235wmq.20.2022.06.15.16.35.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jun 2022 16:35:53 -0700 (PDT) Message-Id: <877a45867ae368bf9e053caedcb6cf421e02344d.1655336146.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 15 Jun 2022 23:35:37 +0000 Subject: [PATCH 03/11] submodule--helper: avoid memory leak in `update_submodule()` 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 Reported by Coverity. Signed-off-by: Johannes Schindelin --- builtin/submodule--helper.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 5c77dfcffee..d7b8004b933 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2512,6 +2512,8 @@ static int update_submodule(struct update_data *update_data) next.recursive_prefix = get_submodule_displaypath(prefixed_path, update_data->prefix); + free(prefixed_path); + next.prefix = NULL; oidcpy(&next.oid, null_oid()); oidcpy(&next.suboid, null_oid()); From patchwork Wed Jun 15 23:35:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12883072 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 C5F11C433EF for ; Wed, 15 Jun 2022 23:36:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353179AbiFOXgF (ORCPT ); Wed, 15 Jun 2022 19:36:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50376 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350721AbiFOXf6 (ORCPT ); Wed, 15 Jun 2022 19:35:58 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 56AE61E3EA for ; Wed, 15 Jun 2022 16:35:57 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id q9so18925wrd.8 for ; Wed, 15 Jun 2022 16:35:57 -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=ANsbg2yeJFKLZLs2d33rrXjqBnFMEV8dtSd0djH7nI4=; b=AuHtvju0ybGXC9JNBQQcZAYfHZtOydAJvvjSdMv2YeDeyPypyS47U49lkke35dNRia bF2xuhxS3AdyEKP+nsWIeNiOtcZ/VmRm2KG0mjy71+SnQ+94Jrc0+7ecTWnoMw4liwPv o5Ib0eOsWO06kg3VajOYxVrStu1yNe9+l6n97rBtryXg2pNzRpqjGkhXEMIa5H7munwt uRES37OdZMUuH+RfkCYJ+XlTVATsR7ru83sFRBn8K9qJOnBHU2qe+pxFlCstVBvxvdOm HqDFD9W91AVPj0jyiIrquW5D/SOvwkBu/CZ3fFjg0ME+AKgkzgn42UZJaAUaOwruS4Ym XXSw== 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=ANsbg2yeJFKLZLs2d33rrXjqBnFMEV8dtSd0djH7nI4=; b=JXmLawGViCe5aZ2TpdqmlMJ/IrsnRGetpb4gcFRL9C8GcQbjFCtG7PKTbtGSBMhqe7 PaPJIEJj3OeX80B/SdLGKQCWCyn4DTfAhbKVloHiYNvSydmCkTvzZdItvAuqY5AUY0LN X8zSEMzPCAcAlsSisjocNR9HpJVrccjSBxGxuRgOXSwOEqGy3WFwAbLH3URrt1BE31zS eYku4AA5ZdD2Oxl1V+S1dMuKX0XdxY80NIMNa0O8cQGNbYPdnMMPji5zpPOK4JHChiNR wwaFUFINMOdPc0Mlm8Bq0mVGZWbjHkSlT9Gmnl0vBOIzSwZ9KoL13Rj/ig8xwVzHC4QB /oTA== X-Gm-Message-State: AJIora8JiwM2baA3slvFX2jX8hgYXWAar5hv3vErtBsIzQ2yWiecIIcy HZBC3A8CvztYB1aTmRsVfbXWvsZj7IOsAg== X-Google-Smtp-Source: AGRyM1u/e30MPJtET4uZvumv49+nV8eTRRU+FQgbe/Dyu7IxnfRVE0pUIBZmPYNV9/4WXFxIROhnEA== X-Received: by 2002:a5d:5a94:0:b0:218:531a:eea with SMTP id bp20-20020a5d5a94000000b00218531a0eeamr1949558wrb.703.1655336155176; Wed, 15 Jun 2022 16:35:55 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id j19-20020a05600c1c1300b0039c5645c60fsm9223080wms.3.2022.06.15.16.35.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jun 2022 16:35:54 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Wed, 15 Jun 2022 23:35:38 +0000 Subject: [PATCH 04/11] get_oid_with_context_1(): avoid use-after-free 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 561287d342cc (object-name: reject trees found in the index, 2022-04-26), we changed the code to release the memory stored under the `new_path` variable a bit earlier. However, at that point the variable `cp` still points to `new_path` (if non-`NULL`), and we _then_ pass that pointer to `reject_tree_in_index()`. Let's make sure that the pointer still points to allocated memory by moving the original `free()` call back where it was, and adding another one in the early return code path. Reported by Coverity. Signed-off-by: Johannes Schindelin --- object-name.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/object-name.c b/object-name.c index 4d2746574cd..228c12a554c 100644 --- a/object-name.c +++ b/object-name.c @@ -1971,12 +1971,14 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo, memcmp(ce->name, cp, namelen)) break; if (ce_stage(ce) == stage) { - free(new_path); if (reject_tree_in_index(repo, only_to_die, ce, - stage, prefix, cp)) + stage, prefix, cp)) { + free(new_path); return -1; + } oidcpy(oid, &ce->oid); oc->mode = ce->ce_mode; + free(new_path); return 0; } pos++; From patchwork Wed Jun 15 23:35:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12883073 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 68F04C43334 for ; Wed, 15 Jun 2022 23:36:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351973AbiFOXgG (ORCPT ); Wed, 15 Jun 2022 19:36:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50414 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350811AbiFOXf7 (ORCPT ); Wed, 15 Jun 2022 19:35:59 -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 0A4F81EACA for ; Wed, 15 Jun 2022 16:35:58 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id m24so17232234wrb.10 for ; Wed, 15 Jun 2022 16:35:57 -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=C780sC91xhPPLJe3OMpTJIx0Gc8ojEZaalLWRRgRH2U=; b=cJ6epaLLR9uhaxwcwQOpCPwcNVgAXY+U67NigdcpoSaHLjG5tARlbIMzaN9sX4hpL+ WDFBMoxeUhQkJQ9K+a+pjCCiRMoMS/7ZB/PmZ1KMIPtOybal7S4+QVpHrSYm0uklmiyY QVwKYKERY42d1861phUtuLNlnana9cYU4ls5wquKyZ1sZwlk3ZtzeGnrNTwoitQ08DyN asaG3OnvIBJoDYQwqSS8sJHSoIqZYVQzkidkK1PUtDExOIogwkWA78sZxblIBN1qS2nY +Zmfje/y3bv8UJ2hq/pVvNz7kMz3q0pAM2X+M4r9QSEkKn/npsD7bdwtF8nIvBz42wxF 5wYw== 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=C780sC91xhPPLJe3OMpTJIx0Gc8ojEZaalLWRRgRH2U=; b=v0RWli2l0XU6ImPIuOcyN64lLhf32yM0/CWM+q3orGL/4cZ/qALFL5ywbCpXlzCupG ET8lOorV3jDKvyMPftsJ4as3ifLPQFgiHjQdVwpC6CK0YlMGp8x+AhSBT9B5Jw06mUmI aMR1jCi8cNAWI+AHgV8dE4gISHDQS+ALHouWBF7m0xIoRhHBO4cpNGdSxeK2ux1EXKe4 TMzf4dykY9Y1GeLXa5hp7iPpiKe1mBZQfmGlRjewDmTDxZdw/y8KeKf9LtrSBQOd9FZl HYnAaSXauaGkUw+mZ+3BeGgKkqd/BoQFO5CeI+dfklFN2cfzZJqsHPTi/leMVbNE7OQW kiyw== X-Gm-Message-State: AJIora+s16rNHs97g9+n9h5qk6pcLn6ngq82zExgVMyIX4RASEEQI3oV /khveg7s8Fw6Wy90s0qT4N2ddRFrNBRR9A== X-Google-Smtp-Source: AGRyM1vOVVkKQqtnE7pOPeOfFA/9phTND1w4nLZSMEBrh9ouRq3x2ak/DM7AZnqvK/sWLYKIkLeN9w== X-Received: by 2002:a05:6000:1549:b0:218:56b3:e3 with SMTP id 9-20020a056000154900b0021856b300e3mr1937973wry.403.1655336156326; Wed, 15 Jun 2022 16:35:56 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id m188-20020a1c26c5000000b0039c4945c753sm3852392wmm.39.2022.06.15.16.35.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jun 2022 16:35:55 -0700 (PDT) Message-Id: <591166e07d87fdb5efc2769d3e2963e3f0412720.1655336146.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 15 Jun 2022 23:35:39 +0000 Subject: [PATCH 05/11] submodule-config: avoid memory leak 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 961b130d20c9 (branch: add --recurse-submodules option for branch creation, 2022-01-28), a funny pattern was introduced where first some struct is `xmalloc()`ed, then we resize an array whose element type is the same struct, and then the first struct's contents are copied into the last element of that array. Crucially, the `xmalloc()`ed memory never gets released. Let's avoid that memory leak and that memory allocation dance altogether by first reallocating the array, then using a pointer to the last array element to go forward. Reported by Coverity. Signed-off-by: Johannes Schindelin --- submodule-config.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/submodule-config.c b/submodule-config.c index ce3beaf5d4f..51ecbe901ec 100644 --- a/submodule-config.c +++ b/submodule-config.c @@ -756,7 +756,10 @@ static void traverse_tree_submodules(struct repository *r, if (S_ISGITLINK(name_entry->mode) && is_tree_submodule_active(r, root_tree, tree_path)) { - st_entry = xmalloc(sizeof(*st_entry)); + ALLOC_GROW(out->entries, out->entry_nr + 1, + out->entry_alloc); + st_entry = &out->entries[out->entry_nr++]; + st_entry->name_entry = xmalloc(sizeof(*st_entry->name_entry)); *st_entry->name_entry = *name_entry; st_entry->submodule = @@ -766,9 +769,6 @@ static void traverse_tree_submodules(struct repository *r, root_tree)) FREE_AND_NULL(st_entry->repo); - ALLOC_GROW(out->entries, out->entry_nr + 1, - out->entry_alloc); - out->entries[out->entry_nr++] = *st_entry; } else if (S_ISDIR(name_entry->mode)) traverse_tree_submodules(r, root_tree, tree_path, &name_entry->oid, out); From patchwork Wed Jun 15 23:35:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12883074 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 B96EAC433EF for ; Wed, 15 Jun 2022 23:36:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353626AbiFOXgI (ORCPT ); Wed, 15 Jun 2022 19:36:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350821AbiFOXgB (ORCPT ); Wed, 15 Jun 2022 19:36:01 -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 D74081F2C1 for ; Wed, 15 Jun 2022 16:35:59 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id a15so17279717wrh.2 for ; Wed, 15 Jun 2022 16:35:59 -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=fsqie9DP/xVl7vON6ezt0AdhOBqtz8CpDNLwZoU5tWg=; b=FG6O1BO7dOalLT8YWlwNFEXlF2UVfEMzsMBakLlZOvQAubMwqOfBGMTfNnJE2b/+O6 IsC6la057NX8DF+b37FbO7Oi6xrulBRcHBFOR2VZhtIU043/2Xyg2tgn/XhGkT7bVY6U k9FD5fKTHvHryvhD+QRo+ZROPwO+hCY9I24/uS8JbPJYahIlfNwNvKviStTEDNiW7s+7 M0tyKpz7l+ZuuSgwu7+N78LLfmHv8MekqF5WYmRColKBj81Ye/yZ2ADIsDcGBdi+HBAF jB9xN9DKtzHfdmAxrRGqo1WY77mSE3hJbHw7cxaCHeNiqQQz0fvvTcP4N4uqX0TMPxR1 ZlmA== 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=fsqie9DP/xVl7vON6ezt0AdhOBqtz8CpDNLwZoU5tWg=; b=NmMGnyOB3FZvKm2AatK5ucBQ0VlL4jomQt1KuQS6Ofow6X51ZAVdapgCsqUuqiKa8v dGmJDrMcYAdKKP60xhpybDN4pCV46xmNMeLgfpV+GKjPOtTs3/C+X8c32UC2W2OnllGl 1pJrJ/70JXz6j7bkh63RUEWHW2Gzy9xw0oOJcYf7tXKXSn3aFJAhP+bhG7Yeh1s/vhTY 0tJG9mBZxOBDAXgjLdbh7ShI4kgBdH0bm3spy2w9pRn2/FyCjTx0kFKqgIZZY+8Vfhla tNIHXnE0qIiDWzsTHZCe7usbvpp6E/nvouBUkgYcS7SnTr8txaAGtIRYOoMmIrQWzPd2 uPHw== X-Gm-Message-State: AJIora9M5iVEnFzjQxTAtFwhi+c6Kfm1JkofwGD6jrcLTxL5lKXgod5j YglkNX5HgvZDvXZxKj5BRtIglWYCa3Ta8w== X-Google-Smtp-Source: AGRyM1s+mRb8KUeuuphRP4M9vRdCfTZqOYbY5zEATM80982zE+XBO84fuNRCWBmOVyOwEUlbI46Low== X-Received: by 2002:a5d:5686:0:b0:217:7da8:8c5a with SMTP id f6-20020a5d5686000000b002177da88c5amr1905870wrv.3.1655336158080; Wed, 15 Jun 2022 16:35:58 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id j19-20020a05600c1c1300b0039c5645c60fsm9223158wms.3.2022.06.15.16.35.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jun 2022 16:35:56 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Wed, 15 Jun 2022 23:35:40 +0000 Subject: [PATCH 06/11] pack-redundant: avoid using uninitialized memory 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 the `add_pack()` function, we forgot to initialize the field `next`, which could potentially lead to readin uninitialized memory later. Reported by Coverity. Signed-off-by: Johannes Schindelin --- builtin/pack-redundant.c | 1 + 1 file changed, 1 insertion(+) diff --git a/builtin/pack-redundant.c b/builtin/pack-redundant.c index ed9b9013a5f..1f7da1f68b6 100644 --- a/builtin/pack-redundant.c +++ b/builtin/pack-redundant.c @@ -526,6 +526,7 @@ static struct pack_list * add_pack(struct packed_git *p) } l.all_objects_size = l.remaining_objects->size; l.unique_objects = NULL; + l.next = NULL; if (p->pack_local) return pack_list_insert(&local_packs, &l); else From patchwork Wed Jun 15 23:35:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12883075 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 A21D4C43334 for ; Wed, 15 Jun 2022 23:36:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355176AbiFOXgK (ORCPT ); Wed, 15 Jun 2022 19:36:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352214AbiFOXgC (ORCPT ); Wed, 15 Jun 2022 19:36:02 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F6261FA4E for ; Wed, 15 Jun 2022 16:36:01 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id a15so17279755wrh.2 for ; Wed, 15 Jun 2022 16:36:00 -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=Nnd6xL32hUge5nGiU/0P2C+0HjczE0+v6Q2+Ox5siBs=; b=LKF9v/cFlsd68TYQYwpLvHl0l+Qz+4Gk4ZMX31GXnTDgPcRUYLGwzZ2QmrdT29QPtl DR8m3sylwY8IGnTjl8b5tfdkolT1kC/sbc9yntfsUYdEpSyv2SlQjyiDY1cJLDQRVFpz Nd3hXg/Vtn6ZmvMKguhC96/EMi45N+tYximtzEc/jv8bW4dqilzK3gTl0khwlsCwlOxH 8Dcg8+LjXkbaXZp9dTx6ohjYq0/pcuv2fkBM/VVNae71OYtFZJT9IH2peLvAjul86qgf 1LSrc5lQxe0/H50UXLziGt8KrPspj+YcRmV4nwqzFKZ/etKRL9In+SLn9qdCFWaSsUjO mFMQ== 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=Nnd6xL32hUge5nGiU/0P2C+0HjczE0+v6Q2+Ox5siBs=; b=PGZ+jRltHMHto6S6V95UO0rW+FeK1PzRq3OxhB98bneEYBev+XaVdo7ZVFtvoZHXjV Lh0xCozl5m8oQr0LD3JmDx+aYM5bL9T9Jj17IWePJiQ6Y5Z/bTIMwWsxvci7XMI2whze cOxamGvabiS0u13c1wbC78COVrxcCxFQq803eQmgV8ZKT/R1f2UKQTM4tUCFuNFy4FpG 7HQiqiwHH53CokTssTLim1o+gWKOoXkQTwW1eHwSaTlFA3J6KciOAgD5Ysf4tNEuU9uT V/FIpMfUvoH2LjvdIZRwiWbmKPKxA2RGu/6KDlKO6ZIIroKzNuROgDPbrXp1PtSE0OPJ M8dA== X-Gm-Message-State: AJIora9ABnV5AZQm7qUrJmdw2xLRrLinz4kDarC1Mb0jjM3JNgnFSDDQ qBHp9Xts2pnhtGze9cXS636KsfM1yJhI6w== X-Google-Smtp-Source: AGRyM1tXibuzsTVL/k+0GuegWxA0ZpyzZ2/Z3oFdvgrd4b6FaRJg/4d2KO0WezNb3uXq3LojnznpNA== X-Received: by 2002:a5d:4fc9:0:b0:213:aac9:33b3 with SMTP id h9-20020a5d4fc9000000b00213aac933b3mr1968887wrw.443.1655336159379; Wed, 15 Jun 2022 16:35:59 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id z18-20020a5d6412000000b002117f872f81sm194091wru.113.2022.06.15.16.35.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jun 2022 16:35:58 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Wed, 15 Jun 2022 23:35:41 +0000 Subject: [PATCH 07/11] submodule--helper: avoid memory leak when fetching submodules 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 c51f8f94e5b3 (submodule--helper: run update procedures from C, 2021-08-24), we added code that first obtains the default remote, and then adds that to a `strvec`. However, we never released the default remote's memory. Reported by Coverity. Signed-off-by: Johannes Schindelin --- builtin/submodule--helper.c | 1 + 1 file changed, 1 insertion(+) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index d7b8004b933..9a8248ffe6a 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2208,6 +2208,7 @@ static int fetch_in_submodule(const char *module_path, int depth, int quiet, str char *hex = oid_to_hex(oid); char *remote = get_default_remote(); strvec_pushl(&cp.args, remote, hex, NULL); + free(remote); } return run_command(&cp); From patchwork Wed Jun 15 23:35:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12883076 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 04FE6C43334 for ; Wed, 15 Jun 2022 23:36:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355614AbiFOXgL (ORCPT ); Wed, 15 Jun 2022 19:36:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353164AbiFOXgE (ORCPT ); Wed, 15 Jun 2022 19:36:04 -0400 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E6B81F2F1 for ; Wed, 15 Jun 2022 16:36:02 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id g4so664112wrh.11 for ; Wed, 15 Jun 2022 16:36:02 -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=z8+UMTp30b1F78jgENYieuMCerJSCWnKSUPMDjMHk04=; b=Ivy7WaHPqjGX6KDO4S2I8rVQj41lhgo9ekrlWaIrfrFyBFtYS2JzQlqyHVk1eud52S MS/mK8n2wQ8gM0EaDwJDKSG5u5atJwhL5FF6qyiaflCbeGvgioRQDdfFT6jlyiqSs4O/ A/s7rl/OZAJqg2iAG3Wrkp2SCmtqnOlu2/61gXUg9FiOxY9y3rheK5/rUvYFgB0z5PoE I660M/rZOiVV9IJujKKHw18uQ5QN4tudXX165wapVC4SLtCAVoLqfhjgVkanzrmlRtcM TVAVbbf86JNLzUtJouV8rwGLugeTWMH7Ol8xn814zQc/q5hLYtoJRo92m10OzULIt7Kh 28eQ== 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=z8+UMTp30b1F78jgENYieuMCerJSCWnKSUPMDjMHk04=; b=Og7O+BhNlI1a07OJ1MA8O3Q9QMknJ/vAZAb8qAIoOge3DeSs1hyZjApXaMMCCoDf9H /vld+4XD0zIEbpltPVciOMknM3AQQmRsrn7DE6LxCYQ8oZN706LaKlY0oE7WsDlw1M1G wXgHDVSwGbgxUGLxOb5+bHIbO5uV74J2MPWCHBjPt19sMa1++VYgXYsY7ZVa0gzsiSaK XS3cBDEYWLCrGDrogJ3rKcLA6Fn4XAbmimcIjj+jOuyIvZlT0fWxnBRlls1giaKFwVdw cwUEvjrTC7xyHuXR/gk2dDMA+oehM5xaAdDAw8RHhCA6O3ffJpCvsw+fca91JBQWgk3U lCmg== X-Gm-Message-State: AJIora/IRniMcTNDReAHxrooDZbqxIyJ843O2rr2GRwuFc/8dZfhTihX Tc+QSlkVf2vrMcUgDGB1FXwKZhqXMw6Rbg== X-Google-Smtp-Source: AGRyM1vUPb0ZIGGxeRsxREdHl5WNqV5CFStRkFrpjffwwiLASiNVz/UMcSP82r3On+qv0ZXg5Nkh7g== X-Received: by 2002:adf:cc92:0:b0:21a:356e:bda9 with SMTP id p18-20020adfcc92000000b0021a356ebda9mr124570wrj.509.1655336161182; Wed, 15 Jun 2022 16:36:01 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id be8-20020a05600c1e8800b0039c235fb6a5sm376771wmb.8.2022.06.15.16.35.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jun 2022 16:36:00 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Wed, 15 Jun 2022 23:35:42 +0000 Subject: [PATCH 08/11] read_index_from(): avoid memory leak 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 998330ac2e7c (read-cache: look for shared index files next to the index, too, 2021-08-26), we added code that allocates memory to store the base path of a shared index, but we never released that memory. Reported by Coverity. Signed-off-by: Johannes Schindelin --- read-cache.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/read-cache.c b/read-cache.c index e61af3a3d4d..76f372ff917 100644 --- a/read-cache.c +++ b/read-cache.c @@ -2473,15 +2473,15 @@ int read_index_from(struct index_state *istate, const char *path, the_repository, "%s", base_path); if (!ret) { char *path_copy = xstrdup(path); - const char *base_path2 = xstrfmt("%s/sharedindex.%s", - dirname(path_copy), - base_oid_hex); + char *base_path2 = xstrfmt("%s/sharedindex.%s", + dirname(path_copy), base_oid_hex); free(path_copy); trace2_region_enter_printf("index", "shared/do_read_index", the_repository, "%s", base_path2); ret = do_read_index(split_index->base, base_path2, 1); trace2_region_leave_printf("index", "shared/do_read_index", the_repository, "%s", base_path2); + free(base_path2); } if (!oideq(&split_index->base_oid, &split_index->base->oid)) die(_("broken index, expect %s in %s, got %s"), From patchwork Wed Jun 15 23:35:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12883077 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 1F6E1C433EF for ; Wed, 15 Jun 2022 23:36:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355709AbiFOXgN (ORCPT ); Wed, 15 Jun 2022 19:36:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354405AbiFOXgF (ORCPT ); Wed, 15 Jun 2022 19:36:05 -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 9F9F91FA70 for ; Wed, 15 Jun 2022 16:36:04 -0700 (PDT) Received: by mail-wm1-x330.google.com with SMTP id c130-20020a1c3588000000b0039c6fd897b4so1946764wma.4 for ; Wed, 15 Jun 2022 16:36:04 -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=Rz4Spf9wJ4JUzJ6rRlAuh8KL9eEdhg8OuaHDT2kKLkE=; b=erDyRc619uxEPNLB1Q/eN+3sYi6HNuibA7yUbPDkBhiyKsXzalA2h/XldpiKahhnpF zKjGVNChR5NJZRsKb6CmQuOOYWQFHCY0Ddc1g6gxRmfMfdNq2lcu7sTFpY+mtPmWl+4c xT/4McwmGkLDzFGKyl6IK9aV1y9JiFNNuRT3mPzEf6OGoVcGQyiKBiXBx8YbgVgrKvOG 9ueY/W8JAZlJEwCUd+nlT0vfZk/BhY7LSOYRYQsOnqu/Yho9Gb2LEQNPO/PrQYotITV8 VatmctypKYqdDcQmALwbFME1hpy5Cn9GnBa4bjLcy+4YInYFS/3VvaO9wfxlMdCWF0Ra Xobw== 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=Rz4Spf9wJ4JUzJ6rRlAuh8KL9eEdhg8OuaHDT2kKLkE=; b=y0h8F9ppRfXQhHfv/iF6ehwxY0gt8oYMR0/j22xhbEhjLJLwAD6QqPw0sMjrLfzIac 3rCjMkWfKLXhNC+XOLSxkWb28BxyLnu9X0qSbHlFEnWc8T+07xwQTgRO6H31HHPvls1u A6AWSox7ExdkopcoR6ecmKETnrt5th0T+RQ4s8Wiq9/Lx+fPOgtXGaMWsVlTnvPPXTZ9 6wA2iXAPCodUMm5GSb1JUKivzes9dYVQjyxJoU+e8CQLvcO85mh886fIIXbVDlIA3qRO bg56kDzA/bh0iFZRpnM0vUe4CMEuFQCQxIc2aENEpPswH55Htt2kmA+zp0b8dmsBxxmU Fz8Q== X-Gm-Message-State: AOAM531NMGYHvBZJLV+N4+h64fmUAmJeN97hUVEGf3E7MnyUFPratUY7 bpHpbyHIMaATN/dOGbNXLmTvwQXHmpTeRQ== X-Google-Smtp-Source: ABdhPJzAYZ/OLJVofTMJZpMjsc5HV23Y+3hlmfD4GGIvklzguH+bda+nTzcIlkIJbpg6zmg/MFkAbw== X-Received: by 2002:a05:600c:3ba7:b0:39c:5b80:3b76 with SMTP id n39-20020a05600c3ba700b0039c5b803b76mr12572880wms.35.1655336162745; Wed, 15 Jun 2022 16:36:02 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id e3-20020a5d5943000000b002103136623esm229630wri.85.2022.06.15.16.36.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jun 2022 16:36:01 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Wed, 15 Jun 2022 23:35:43 +0000 Subject: [PATCH 09/11] pack-mtimes: avoid closing a bogus file descriptor 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 94cd775a6c52 (pack-mtimes: support reading .mtimes files, 2022-05-20), code was added to close the file descriptor corresponding to the mtimes file. However, it is possible that opening that file failed, in which case we are closing a file descriptor with the value `-1`. Let's guard that `close()` call. Reported by Coverity. Signed-off-by: Johannes Schindelin --- pack-mtimes.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pack-mtimes.c b/pack-mtimes.c index 0e0aafdcb06..0f9785fc5e4 100644 --- a/pack-mtimes.c +++ b/pack-mtimes.c @@ -89,7 +89,8 @@ cleanup: *data_p = data; } - close(fd); + if (fd >= 0) + close(fd); return ret; } From patchwork Wed Jun 15 23:35:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12883078 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 5C813C43334 for ; Wed, 15 Jun 2022 23:36:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356444AbiFOXgT (ORCPT ); Wed, 15 Jun 2022 19:36:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350852AbiFOXgG (ORCPT ); Wed, 15 Jun 2022 19:36:06 -0400 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 26FF81EAF0 for ; Wed, 15 Jun 2022 16:36:06 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id h19so14037975wrc.12 for ; Wed, 15 Jun 2022 16:36:06 -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=rn9MUwmdpTYqKTHIEnRekJCNC83tRUHfChU0KJbXcrk=; b=gEsc1UvI0voufIfjYfzH3MOb6ozpUFooL6OYYHod5Bp+eFSS9gsaznr55EV2HvDGOu uwmqhMp9OYrzoymWbyxlYq5bPdnZm5njwqX18IFvsQ2ajT5TYBSI10Wod9r6QC3d6mCs 4geqFYgir3S+ytRxXNZASScyi2KWsKBzpZ/hutEh9Jx2BXC2i/TMTGenN1NQs6qBXulG RFg+zWIJng8yBMEM5c8VpfWWz3vZQoXYKrZQGXBnGhG6YM7ZSQJh7sKaUPKYenuyndY6 Ce1he9Dm+ogIIhvHi927GM6MfQ6PmGtRn4WBxDzLf93uqVXM7FKxrYJ7msXAxn6hi8LH X9JQ== 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=rn9MUwmdpTYqKTHIEnRekJCNC83tRUHfChU0KJbXcrk=; b=A5LMU+oKUyALmhxJ5uQqTh92Sa+n0PgjYsusuDoL5qoDWplvUhUCNis+fhrMZIhGSn RlFeBgMsRQAc8T4DiK+wLWIfSvqdVBIM6IZfNkh4Xh2pMoNzcoFRIm8peCsQTuZMybfA ZEMoPUBdYSRXm3p6vMplyNF4JCoIZxqQuN5gD9RU8sKorckwtYJuF/IxWLCRmttQlyvx vHO+S8CH5Pb8GCj6C2vVo/oeEl20u60c4McMieslSpfRn//uv66XGoM47N9xZcTL5Wzq u3acNDtZf+nyHgREQnkXShU7lCLVSiRACl0FA0Cj30LqA5Lax4ags+y8wa1uxbY7nJsd JoJQ== X-Gm-Message-State: AJIora+RF+u51k44u1FaiiiPMho3ZDkIUOjepKqKrikyDAFI4r8bcPEp vYXNx29t1qmbiYVCqxMWPiv5Wos08L8g0A== X-Google-Smtp-Source: AGRyM1ugFHcSlX9R5GqvLsQLVDXEnfFoDt7eJCQB8jQhYgnMwCS/MPID6+eVQ/+kFTacM2sMWDHfrg== X-Received: by 2002:a5d:64e7:0:b0:218:5626:7e7f with SMTP id g7-20020a5d64e7000000b0021856267e7fmr1973050wri.245.1655336164464; Wed, 15 Jun 2022 16:36:04 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id w5-20020a7bc105000000b003976fbfbf00sm315101wmi.30.2022.06.15.16.36.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jun 2022 16:36:03 -0700 (PDT) Message-Id: <0bf70e65d2c9e187203a77088ff0f7d18510caca.1655336146.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 15 Jun 2022 23:35:44 +0000 Subject: [PATCH 10/11] relative_url(): fix incorrect condition 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 63e95beb085c (submodule: port resolve_relative_url from shell to C, 2016-04-15), we added a loop over `url` where we are looking for `../` or `./` components. The loop condition we used is the pointer `url` itself, which is clearly not what we wanted. Pointed out by Coverity. Signed-off-by: Johannes Schindelin --- remote.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/remote.c b/remote.c index 9b9bbfe80ec..bded6acbfe8 100644 --- a/remote.c +++ b/remote.c @@ -2846,7 +2846,7 @@ char *relative_url(const char *remote_url, const char *url, * When the url starts with '../', remove that and the * last directory in remoteurl. */ - while (url) { + while (*url) { if (starts_with_dot_dot_slash_native(url)) { url += 3; colonsep |= chop_last_dir(&remoteurl, is_relative); From patchwork Wed Jun 15 23:35:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12883079 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 649FDC433EF for ; Wed, 15 Jun 2022 23:36:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356711AbiFOXgU (ORCPT ); Wed, 15 Jun 2022 19:36:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352091AbiFOXgH (ORCPT ); Wed, 15 Jun 2022 19:36:07 -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 766B81F2F1 for ; Wed, 15 Jun 2022 16:36:06 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id m24so17232234wrb.10 for ; Wed, 15 Jun 2022 16:36:06 -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=uYdSgTzWqiXia98lPyBfzCkBVv/id87lXXSTSIjOsUM=; b=YfqBfMNAqDxT7N1wEvbJqj+pS32pjU5ikpVyTaXTqoVxmyNvQtTSMcbHyPl4lE+yX1 VaPKvMunSyCh7YqxHsZ6n33+nyiJk5hnlmdfSKcCMrkREdDlOk6fDOA7xcAmntZGmEWR NrsEJQjvsJPmp12rMfB/f96PPwlg9C69x6MK7KlIYj1ViISu5ilW/B+twTvD6+gcTfyT fw5gSnYEsSEGeVqQHEMYQpErSbFTRUV/hB9DfkF87Q9M2QKzhErxVdZpm2NadLlyN+yA XX9h+/+bIgOjUVNljkwlPhMoHh4JkDv8paeI1oFo3AM38b3E9+5O+yGHVxRpXFMrTdHL KrpA== 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=uYdSgTzWqiXia98lPyBfzCkBVv/id87lXXSTSIjOsUM=; b=vWEMwklgakC/Pu6aIyaCksuXj44PGxPot6qQCHrmoKcCAMWZwDVebppNDeUI/FK2Cu 2tTgbtAP147fK7MjFrjcGRFssW/zJr8eBsbZI6kpuoqei5Frh/haw/mOtED2HCIH1ZdH qBoEbzRDTP9ATMw+siYxtwzw0ZgtqvuiGNX8IY8GLqLsmHiNyweb4KbYQ99uYyF/KrOQ Lzh0ybs7C6cdjEA7wcDAbjh3tzpRPx9H1mVBI0VxAv54iTnfKTDF0Ah2KpwTw0liNH4E Lp6+uQ80nI9mKSMcpptUGTL5y6LCg2qI/FK3roj1y3XjhGe36wC9gcrmCXZZEnlpIb3Y Wifg== X-Gm-Message-State: AJIora9ERPHYKddPf49DXQJqZVqszGH5bXB1pTR7Ef9AIpy5qatt1Pla JElqiuOlL4H6p3ajQsZkwHdZX4wavdcScQ== X-Google-Smtp-Source: AGRyM1sAIGoV1HQ2rs83vcGruYg5YGC1+nLPZKYks4r/IhlVggmFTyVxr8mpfGBLcO/JYaTBNkdzVg== X-Received: by 2002:a5d:4fc5:0:b0:211:c8fd:3d0f with SMTP id h5-20020a5d4fc5000000b00211c8fd3d0fmr2068063wrw.10.1655336165647; Wed, 15 Jun 2022 16:36:05 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id d5-20020a05600c3ac500b0039c457cea21sm300538wms.34.2022.06.15.16.36.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jun 2022 16:36:05 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Wed, 15 Jun 2022 23:35:45 +0000 Subject: [PATCH 11/11] bug_fl(): add missing `va_end()` call 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 According to the manual: Each invocation of va_copy() must be matched by a corresponding invocation of va_end() in the same function. Note: There is another instance of `va_copy()` in `usage.c` that is missing a `va_end()` call, in `BUG_vfl()`. It does not matter there, though, because that function either `exit()`s or `abort()`s, anyway. Reported by Coverity. Signed-off-by: Johannes Schindelin --- usage.c | 1 + 1 file changed, 1 insertion(+) diff --git a/usage.c b/usage.c index 79900d0287f..4849eb75785 100644 --- a/usage.c +++ b/usage.c @@ -343,6 +343,7 @@ void bug_fl(const char *file, int line, const char *fmt, ...) BUG_vfl_common(file, line, fmt, ap); va_end(ap); trace2_cmd_error_va(fmt, cp); + va_end(cp); } #ifdef SUPPRESS_ANNOTATED_LEAKS