From patchwork Fri Apr 19 09:51:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13636074 Received: from wfhigh7-smtp.messagingengine.com (wfhigh7-smtp.messagingengine.com [64.147.123.158]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0F1877F49B for ; Fri, 19 Apr 2024 09:51:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.158 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713520304; cv=none; b=qy/+r2botO0UzleREMra4sYFWpxraNuLgjJf2eDDKb43lELAawHn2fzcGvZINvcsvQLsUmxykJyXrNoMXrFtje2CrygmpelMUtnqlJG4/OvTQbKRuvan8gso9U1Mb+9avydn4yUO0EHiqyEzuUGlEKOi0zPvzZyWIJ/HfPgvLuE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713520304; c=relaxed/simple; bh=7Eqtdk6lGd46dee0fWUHtgqfzuWnFppKS0flS2gaSQ4=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=cCimVZfj2y8fdMkTglAszwukMcGdpufb8uKSLTLM/VcSmfLCk562a9e3a3H+xEMnPITiShYHelXgtxarmPpPW8lgpbMi1/OyZy6Y4Z2krTX1M5FfZSxSSyXcd9cacgKPm2G0zT2UmDy0rtFilk/y8+B7JbtTG30OCH9ewcAsz2I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=g1lgUQSv; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=PcVQpsfk; arc=none smtp.client-ip=64.147.123.158 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="g1lgUQSv"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="PcVQpsfk" Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailfhigh.west.internal (Postfix) with ESMTP id 2146118000D3 for ; Fri, 19 Apr 2024 05:51:42 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute7.internal (MEProxy); Fri, 19 Apr 2024 05:51:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1713520301; x=1713606701; bh=Ws+Icsa0m0 o/RElShCPyupFZx1DnlkfPmgMhf+7BEqs=; b=g1lgUQSv+YaHvRSujecjpsBFLU CsEMFgda298An6Hn3uii0E64Sq+RHSZwwnhJ9Hmhj1eo2HZGEPZcsl6yjgXUg0QA s1lzQys1erIkGAWtegHHXHz46xZLUw/dW8x97qgTVJ5duQkLdyioFzDICzIbOktq 1IL6SAVDmkrUDHXdyYK93oh1X1jZOsemD1vgUXC1VuOhxTqjZ+vuoAm7zulSn9RC TatccP6AN0zRJA641AFaVE16I1jzD0JbgsL6uMyjl5XEL6qM0i+2jx4O4N862o/0 CYGgA7nqxvgtUsNfTqTH7xQgFyPL1pyWicHe824ZYCfAgDw8rdGKkfgPY6iw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1713520301; x=1713606701; bh=Ws+Icsa0m0o/RElShCPyupFZx1Dn lkfPmgMhf+7BEqs=; b=PcVQpsfkBdToHnkVo4Amxal6CEvF1zj7UlxHMTCo/5G4 pR9ghhwWPSxBB9htliT2lY1tpZ6iO+MaUSq4UEJMJhyDGVdtiwyzBgi/W8B93e/l XChQAaSX7F4+SHnJPNJcU/49Ogx2msYJcpkATKUZ1HXzr81gPwXT0LlJsWkZnyrZ ayqjZAY++LoLmICYiAQiK1NJbOHMtxnAr26/8ESCWXni+i5zu3lFY6RjpVMRbvWw Bs3c33CGtUMG/tuVmSSigaEv23Rgtx6QzY1gyg1MWPg/dxBJhQpKEtac24Zm4DwA mopBtszB+jeagVPIwP03DQBsHOEqQHb2vJ57gHuNMg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrudekvddgvdduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkfhggtggujgesghdtre ertddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehp khhsrdhimheqnecuggftrfgrthhtvghrnhepheeghfdtfeeuffehkefgffduleffjedthf dvjeektdfhhedvlefgtefgvdettdfhnecuvehluhhsthgvrhfuihiivgepvdenucfrrghr rghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Fri, 19 Apr 2024 05:51:40 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id e83b718a (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Fri, 19 Apr 2024 09:51:14 +0000 (UTC) Date: Fri, 19 Apr 2024 11:51:38 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 07/11] builtin/blame: don't access potentially unitialized `the_hash_algo` Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: We access `the_hash_algo` in git-blame(1) before we have executed `parse_options_start()`, which may not be properly set up in case we have no repository. This is fine for most of the part because all the call paths that lead to it (git-blame(1), git-annotate(1) as well as git-pick-axe(1)) specify `RUN_SETUP` and thus require a repository. There is one exception though, namely when passing `-h` to print the help. Here we will access `the_hash_algo` even if there is no repo. This works fine right now because `the_hash_algo` gets sets up to point to the SHA1 algorithm via `initialize_repository()`. But we're about to stop doing this, and thus the code would lead to a `NULL` pointer exception. Prepare the code for this and only access `the_hash_algo` after we are sure that there is a proper repository. Signed-off-by: Patrick Steinhardt --- builtin/blame.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/builtin/blame.c b/builtin/blame.c index 9aa74680a3..e325825936 100644 --- a/builtin/blame.c +++ b/builtin/blame.c @@ -915,7 +915,6 @@ int cmd_blame(int argc, const char **argv, const char *prefix) struct range_set ranges; unsigned int range_i; long anchor; - const int hexsz = the_hash_algo->hexsz; long num_lines = 0; const char *str_usage = cmd_is_annotate ? annotate_usage : blame_usage; const char **opt_usage = cmd_is_annotate ? annotate_opt_usage : blame_opt_usage; @@ -973,11 +972,11 @@ int cmd_blame(int argc, const char **argv, const char *prefix) } else if (show_progress < 0) show_progress = isatty(2); - if (0 < abbrev && abbrev < hexsz) + if (0 < abbrev && abbrev < (int)the_hash_algo->hexsz) /* one more abbrev length is needed for the boundary commit */ abbrev++; else if (!abbrev) - abbrev = hexsz; + abbrev = the_hash_algo->hexsz; if (revs_file && read_ancestry(revs_file)) die_errno("reading graft file '%s' failed", revs_file);