Message ID | 20250207-pks-reftable-drop-git-compat-util-v5-4-ba2adc79110f@pks.im (mailing list archive) |
---|---|
State | Superseded |
Headers | show
Received: from fout-a8-smtp.messagingengine.com (fout-a8-smtp.messagingengine.com [103.168.172.151]) (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 D3E711DF752 for <git@vger.kernel.org>; Fri, 7 Feb 2025 11:52:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.151 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738929132; cv=none; b=dd560MRkS2RY2FEkxthh5yyKEx3bguiSFNX+7FjyWoKFLxDS5gdz4funOy1U4p0HuVkBo8ucv9IFQmmaQmj1MemUB9rxqQl7tYQUedmJzgzjok9eI7UbEIX+Aeg7GeVlHlVjzbLpI++Jsi6r5VevN18f9qISNpfHyUTSpBsTpus= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738929132; c=relaxed/simple; bh=+sfDFJ9ndI2wqkFzPAkNIaU0EeKHSdWxl33c5nvqNz0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ctOGdQPtkGaxeXpIKcMTTlJgtiZY638YMO/Wfxv1W86mUAURmeTmRpEU9BbUHJGOaqUXOtBgiLruyPJdjiYOzBsjyyWDSxum33rjYw/7SGx3j82IZWGHo86YdNsO21PQ8KFW509MEDMSAIZBbsus94f5LQ9NyObiEkEkxDQs7qc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject 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=dnDdaewK; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=WerveR/7; arc=none smtp.client-ip=103.168.172.151 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject 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="dnDdaewK"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="WerveR/7" Received: from phl-compute-06.internal (phl-compute-06.phl.internal [10.202.2.46]) by mailfout.phl.internal (Postfix) with ESMTP id E4122138016B; Fri, 7 Feb 2025 06:52:08 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-06.internal (MEProxy); Fri, 07 Feb 2025 06:52:08 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-transfer-encoding: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=1738929128; x=1739015528; bh=C7QV0kCJ4r1t8KXYpuFP34bogFrxND3jDhV8HS9ZL3s=; b= dnDdaewK2BEhMWGzC2CBvlPCcbGMLLUo0DIYl2MJPglxZXxSnIkLkYFJmYK3CNeu FmP+EPmvli+/zphbEgqRKtf1jzM0xLhRnIZxKQciONRwjyvmjQK+gdk/UU43tbyG o6uvfuAgpEj9SXBBSOVNqbqTSVdQq82f2RRmKMRJ/kqIj9G+bufgTKrqkoAYOpXJ KApiKqcRM1aCGH6zA4f+pbAfG1jrQz+XuzelszAK+E9vOGOcFA76ankcPCq+rQrl 5Pk+hrncAsfVSyCPRSD8XIpWgBwUmSFwV26THqJ/qGH3txCjQ/9nNhbptG7Tm7lG voT2IKBHYi3YsVtKRz5JWA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :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-sender:x-me-sender:x-sasl-enc; s=fm3; t=1738929128; x= 1739015528; bh=C7QV0kCJ4r1t8KXYpuFP34bogFrxND3jDhV8HS9ZL3s=; b=W erveR/798wS3/AGUvNWQT7yc+j3qxouti2j0o9r3y+uGNXgF5eM+jeq/IE3hAKKB 9P7zTippFxmFXxmBQYP3RSRTC4WzY4vKsKh90vGyv54EXNLrHFMV29/5NDOqoaXx ddg2XsvPqc6ht9V1wo6g5mU1zQxawA2NE1DX/IX5XZQ3yvWt58z3NURgr7DDmXki 2kLQ2LSjVScwPv3jVqsQ1WVu7rQtH4aYoU7nNmi2t50GlI0Rzr7spomjFgbXpaov aayaabVh1PFn+PnvsnTqG9tprbXtTiA2QInyBoaeukXsS6Vk0ZIb5Eo4VfpQmtI1 XQrwYnePmbmjjkaZCI3Ng== X-ME-Sender: <xms:6POlZ3ssG524UeqNx04dkF7E_WOI6AaPYhBkWewWpfQUzD100KGwpA> <xme:6POlZ4eO4kFI_Z3nOXT1L82yM-8VCwiSmvTB0sV-KRGx4jQ2OwrikEGSqP6V3cAan t2N5T83YwznnOEOJw> X-ME-Received: <xmr:6POlZ6xRWAc_cQu-CiEKTOBlzhxt1S54O_BquWtNjRih3iNP8lhLpndbv4QIWogrDAJ11jUkF358qfCz9mEQMnB0CRNb0RJ3nafZuMXRlCn5XxCj> X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddvledvudcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenucfjughrpefhfffugggtgffkfhgjvfevofesthejredtredt jeenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrd himheqnecuggftrfgrthhtvghrnhepffeuiedujedvkeehuedvkeefffeivdeuleetkedu heejteekgedvudfgtdfgieelnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohephedpmhhouggv pehsmhhtphhouhhtpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrgh dprhgtphhtthhopehgihhtshhtvghrsehpohgsohigrdgtohhmpdhrtghpthhtohepjhhl thhosghlvghrsehgmhgrihhlrdgtohhmpdhrtghpthhtohepjheitheskhgusghgrdhorh hgpdhrtghpthhtohepvghthhhomhhsohhnsegvugifrghrughthhhomhhsohhnrdgtohhm X-ME-Proxy: <xmx:6POlZ2O6bjFGFVUi0IRVVZliwSf0bnD8MT2dszckPF8LDoU0mvqqaQ> <xmx:6POlZ38SInGCNeihIYL6cOPyniaNpWhMAdAvYkVgc61rHfDcUk-0qA> <xmx:6POlZ2WWGnj-sXiqpToOBWFZVTOqqVPvFIinKROYlWRR7rJ6ILfqPA> <xmx:6POlZ4dYKrQapxb5bBVpdILbbf-FeLZ6DuEttGHGANfC_aHune1yRA> <xmx:6POlZymO4dTBajaK4WiPmfcwGpHtZ24oSbuLTntk0zk3w9WF0EXvr16b> Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 7 Feb 2025 06:52:07 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 2586e381 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 7 Feb 2025 11:52:04 +0000 (UTC) From: Patrick Steinhardt <ps@pks.im> Date: Fri, 07 Feb 2025 12:51:59 +0100 Subject: [PATCH v5 04/18] reftable/record: stop using `COPY_ARRAY()` Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: <git.vger.kernel.org> List-Subscribe: <mailto:git+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:git+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20250207-pks-reftable-drop-git-compat-util-v5-4-ba2adc79110f@pks.im> References: <20250207-pks-reftable-drop-git-compat-util-v5-0-ba2adc79110f@pks.im> In-Reply-To: <20250207-pks-reftable-drop-git-compat-util-v5-0-ba2adc79110f@pks.im> To: git@vger.kernel.org Cc: Edward Thomson <ethomson@edwardthomson.com>, Justin Tobler <jltobler@gmail.com>, Junio C Hamano <gitster@pobox.com>, Johannes Sixt <j6t@kdbg.org> X-Mailer: b4 0.14.2 |
Series |
reftable: stop using "git-compat-util.h"
|
expand
|
diff --git a/reftable/record.c b/reftable/record.c index 8919df8a4d..2c0cc32cbd 100644 --- a/reftable/record.c +++ b/reftable/record.c @@ -504,11 +504,17 @@ static int reftable_obj_record_copy_from(void *rec, const void *src_rec, if (src->hash_prefix_len) memcpy(obj->hash_prefix, src->hash_prefix, obj->hash_prefix_len); - REFTABLE_ALLOC_ARRAY(obj->offsets, src->offset_len); - if (!obj->offsets) - return REFTABLE_OUT_OF_MEMORY_ERROR; - obj->offset_len = src->offset_len; - COPY_ARRAY(obj->offsets, src->offsets, src->offset_len); + if (src->offset_len) { + if (sizeof(*src->offsets) > SIZE_MAX / src->offset_len) + return REFTABLE_OUT_OF_MEMORY_ERROR; + + REFTABLE_ALLOC_ARRAY(obj->offsets, src->offset_len); + if (!obj->offsets) + return REFTABLE_OUT_OF_MEMORY_ERROR; + + memcpy(obj->offsets, src->offsets, sizeof(*src->offsets) * src->offset_len); + obj->offset_len = src->offset_len; + } return 0; }
Drop our use of `COPY_ARRAY()`, replacing it with an open-coded variant thereof. This is done to reduce our dependency on the Git library. While at it, guard the whole array copy logic so that we only copy it in case there actually is anything to be copied. Otherwise, we may end up trying to allocate a zero-sized array, which will return a NULL pointer and thus cause us to return an `REFTABLE_OUT_OF_MEMORY_ERROR`. Signed-off-by: Patrick Steinhardt <ps@pks.im> --- reftable/record.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)