From patchwork Tue Oct 20 06:48:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?TWljaGHFgiBLxJlwaWXFhA==?= X-Patchwork-Id: 11845833 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9EA21C43457 for ; Tue, 20 Oct 2020 06:48:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5FE90223BF for ; Tue, 20 Oct 2020 06:48:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404555AbgJTGsS convert rfc822-to-8bit (ORCPT ); Tue, 20 Oct 2020 02:48:18 -0400 Received: from mx.pao1.isc.org ([149.20.64.53]:19240 "EHLO mx.pao1.isc.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404551AbgJTGsQ (ORCPT ); Tue, 20 Oct 2020 02:48:16 -0400 Received: from zmx1.isc.org (zmx1.isc.org [149.20.0.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx.pao1.isc.org (Postfix) with ESMTPS id BA8113AB0C9 for ; Tue, 20 Oct 2020 06:48:15 +0000 (UTC) Received: from zmx1.isc.org (localhost [127.0.0.1]) by zmx1.isc.org (Postfix) with ESMTPS id 93BCA160038 for ; Tue, 20 Oct 2020 06:48:15 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by zmx1.isc.org (Postfix) with ESMTP id 71C07160072 for ; Tue, 20 Oct 2020 06:48:15 +0000 (UTC) Received: from zmx1.isc.org ([127.0.0.1]) by localhost (zmx1.isc.org [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id HLw_HMPILfee for ; Tue, 20 Oct 2020 06:48:15 +0000 (UTC) Received: from larwa.hq.kempniu.pl (unknown [212.180.223.213]) by zmx1.isc.org (Postfix) with ESMTPSA id D4D15160042 for ; Tue, 20 Oct 2020 06:48:14 +0000 (UTC) From: =?utf-8?b?TWljaGHFgiBLxJlwaWXFhA==?= To: git@vger.kernel.org Subject: [PATCH v4 1/2] merge-base, xdiff: zero out xpparam_t structures Date: Tue, 20 Oct 2020 08:48:08 +0200 Message-Id: <20201020064809.14297-2-michal@isc.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201020064809.14297-1-michal@isc.org> References: <20201015072406.4506-1-michal@isc.org> <20201020064809.14297-1-michal@isc.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org xpparam_t structures are usually zero-initialized before their specific fields are assigned to, but there are three locations in the tree where that does not happen. Add the missing memset() calls in order to make initialization of xpparam_t structures consistent tree-wide and to prevent stack garbage from being used as field values. Signed-off-by: Michał Kępień --- builtin/merge-tree.c | 1 + xdiff/xhistogram.c | 2 ++ xdiff/xpatience.c | 2 ++ 3 files changed, 5 insertions(+) diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c index e72714a5a8..de8520778d 100644 --- a/builtin/merge-tree.c +++ b/builtin/merge-tree.c @@ -109,6 +109,7 @@ static void show_diff(struct merge_list *entry) xdemitconf_t xecfg; xdemitcb_t ecb; + memset(&xpp, 0, sizeof(xpp)); xpp.flags = 0; memset(&xecfg, 0, sizeof(xecfg)); xecfg.ctxlen = 3; diff --git a/xdiff/xhistogram.c b/xdiff/xhistogram.c index c7b35a9667..e694bfd9e3 100644 --- a/xdiff/xhistogram.c +++ b/xdiff/xhistogram.c @@ -235,6 +235,8 @@ static int fall_back_to_classic_diff(xpparam_t const *xpp, xdfenv_t *env, int line1, int count1, int line2, int count2) { xpparam_t xpparam; + + memset(&xpparam, 0, sizeof(xpparam)); xpparam.flags = xpp->flags & ~XDF_DIFF_ALGORITHM_MASK; return xdl_fall_back_diff(env, &xpparam, diff --git a/xdiff/xpatience.c b/xdiff/xpatience.c index 3c5601b602..20699a6f60 100644 --- a/xdiff/xpatience.c +++ b/xdiff/xpatience.c @@ -318,6 +318,8 @@ static int fall_back_to_classic_diff(struct hashmap *map, int line1, int count1, int line2, int count2) { xpparam_t xpp; + + memset(&xpp, 0, sizeof(xpp)); xpp.flags = map->xpp->flags & ~XDF_DIFF_ALGORITHM_MASK; return xdl_fall_back_diff(map->env, &xpp, From patchwork Fri Feb 5 14:13:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12071133 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E53BBC433E0 for ; Fri, 5 Feb 2021 22:28:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B31F964FDC for ; Fri, 5 Feb 2021 22:28:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232144AbhBEW15 (ORCPT ); Fri, 5 Feb 2021 17:27:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39806 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232075AbhBEOUK (ORCPT ); Fri, 5 Feb 2021 09:20:10 -0500 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D9FAC0698C3 for ; Fri, 5 Feb 2021 07:56:39 -0800 (PST) Received: by mail-ej1-x62f.google.com with SMTP id w1so12611954ejf.11 for ; Fri, 05 Feb 2021 07:56:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GDK16P2e0rTeYMiBGwvWsBHGJpVBBYm+JTdtKixPLIE=; b=N/puu1ticPrVVnoV8QYaGTI7PErmhUNzPFwuahjI4N+mMCGkQv9jW4zi/M7EEV2dSV OtxmALwfHIxlavzH1ngNBUAYewRH4Queeyt9yRKuDqhNPIeAEXQICdTkRE856/yltOK6 HXPLK9C9WOJLj0BJ4J9IXa9nEX1Om+1ShTknrIC4Xq8T+6C8RMJvYIUVs/hJhyOvovPS IvAyvnOCwliP6yrLBqHxel5nwZlXyUzARDVWru9bczd7SUqHPHnkwVNxHAc/ZVeMmE6R Uka5BOywa7gEyoDFx0tm0PLpUWb89ZkUAOg3rgi1HlGrk69+OqkytTO1RAAoCjAznBC4 zVPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=GDK16P2e0rTeYMiBGwvWsBHGJpVBBYm+JTdtKixPLIE=; b=gJSIN5IAXG0yx6yGuDo6rm5v1ceiFONn304MKr8AH+bWjQTg+y6G537mhYl0aDPO4e KxdvzjQnf+m2GiAqcZe0d4Hj/SLKvPBNl+KIxaRcGUAmeG8B4TKFceEunVES217HicrY EechBjCyZJHCXxqXWm91YK4k+yyTWpm4XmalN1t2Hup2Z7cfKggEgvO7X4LNX3loXluH +vAOO+C/pFcyKQuyJFSwB2JIHS2wP1T8BG6FXQh1fABVLtMKoZjlRuLOfpPOZIVBekC8 U6smG9VYNq7C9Bebb2OkfGX2Z/388HbXcxZa996a0CwtsTxIB4nG8Lk5t4FLv2CZNeYP L4wQ== X-Gm-Message-State: AOAM531gwzrCGG06QBLbGWeLpUGqLLFQBVTIr8lwta9HMbJVxhHnDArQ s6z4CZFxV8oIb5JvYTz3dlylk0nAjd+suA== X-Google-Smtp-Source: ABdhPJx6JPMH9qXo9vEavZ+kpPjSaeDHh2RHtrbMZz2prp6LptNJ81RaoQuE3mZMgsXJK7mdyxj6DQ== X-Received: by 2002:a05:6000:1547:: with SMTP id 7mr5323426wry.301.1612534656062; Fri, 05 Feb 2021 06:17:36 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id j15sm12630172wrw.9.2021.02.05.06.17.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Feb 2021 06:17:35 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , =?utf-8?b?TWljaGHFgiBLxJlwaWXFhA==?= , Johannes Schindelin , Phillip Wood , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= Subject: [PATCH 2/2] diff: plug memory leak from regcomp() on {log,diff} -I Date: Fri, 5 Feb 2021 15:13:20 +0100 Message-Id: <20210205141320.18076-2-avarab@gmail.com> X-Mailer: git-send-email 2.30.0.284.gd98b1dd5eaa7 In-Reply-To: <20201020064809.14297-1-michal@isc.org> References: <20201020064809.14297-1-michal@isc.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Fix a memory leak in 296d4a94e7 (diff: add -I that ignores matching changes, 2020-10-20) by freeing the memory it allocates in the newly introduced diff_free(). See the previous commit for details on that. This memory leak was intentionally introduced in 296d4a94e7, see the discussion on a previous iteration of it in https://lore.kernel.org/git/xmqqeelycajx.fsf@gitster.c.googlers.com/ At that time freeing the memory was somewhat tedious, but since it isn't anymore with the newly introduced diff_free() let's use it. Signed-off-by: Ævar Arnfjörð Bjarmason --- diff.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/diff.c b/diff.c index 3e6f8f0a71..24257759bb 100644 --- a/diff.c +++ b/diff.c @@ -6450,10 +6450,17 @@ void diff_flush(struct diff_options *options) void diff_free(struct diff_options *options) { + int i; if (options->no_free) return; if (options->fclose_file) fclose(options->file); + + for (i = 0; i < options->ignore_regex_nr; i++) { + regfree(options->ignore_regex[i]); + free(options->ignore_regex[i]); + } + free(options->ignore_regex); }