From patchwork Wed Apr 15 20:32:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin via GitGitGadget X-Patchwork-Id: 11491937 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0E0566CA for ; Wed, 15 Apr 2020 20:32:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E1B432078B for ; Wed, 15 Apr 2020 20:32:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JDIzETvp" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S371251AbgDOUcj (ORCPT ); Wed, 15 Apr 2020 16:32:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S2636965AbgDOUc3 (ORCPT ); Wed, 15 Apr 2020 16:32:29 -0400 Received: from mail-ed1-x544.google.com (mail-ed1-x544.google.com [IPv6:2a00:1450:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0CDADC061A10 for ; Wed, 15 Apr 2020 13:32:29 -0700 (PDT) Received: by mail-ed1-x544.google.com with SMTP id ca21so6729896edb.7 for ; Wed, 15 Apr 2020 13:32:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=dG3NkKChRsTApDpikUSdiqFvX3FGhTiGGuLhBA15Ab8=; b=JDIzETvpKLreV//pHFmY7TdYGyXg88dq4jq0/qixiry2ULg/SP7Q94Wux0I/mmxNL7 S81JJooXcG27mOjLoxIZQGoTmYaBVk+0+hsYbgrijQELpqi2X5z/RFvcY/FB13qemJn2 T5tK6OWWvbsFOUKJRmI+N2VV0w4oezT2bze6/JTIQRbO280Vb2WOy2JZ6Jnd9H0hluWk duRTCh9wBuHiUOLp9386oNltXr/2YnoJuSzvlxmZnDrCzTOe+CD1lKEPGH73lMtR5QhH NYW4ATaX8oAexUc8OOvtHV5KD0KRCmRhoUL+WA1DGW9VOY5C2I02JgDibis3xbe/zTzr djWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=dG3NkKChRsTApDpikUSdiqFvX3FGhTiGGuLhBA15Ab8=; b=GmzZjK1B4adKTbey8P20FnIQlKxR5nFvnJTktZgTIA/QPYfCanoW8BQn1OreCGAbVj PYAsvkNAmnw4v8IgDMBewQp6XcAf2qR6pmzcr+4WwK0gjPboyWlNiPfZ4/yVpJNFYh2U nGIZOfePqVuR037NX6BAoKFiEeb89zFKBbGIhPLJfc7syrak2c6NRsoAkLnzaCx2Beft vfbOlDxeL7p6vxUzNWiryzOQE8sIsWvf4B+zYGMs2K4JoezdQtqpOqVQ0WMy5VQ5D4wf 7Cje7j+OgI2reWn3qqiuo7cY71+Hf7Rf3NiuOQ0KGc5X32EM5WyHavoAp9nt8AIUTh1n CfoA== X-Gm-Message-State: AGi0PuaW5s6w8Po1PAO4lO218dnF1CzsNioXBj6w+872kXfgCCAuhayN WMlJX/ESy7y8PNERA28el5wYTXoY X-Google-Smtp-Source: APiQypLFsO4Lw/ex1k1sYJirIjiBzVR/jDUDqa+3CpQZhMD/myRs2TgDZaHfqSVZInLlW7H1cxcHkg== X-Received: by 2002:a50:9d42:: with SMTP id j2mr26385035edk.249.1586982747549; Wed, 15 Apr 2020 13:32:27 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id ce16sm2640410ejc.74.2020.04.15.13.32.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Apr 2020 13:32:27 -0700 (PDT) Message-Id: <2375e34100e571f9c3ce658d28aba6648fba18a6.1586982745.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Vasil Dimov via GitGitGadget" Date: Wed, 15 Apr 2020 20:32:24 +0000 Subject: [PATCH v2 1/2] range-diff: fix a crash in parsing git-log output Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Vasil Dimov , Vasil Dimov Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Vasil Dimov `git range-diff` calls `git log` internally and tries to parse its output. But `git log` output can be customized by the user in their git config and for certain configurations either an error will be returned by `git range-diff` or it will crash. To fix this explicitly set the output format of the internally executed `git log` with `--pretty=medium`. Because that cancels `--notes`, add explicitly `--notes` at the end. Also, make sure we never crash in the same way - trying to dereference `util` which was never created and has remained NULL. It would happen if the first line of `git log` output does not begin with 'commit '. Alternative considered but discarded - somehow disable all git configs and behave as if no config is present in the internally executed `git log`, but that does not seem to be possible. GIT_CONFIG_NOSYSTEM is the closest to it, but even with that we would still read `.git/config`. Signed-off-by: Vasil Dimov --- range-diff.c | 13 +++++++++++++ t/t3206-range-diff.sh | 10 ++++++++++ 2 files changed, 23 insertions(+) diff --git a/range-diff.c b/range-diff.c index f745567cf67..5cc920be391 100644 --- a/range-diff.c +++ b/range-diff.c @@ -63,6 +63,8 @@ static int read_patches(const char *range, struct string_list *list, "--output-indicator-old=<", "--output-indicator-context=#", "--no-abbrev-commit", + "--pretty=medium", + "--notes", NULL); if (other_arg) argv_array_pushv(&cp.args, other_arg->argv); @@ -106,6 +108,17 @@ static int read_patches(const char *range, struct string_list *list, continue; } + if (!util) { + error(_("could not parse first line of `log` output: " + "did not start with 'commit ': '%s'"), + line); + string_list_clear(list, 1); + strbuf_release(&buf); + strbuf_release(&contents); + finish_command(&cp); + return -1; + } + if (starts_with(line, "diff --git")) { struct patch patch = { 0 }; struct strbuf root = STRBUF_INIT; diff --git a/t/t3206-range-diff.sh b/t/t3206-range-diff.sh index bd808f87ed5..e024cff65cb 100755 --- a/t/t3206-range-diff.sh +++ b/t/t3206-range-diff.sh @@ -513,6 +513,16 @@ test_expect_success 'range-diff overrides diff.noprefix internally' ' git -c diff.noprefix=true range-diff HEAD^... ' +test_expect_success 'basic with modified format.pretty with suffix' ' + git -c format.pretty="format:commit %H%d%n" range-diff \ + master..topic master..unmodified +' + +test_expect_success 'basic with modified format.pretty without "commit "' ' + git -c format.pretty="format:%H%n" range-diff \ + master..topic master..unmodified +' + test_expect_success 'range-diff compares notes by default' ' git notes add -m "topic note" topic && git notes add -m "unmodified note" unmodified && From patchwork Wed Apr 15 20:32:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin via GitGitGadget X-Patchwork-Id: 11491939 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2298C92C for ; Wed, 15 Apr 2020 20:32:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0A33820787 for ; Wed, 15 Apr 2020 20:32:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="GJpmunkd" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2438404AbgDOUcz (ORCPT ); Wed, 15 Apr 2020 16:32:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S2636968AbgDOUca (ORCPT ); Wed, 15 Apr 2020 16:32:30 -0400 Received: from mail-ed1-x543.google.com (mail-ed1-x543.google.com [IPv6:2a00:1450:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 099C2C061A41 for ; Wed, 15 Apr 2020 13:32:30 -0700 (PDT) Received: by mail-ed1-x543.google.com with SMTP id r7so104874edo.11 for ; Wed, 15 Apr 2020 13:32:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=GzmpfVcWwFgm71xNfp3t2ZsVFTZARKOsv58I8Lux5JQ=; b=GJpmunkd61SZU0hn8mQJuVLY6HnQUoRoNqVQRh6X1Js/fiiMYjpGmKg4bx+E7wSjl7 nPC9S3s3bwvFHuC4xNIIb84CdnXzh1dYftQRIuYl8/27VSEse6DSImeM5anXx3cpAYNF n/6GVRhTTWkgyqGTnML1meMTKTOA/pAAjg4LpIR5iXonuJU8YLo4zdVw0U0RwVDlUE0V IMCyymxAiI6nOJUsAWzNoH+dJo8uYMZvmJGpUlAoeR98cX8mWKwfED0iEb3w/8ENRFvW A3oiitXGA1PtcLdf0FR5tIV9iA2bVC2W+tC/e0QrzxtOaS+5GLNZGuk0LzqmKgFEeGcC eVFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=GzmpfVcWwFgm71xNfp3t2ZsVFTZARKOsv58I8Lux5JQ=; b=DLpr9P2DKsq8B0Uxk7JlMvF0D+c/wM2VKk2ubwBlbElDgkxt7UpqoHwyHwNTpxxLoT qCrkciPv+USg1VhdrZkJwD+O/VyDawt9POGegsEXJxGqW+cE61+Yz3FVg5HTU9BASn36 eXW654CdhgJJ3LbwF0yCrmX17leKU1hHP35JrsqDqlrhGIXO1x4clJ8w8JqkO5FjF7yh LR4/BMdtSVhjzs+X3Ovg0mIeEUWQ+rXHzGpplzY5n/+eqX3FJzWUYNEIIjuf3/Up0TgW ztTbukSmXqs4woMfc1HpalAjbI/IWoQ+JjjhSfRv3PJgLH1LtFjMoK/ioOLrj/cTPdzk WnQw== X-Gm-Message-State: AGi0PubYHpqXeyhUc+0cgnikQ0IlpFYoUXTBDKrL7IxdjkbmGiinBNPu hyS5zGxwa3T/jQGhzqpHn1s/+DJl X-Google-Smtp-Source: APiQypLDDFMVvacuKoPrJejSV5f/0jz1cK1Hh121QcxJIh0IIsyX/DyFDQN8Nq1Qa+lC6PKgXhsFpQ== X-Received: by 2002:a50:e809:: with SMTP id e9mr19430078edn.182.1586982748331; Wed, 15 Apr 2020 13:32:28 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id l16sm2233946edv.71.2020.04.15.13.32.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Apr 2020 13:32:27 -0700 (PDT) Message-Id: <72fddcff55425cffb598790fce3d5e7c47325234.1586982745.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Vasil Dimov via GitGitGadget" Date: Wed, 15 Apr 2020 20:32:25 +0000 Subject: [PATCH v2 2/2] range-diff: avoid negative string precision Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Vasil Dimov , Vasil Dimov Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Vasil Dimov If the supplied integer for "precision" is negative in `"%.*s", len, line` then it is ignored. So the current code is equivalent to just `"%s", line` because it is executed only if `len` is negative. Fix this by saving the value of `len` before overwriting it with the return value of `parse_git_diff_header()`. Signed-off-by: Vasil Dimov --- range-diff.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/range-diff.c b/range-diff.c index 5cc920be391..40af0862818 100644 --- a/range-diff.c +++ b/range-diff.c @@ -123,16 +123,19 @@ static int read_patches(const char *range, struct string_list *list, struct patch patch = { 0 }; struct strbuf root = STRBUF_INIT; int linenr = 0; + int orig_len; in_header = 0; strbuf_addch(&buf, '\n'); if (!util->diff_offset) util->diff_offset = buf.len; line[len - 1] = '\n'; + orig_len = len; len = parse_git_diff_header(&root, &linenr, 0, line, len, size, &patch); if (len < 0) - die(_("could not parse git header '%.*s'"), (int)len, line); + die(_("could not parse git header '%.*s'"), + orig_len, line); strbuf_addstr(&buf, " ## "); if (patch.is_new > 0) strbuf_addf(&buf, "%s (new)", patch.new_name);