From patchwork Tue Oct 2 17:55:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 10623957 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 29D6615A6 for ; Tue, 2 Oct 2018 17:55:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 186B02834A for ; Tue, 2 Oct 2018 17:55:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0CC7A283A5; Tue, 2 Oct 2018 17:55:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 28C33283BD for ; Tue, 2 Oct 2018 17:55:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727610AbeJCAkM (ORCPT ); Tue, 2 Oct 2018 20:40:12 -0400 Received: from smtp-out-2.talktalk.net ([62.24.135.66]:27023 "EHLO smtp-out-2.talktalk.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726720AbeJCAkL (ORCPT ); Tue, 2 Oct 2018 20:40:11 -0400 Received: from lindisfarne.localdomain ([92.28.142.68]) by smtp.talktalk.net with SMTP id 7OtMgc0MNVlGZ7OtSgNKnh; Tue, 02 Oct 2018 18:55:35 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=talktalk.net; s=cmr1711; t=1538502935; bh=OL0snNrzMotadA2Qcc02aSvvmAzLTHhtdAgOg0L+3T0=; h=From:To:Cc:Subject:Date:Reply-To; b=YWbikhRrhzDO5WnYhi9hE5oKwvQuCwpUBUxYDJ7zjVpCnc0vvFdd7Ni4DUxQLEre4 Q0kv8mUZpF0XPC+v/popAzKValy8EJVdcfXTG17IltunJ2DV3QbZJkR8pS6JpGUF6E BUAopS2zJWEfdX103kT2+qwY4DsJcNimuPBz+U6c= X-Originating-IP: [92.28.142.68] X-Spam: 0 X-OAuthority: v=2.3 cv=JcuSU3CV c=1 sm=1 tr=0 a=UGDAwvN9cmeZh0o4udnnNw==:117 a=UGDAwvN9cmeZh0o4udnnNw==:17 a=evINK-nbAAAA:8 a=ntzaUikQTcRssMVSSQcA:9 a=zsTBMss3UI1NevS6:21 a=AHVvEGFpytpJ4wty:21 a=RfR_gqz1fSpA9VikTjo0:22 From: Phillip Wood To: Stefan Beller Cc: Git Mailing List , Junio C Hamano , Phillip Wood Subject: [PATCH 1/5] diff --color-moved-ws: fix double free crash Date: Tue, 2 Oct 2018 18:55:10 +0100 Message-Id: <20181002175514.31495-1-phillip.wood@talktalk.net> X-Mailer: git-send-email 2.19.0 MIME-Version: 1.0 Reply-To: Phillip Wood X-CMAE-Envelope: MS4wfGVJQQjfhe11d9fwYfDRpENNcIPzjlWxScSxj0hevRKAcdI3nhuAEc0U8J0z5+Ghtue3dia8vqOrr0XEYlHTF3tqnwG+rd2oqAJ9I7M4PCRBHD9FC7h3 9o0mhU41f4M34eLofPw4AaLtdS6yQHbbTbimITa4CQKJwaOvyD5hCw8AGX38oZUXaNU3YIWCN+bBaAN5juCr4j5Cjxh71RCXbAvWN3W9os6vphqfRCSUaRoy BzZFYS8o8DZf+SPDEg2vON2MgK4VhGcuERbuKyIR0ZWoNP3mHrRKrXNPPNm7Xdya Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Phillip Wood Running git diff --color-moved-ws=allow-indentation-change v2.18.0 v2.19.0 results in a crash due to a double free. This happens when two potential moved blocks start with consecutive lines. As pmb_advance_or_null_multi_match() advances it copies the ws_delta from the last matching line to the next. When the first of our consecutive lines is advanced its ws_delta well be copied to the second, overwriting the ws_delta of the block containing the second line. Then when the second line is advanced it will copy the new ws_delta to the line below it and so on. Eventually one of these blocks will stop matching and the ws_delta will be freed. From then on the other block is in a use-after-free state and when it stops matching it will try to free the ws_delta that has already been freed by the other block. The solution is to store the ws_delta in the array of potential moved blocks rather than with the lines. This means that it no longer needs to be copied around and one block cannot overwrite the ws_delta of another. Additionally it saves some malloc/free calls as we don't keep allocating and freeing ws_deltas. Signed-off-by: Phillip Wood Reviewed-by: Stefan Beller --- diff.c | 73 +++++++++++++++++++++++++++++++++------------------------- 1 file changed, 41 insertions(+), 32 deletions(-) diff --git a/diff.c b/diff.c index 9393993e33..5a08d64497 100644 --- a/diff.c +++ b/diff.c @@ -751,7 +751,6 @@ struct moved_entry { struct hashmap_entry ent; const struct emitted_diff_symbol *es; struct moved_entry *next_line; - struct ws_delta *wsd; }; /** @@ -768,6 +767,17 @@ struct ws_delta { }; #define WS_DELTA_INIT { NULL, 0 } +struct moved_block { + struct moved_entry *match; + struct ws_delta wsd; +}; + +static void moved_block_clear(struct moved_block *b) +{ + FREE_AND_NULL(b->wsd.string); + b->match = NULL; +} + static int compute_ws_delta(const struct emitted_diff_symbol *a, const struct emitted_diff_symbol *b, struct ws_delta *out) @@ -785,7 +795,7 @@ static int compute_ws_delta(const struct emitted_diff_symbol *a, static int cmp_in_block_with_wsd(const struct diff_options *o, const struct moved_entry *cur, const struct moved_entry *match, - struct moved_entry *pmb, + struct moved_block *pmb, int n) { struct emitted_diff_symbol *l = &o->emitted_symbols->buf[n]; @@ -805,7 +815,7 @@ static int cmp_in_block_with_wsd(const struct diff_options *o, if (strcmp(a, b)) return 1; - if (!pmb->wsd) + if (!pmb->wsd.string) /* * No white space delta was carried forward? This can happen * when we exit early in this function and do not carry @@ -822,8 +832,8 @@ static int cmp_in_block_with_wsd(const struct diff_options *o, * one of them for the white spaces, depending which was longer. */ - wslen = strlen(pmb->wsd->string); - if (pmb->wsd->current_longer) { + wslen = strlen(pmb->wsd.string); + if (pmb->wsd.current_longer) { c += wslen; cl -= wslen; } else { @@ -873,7 +883,6 @@ static struct moved_entry *prepare_entry(struct diff_options *o, ret->ent.hash = xdiff_hash_string(l->line, l->len, flags); ret->es = l; ret->next_line = NULL; - ret->wsd = NULL; return ret; } @@ -913,76 +922,72 @@ static void add_lines_to_move_detection(struct diff_options *o, static void pmb_advance_or_null(struct diff_options *o, struct moved_entry *match, struct hashmap *hm, - struct moved_entry **pmb, + struct moved_block *pmb, int pmb_nr) { int i; for (i = 0; i < pmb_nr; i++) { - struct moved_entry *prev = pmb[i]; + struct moved_entry *prev = pmb[i].match; struct moved_entry *cur = (prev && prev->next_line) ? prev->next_line : NULL; if (cur && !hm->cmpfn(o, cur, match, NULL)) { - pmb[i] = cur; + pmb[i].match = cur; } else { - pmb[i] = NULL; + pmb[i].match = NULL; } } } static void pmb_advance_or_null_multi_match(struct diff_options *o, struct moved_entry *match, struct hashmap *hm, - struct moved_entry **pmb, + struct moved_block *pmb, int pmb_nr, int n) { int i; char *got_match = xcalloc(1, pmb_nr); for (; match; match = hashmap_get_next(hm, match)) { for (i = 0; i < pmb_nr; i++) { - struct moved_entry *prev = pmb[i]; + struct moved_entry *prev = pmb[i].match; struct moved_entry *cur = (prev && prev->next_line) ? prev->next_line : NULL; if (!cur) continue; - if (!cmp_in_block_with_wsd(o, cur, match, pmb[i], n)) + if (!cmp_in_block_with_wsd(o, cur, match, &pmb[i], n)) got_match[i] |= 1; } } for (i = 0; i < pmb_nr; i++) { if (got_match[i]) { /* Carry the white space delta forward */ - pmb[i]->next_line->wsd = pmb[i]->wsd; - pmb[i] = pmb[i]->next_line; + pmb[i].match = pmb[i].match->next_line; } else { - if (pmb[i]->wsd) { - free(pmb[i]->wsd->string); - FREE_AND_NULL(pmb[i]->wsd); - } - pmb[i] = NULL; + moved_block_clear(&pmb[i]); } } } -static int shrink_potential_moved_blocks(struct moved_entry **pmb, +static int shrink_potential_moved_blocks(struct moved_block *pmb, int pmb_nr) { int lp, rp; /* Shrink the set of potential block to the remaining running */ for (lp = 0, rp = pmb_nr - 1; lp <= rp;) { - while (lp < pmb_nr && pmb[lp]) + while (lp < pmb_nr && pmb[lp].match) lp++; /* lp points at the first NULL now */ - while (rp > -1 && !pmb[rp]) + while (rp > -1 && !pmb[rp].match) rp--; /* rp points at the last non-NULL */ if (lp < pmb_nr && rp > -1 && lp < rp) { pmb[lp] = pmb[rp]; - pmb[rp] = NULL; + pmb[rp].match = NULL; + pmb[rp].wsd.string = NULL; rp--; lp++; } @@ -1029,7 +1034,7 @@ static void mark_color_as_moved(struct diff_options *o, struct hashmap *add_lines, struct hashmap *del_lines) { - struct moved_entry **pmb = NULL; /* potentially moved blocks */ + struct moved_block *pmb = NULL; /* potentially moved blocks */ int pmb_nr = 0, pmb_alloc = 0; int n, flipped_block = 1, block_length = 0; @@ -1058,7 +1063,11 @@ static void mark_color_as_moved(struct diff_options *o, } if (!match) { + int i; + adjust_last_block(o, n, block_length); + for(i = 0; i < pmb_nr; i++) + moved_block_clear(&pmb[i]); pmb_nr = 0; block_length = 0; continue; @@ -1086,14 +1095,12 @@ static void mark_color_as_moved(struct diff_options *o, ALLOC_GROW(pmb, pmb_nr + 1, pmb_alloc); if (o->color_moved_ws_handling & COLOR_MOVED_WS_ALLOW_INDENTATION_CHANGE) { - struct ws_delta *wsd = xmalloc(sizeof(*match->wsd)); - if (compute_ws_delta(l, match->es, wsd)) { - match->wsd = wsd; - pmb[pmb_nr++] = match; - } else - free(wsd); + if (compute_ws_delta(l, match->es, + &pmb[pmb_nr].wsd)) + pmb[pmb_nr++].match = match; } else { - pmb[pmb_nr++] = match; + pmb[pmb_nr].wsd.string = NULL; + pmb[pmb_nr++].match = match; } } @@ -1110,6 +1117,8 @@ static void mark_color_as_moved(struct diff_options *o, } adjust_last_block(o, n, block_length); + for(n = 0; n < pmb_nr; n++) + moved_block_clear(&pmb[n]); free(pmb); } From patchwork Tue Oct 2 17:55:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 10623953 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9B69F1515 for ; Tue, 2 Oct 2018 17:55:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 82FA12834A for ; Tue, 2 Oct 2018 17:55:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 763D02841F; Tue, 2 Oct 2018 17:55:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A51B72834A for ; Tue, 2 Oct 2018 17:55:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727095AbeJCAkK (ORCPT ); Tue, 2 Oct 2018 20:40:10 -0400 Received: from smtp-out-2.talktalk.net ([62.24.135.66]:33180 "EHLO smtp-out-2.talktalk.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726645AbeJCAkK (ORCPT ); Tue, 2 Oct 2018 20:40:10 -0400 Received: from lindisfarne.localdomain ([92.28.142.68]) by smtp.talktalk.net with SMTP id 7OtMgc0MNVlGZ7OtTgNKnm; Tue, 02 Oct 2018 18:55:35 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=talktalk.net; s=cmr1711; t=1538502935; bh=P8ag5AEiZh28d5NxVOMvXDZYkQho8WHJqYyAxTCDpzw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:Reply-To; b=PZUZ6uQleFncW8Fb80uCPntOMNATyxfhCu7diTaIkzCPoCidXOcSqrT6wgXGyMhUO NW2yHjJq2DJpldXE3rb3XfS55R96/V8bQBQCPx5BBZiml3IRjDXG9tSkRC9l2pKObS uSS7bbheWCgxBHP1k1r9FCfPVUIVVmSg7PLxgwbI= X-Originating-IP: [92.28.142.68] X-Spam: 0 X-OAuthority: v=2.3 cv=JcuSU3CV c=1 sm=1 tr=0 a=UGDAwvN9cmeZh0o4udnnNw==:117 a=UGDAwvN9cmeZh0o4udnnNw==:17 a=evINK-nbAAAA:8 a=zrg1TGVO0JqqeQklKD4A:9 a=z_d1wuQn5cqjXh0E:21 a=0UEQN__nQJZCTTcb:21 a=RfR_gqz1fSpA9VikTjo0:22 From: Phillip Wood To: Stefan Beller Cc: Git Mailing List , Junio C Hamano , Phillip Wood Subject: [PATCH 2/5] diff --color-moved-ws: fix out of bounds string access Date: Tue, 2 Oct 2018 18:55:11 +0100 Message-Id: <20181002175514.31495-2-phillip.wood@talktalk.net> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181002175514.31495-1-phillip.wood@talktalk.net> References: <20181002175514.31495-1-phillip.wood@talktalk.net> MIME-Version: 1.0 Reply-To: Phillip Wood X-CMAE-Envelope: MS4wfGVJQQjfhe11d9fwYfDRpENNcIPzjlWxScSxj0hevRKAcdI3nhuAEc0U8J0z5+Ghtue3dia8vqOrr0XEYlHTF3tqnwG+rd2oqAJ9I7M4PCRBHD9FC7h3 9o0mhU41f4M34eLofPw4AaLtdS6yQHbbTbimITa4CQKJwaOvyD5hCw8AGX38oZUXaNU3YIWCN+bBaAN5juCr4j5Cjxh71RCXbAvWN3W9os6vphqfRCSUaRoy BzZFYS8o8DZf+SPDEg2vON2MgK4VhGcuERbuKyIR0ZWoNP3mHrRKrXNPPNm7Xdya Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Phillip Wood When adjusting the start of the string to take account of the change in indentation the code was not checking that the string being adjusted was in fact longer than the indentation change. This was detected by asan. Signed-off-by: Phillip Wood --- diff.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/diff.c b/diff.c index 5a08d64497..0096bdc339 100644 --- a/diff.c +++ b/diff.c @@ -841,7 +841,7 @@ static int cmp_in_block_with_wsd(const struct diff_options *o, al -= wslen; } - if (strcmp(a, c)) + if (al < 0 || al != cl || memcmp(a, c, al)) return 1; return 0; From patchwork Tue Oct 2 17:55:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 10623959 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 502163B73 for ; Tue, 2 Oct 2018 17:55:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3F85D2834A for ; Tue, 2 Oct 2018 17:55:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 34258283A5; Tue, 2 Oct 2018 17:55:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C7B0F283A8 for ; Tue, 2 Oct 2018 17:55:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727559AbeJCAkL (ORCPT ); Tue, 2 Oct 2018 20:40:11 -0400 Received: from smtp-out-2.talktalk.net ([62.24.135.66]:9532 "EHLO smtp-out-2.talktalk.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726818AbeJCAkL (ORCPT ); Tue, 2 Oct 2018 20:40:11 -0400 Received: from lindisfarne.localdomain ([92.28.142.68]) by smtp.talktalk.net with SMTP id 7OtMgc0MNVlGZ7OtTgNKnt; Tue, 02 Oct 2018 18:55:36 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=talktalk.net; s=cmr1711; t=1538502936; bh=5zAfwI85mKH1DQVg46djY86Rm2IFkR5AsFrC/Re7aLI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:Reply-To; b=WZSnPVkd67Z206xGm2AMHye/55wgkfY/IwRK2gQKIm9wHB4M/TGqOUK/Jln6U3tLq Pd/reo9yEzRBiFqF5tZQcJR0H6RrWEhGc4abzNoL7PxzobQJPqwgZTUVZvcFNOqAZS zKndxhZAZNbDm7ZOn1d7rm+mQpts9V7mCBhoUmE0= X-Originating-IP: [92.28.142.68] X-Spam: 0 X-OAuthority: v=2.3 cv=JcuSU3CV c=1 sm=1 tr=0 a=UGDAwvN9cmeZh0o4udnnNw==:117 a=UGDAwvN9cmeZh0o4udnnNw==:17 a=evINK-nbAAAA:8 a=EaTrdlfBmmo0FKB1FiUA:9 a=CgHqBV2zeH8inHE3:21 a=9uuab78wC2ypK9ax:21 a=RfR_gqz1fSpA9VikTjo0:22 From: Phillip Wood To: Stefan Beller Cc: Git Mailing List , Junio C Hamano , Phillip Wood Subject: [PATCH 3/5] diff --color-moved-ws: fix a memory leak Date: Tue, 2 Oct 2018 18:55:12 +0100 Message-Id: <20181002175514.31495-3-phillip.wood@talktalk.net> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181002175514.31495-1-phillip.wood@talktalk.net> References: <20181002175514.31495-1-phillip.wood@talktalk.net> MIME-Version: 1.0 Reply-To: Phillip Wood X-CMAE-Envelope: MS4wfFMBIxGeQbHF1R5SaElQS4Sbh0TL5VhT8X9MtReA7c4mU4pTQXiJjUK1BEk/33ZUFV9znylhkUV3QufOzLVVahoFvlqFArhOww2wT87/eC7Z7DYYtgOa KBbnyzBuxv6CvT8zaQaByqXfqkmsgf4zgQ0n7PPZ1GwqY3tN7D0q9NwdpRviuUODf7lP7PPczhVwn/YLlB7KefMnBbqEOjXZ/zvUMqAPW1SCNRYomkE5gVqM /x6FG/HdzaER83bGgQnaP5AH5TUL3GU8PMqPMPEtJYAeS96bgrioloSQrtXtSVDm Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Phillip Wood Don't duplicate the indentation string if we're not going to use it. This was found with asan. Signed-off-by: Phillip Wood --- diff.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/diff.c b/diff.c index 0096bdc339..efadd05c90 100644 --- a/diff.c +++ b/diff.c @@ -785,11 +785,15 @@ static int compute_ws_delta(const struct emitted_diff_symbol *a, const struct emitted_diff_symbol *longer = a->len > b->len ? a : b; const struct emitted_diff_symbol *shorter = a->len > b->len ? b : a; int d = longer->len - shorter->len; + int ret = !strncmp(longer->line + d, shorter->line, shorter->len); + + if (!ret) + return ret; out->string = xmemdupz(longer->line, d); out->current_longer = (a == longer); - return !strncmp(longer->line + d, shorter->line, shorter->len); + return ret; } static int cmp_in_block_with_wsd(const struct diff_options *o, From patchwork Tue Oct 2 17:55:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 10623955 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D411518A7 for ; Tue, 2 Oct 2018 17:55:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C09042834A for ; Tue, 2 Oct 2018 17:55:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B50012841F; Tue, 2 Oct 2018 17:55:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F25F3283A5 for ; Tue, 2 Oct 2018 17:55:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727679AbeJCAkM (ORCPT ); Tue, 2 Oct 2018 20:40:12 -0400 Received: from smtp-out-2.talktalk.net ([62.24.135.66]:62214 "EHLO smtp-out-2.talktalk.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726851AbeJCAkL (ORCPT ); Tue, 2 Oct 2018 20:40:11 -0400 Received: from lindisfarne.localdomain ([92.28.142.68]) by smtp.talktalk.net with SMTP id 7OtMgc0MNVlGZ7OtUgNKnz; Tue, 02 Oct 2018 18:55:37 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=talktalk.net; s=cmr1711; t=1538502937; bh=tLbqlNKt4ecjPvcJYjA2crvJ9IZwFZKQHVGMWgFvQRc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:Reply-To; b=ZNyf+Goko2a2g0wFxdncAsXMpeXJ2d05H2oAaG5UiOLQEO9UnMXiFZAdl735APO8W lS3FFWIRsI1pwquZx2EuGd01zQKa1qAtddq0CxvE7mUOhoAn7ntmKZ5QlnVWvrHmAO wJP4H9YeTy4GTa5xE8HacS7w8p1nh+S6VSsKJZPw= X-Originating-IP: [92.28.142.68] X-Spam: 0 X-OAuthority: v=2.3 cv=JcuSU3CV c=1 sm=1 tr=0 a=UGDAwvN9cmeZh0o4udnnNw==:117 a=UGDAwvN9cmeZh0o4udnnNw==:17 a=evINK-nbAAAA:8 a=n8RbOExCk_JQ8I0cbEoA:9 a=dpDMFQPqx-khGISw:21 a=nnnCPuPLab-uMWSV:21 a=RfR_gqz1fSpA9VikTjo0:22 From: Phillip Wood To: Stefan Beller Cc: Git Mailing List , Junio C Hamano , Phillip Wood Subject: [PATCH 4/5] diff --color-moved-ws: fix another memory leak Date: Tue, 2 Oct 2018 18:55:13 +0100 Message-Id: <20181002175514.31495-4-phillip.wood@talktalk.net> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181002175514.31495-1-phillip.wood@talktalk.net> References: <20181002175514.31495-1-phillip.wood@talktalk.net> MIME-Version: 1.0 Reply-To: Phillip Wood X-CMAE-Envelope: MS4wfOOkg9HYAapcoquWW4oBMdDY6JJcDZMQPDUyiM8c9C6CIO+EQ3Q5ZCIimSrRTe6OU4T02ziGZIEZs1szFHdFz7PzwxY0VRCKWJhYgeGFUeTLx1ItvhVn tWAPJ6CQssNufdM2+vOLZ1iFWSFg+XsyzuNJw8BFAgEvUfWCFLkSi3EGIhEoYed1ELIN1LVzKoZHPGgkwU9tV5Gd4N93cRT5MhkcR6gicmiHhaHXVISVpp4x OlHYl5ZNO7jD+o90kNx6pKOLInqmDr3YSeo6tg5Oj2Yg7YNkR97d4V6Bie9PkvN1 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Phillip Wood This is obvious in retrospect, it was found with asan. Signed-off-by: Phillip Wood --- diff.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/diff.c b/diff.c index efadd05c90..4464feacf8 100644 --- a/diff.c +++ b/diff.c @@ -971,6 +971,8 @@ static void pmb_advance_or_null_multi_match(struct diff_options *o, moved_block_clear(&pmb[i]); } } + + free(got_match); } static int shrink_potential_moved_blocks(struct moved_block *pmb, From patchwork Tue Oct 2 17:55:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 10623961 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E64EA1515 for ; Tue, 2 Oct 2018 17:55:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D5E752834A for ; Tue, 2 Oct 2018 17:55:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CA479283A5; Tue, 2 Oct 2018 17:55:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5321E283CB for ; Tue, 2 Oct 2018 17:55:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727711AbeJCAkN (ORCPT ); Tue, 2 Oct 2018 20:40:13 -0400 Received: from smtp-out-2.talktalk.net ([62.24.135.66]:33180 "EHLO smtp-out-2.talktalk.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726645AbeJCAkL (ORCPT ); Tue, 2 Oct 2018 20:40:11 -0400 Received: from lindisfarne.localdomain ([92.28.142.68]) by smtp.talktalk.net with SMTP id 7OtMgc0MNVlGZ7OtVgNKo9; Tue, 02 Oct 2018 18:55:38 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=talktalk.net; s=cmr1711; t=1538502938; bh=/YwCUiVIhkqSHYvr4PxPqGr1p+0w8pLg+zti1Shu29w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:Reply-To; b=RzOqRNc++Xv3VXfPmpX9CIol8fS5mfa3X7j8FnWcaMkFJ0AupPePiGih/Hj8MB5iG YNZWfCmeEGqojyudWODmaLYJctikWEMIOzloSC7XZa0JDyQ1T1qvK7zXvmXqOhubJz 1DVA/4y9lNT5pDAJAZrFnkC11b6e5MfCbjW5gO0Y= X-Originating-IP: [92.28.142.68] X-Spam: 0 X-OAuthority: v=2.3 cv=JcuSU3CV c=1 sm=1 tr=0 a=UGDAwvN9cmeZh0o4udnnNw==:117 a=UGDAwvN9cmeZh0o4udnnNw==:17 a=evINK-nbAAAA:8 a=FVCVqbMd_-HzSxj5j7YA:9 a=Vm1BYxNBd15DAg0M:21 a=xFJIqMZrjgypuhHE:21 a=RfR_gqz1fSpA9VikTjo0:22 From: Phillip Wood To: Stefan Beller Cc: Git Mailing List , Junio C Hamano , Phillip Wood Subject: [PATCH 5/5] diff --color-moved: fix a memory leak Date: Tue, 2 Oct 2018 18:55:14 +0100 Message-Id: <20181002175514.31495-5-phillip.wood@talktalk.net> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181002175514.31495-1-phillip.wood@talktalk.net> References: <20181002175514.31495-1-phillip.wood@talktalk.net> MIME-Version: 1.0 Reply-To: Phillip Wood X-CMAE-Envelope: MS4wfMYzgtMvpplU7/Oycl6R9aNNCniRpDaNLAAhEprwuX7Gav6sj6CaR5XY97S/egWDs3R4cR8xu8c3YAyLKP+PXHwSxmc3S+yogqEhS8wgDzw7oK8XJkSK 4+ke2PUJqPOjmyoQPkRGryWZtix29uAujZThlfs3lvowebxsM9uyYbtYXZ/eohNwFg5iml/nEzJdlNcohiX62erfer4bsuLsplN6OLrgUCQ77FWhIRQdCW6G BYsdMQmyeiByS59Hwjxrw8evVog1rNaP7xTBvW2CHUkJaU5LshSkJjOWVqUHvn6g Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Phillip Wood Free the hashmap items as well as the hashmap itself. This was found with asan. Signed-off-by: Phillip Wood --- diff.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/diff.c b/diff.c index 4464feacf8..94cc1b5592 100644 --- a/diff.c +++ b/diff.c @@ -5770,8 +5770,8 @@ static void diff_flush_patch_all_file_pairs(struct diff_options *o) if (o->color_moved == COLOR_MOVED_ZEBRA_DIM) dim_moved_lines(o); - hashmap_free(&add_lines, 0); - hashmap_free(&del_lines, 0); + hashmap_free(&add_lines, 1); + hashmap_free(&del_lines, 1); } for (i = 0; i < esm.nr; i++)