From patchwork Tue Feb 13 16:01:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Kristoffer Haugsbakk X-Patchwork-Id: 13555319 Received: from fhigh7-smtp.messagingengine.com (fhigh7-smtp.messagingengine.com [103.168.172.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 C03EC5F547 for ; Tue, 13 Feb 2024 16:02:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.158 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707840126; cv=none; b=HfjS5Mx7sqiyaSuet39Z5LaCuT0BclC8gQhOUZkeUCDetJzRMQ+VOVIvAypZHy2puE+smUauZtswsOSDA4iJ5I8XtIuJEYnFnRGI1CJZgct9FDpHATgk4ZmNIt4mdMOGa6zHjozojg/sZPwV6FTtIP0IX8SLyxB/qnMl4y5JL90= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707840126; c=relaxed/simple; bh=s+nXSf0HqOPzvWmykAMqvMprok3R5W6LYbexLVO41JA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=IU4D8/YR2s7Cg0Sp4O9swZs0lYWi+WV0VlJvcPtJpIxZoSBWIcWUF/lNJmz6FTL47+JwfiKdwIxiz/C5bhQtxGVHMTuiaKmvEj4RvAyEumJeuFaO/CeDX5qwE2PEcYlhRfbEEOJLuq82Qts1ATh5dKQ2jvskeBbcpWVjmMTEm1U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=khaugsbakk.name; spf=pass smtp.mailfrom=khaugsbakk.name; dkim=pass (2048-bit key) header.d=khaugsbakk.name header.i=@khaugsbakk.name header.b=LZAUu5DX; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=q8iozXUY; arc=none smtp.client-ip=103.168.172.158 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=khaugsbakk.name Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=khaugsbakk.name Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=khaugsbakk.name header.i=@khaugsbakk.name header.b="LZAUu5DX"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="q8iozXUY" Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 8EF8611400C0; Tue, 13 Feb 2024 11:02:03 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Tue, 13 Feb 2024 11:02:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=khaugsbakk.name; 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=fm2; t=1707840123; x=1707926523; bh=dOzsJ8Wh+9lusbFV6e/lBsIiD4U3nOZc Nr/k4V87WHE=; b=LZAUu5DXp64ACvh3QGTdm9tV0JuOUp90BeF0SpqWoOtSuOgg 694j/zMPUTJN+dZm1Gz6z8rik+G7P0gy72tiY/R4pI2auosYvKZGy2O3/E7jFF12 +AN+DP8vSoJgNJyUDAC08joWAcPB9Uu265u5g0SMp0z3VKY+eNRiMyF1LjUN+43T JtYWac3PUxPZSOwXRhjLuIGjdCFkwPoHOb9fk/46G/FeATiUJZ3Bvt8JnFv9RTEE gan6+t+4soXx5hZdJHF8q7kCQ72ddHOCQ0ViQnit0FwCrUaDgvgLEBHED8MiDzsC qQnEBBi9cDKtWuU8II2xkK0GLYZ0o+ba8Vlzgg== 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-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1707840123; x= 1707926523; bh=dOzsJ8Wh+9lusbFV6e/lBsIiD4U3nOZcNr/k4V87WHE=; b=q 8iozXUY7CY5iquEnaKNzZQsu83HiiiTGm7yow1TJB6FW5nn4VFqq5FzdfNPc7ATK 2u4YGEVm5Xr/hPHV+HM4GCfUMRlckXNjQMrdu6QBP4FuyHT1mU7RScGEPrsXxZuD 54+JRIL2lDP2FjSmOkCgdmWO2VXdnFLFZ7HUFAES0dK72FXx0ojBQzW6Jo5t2H5F SDi6o/xIG+A1B/CIBU3IdVbXGOmaZjoOz1gXUgwD1RkmsgzDLMf9J209H7xo8hMN kL3FawWG8z+d2XGxuV52rC07K2zPj5LPBBbKsLA/GffgL+Uk/CwYY2OGneXWC534 CvQTz8p+ld/Tl8WBQm5oQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrudehgdekfecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvfevufffkffojghfgggtgfesthekredtredtjeenucfhrhhomhepmfhrihhs thhofhhfvghrucfjrghughhssggrkhhkuceotghouggvsehkhhgruhhgshgsrghkkhdrnh grmhgvqeenucggtffrrghtthgvrhhnpeevgfelveeikeegjeeikeeuvefhleeiuddvleeg feekjedtkeevtdetgfffveettdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmh epmhgrihhlfhhrohhmpegtohguvgeskhhhrghughhssggrkhhkrdhnrghmvg X-ME-Proxy: Feedback-ID: i2671468f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 13 Feb 2024 11:02:02 -0500 (EST) From: Kristoffer Haugsbakk To: git@vger.kernel.org Cc: Kristoffer Haugsbakk , Tiago Pascoal Subject: [PATCH v3 1/2] column: disallow negative padding Date: Tue, 13 Feb 2024 17:01:20 +0100 Message-ID: <4cac42ca6f8ade5e0200b9f16f1627f0796411d1.1707839454.git.code@khaugsbakk.name> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: <1c959378cf495d7a3d70d0c7bdf08cc501ed6e5d.1707679627.git.code@khaugsbakk.name> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 A negative padding does not make sense and can cause errors in the memory allocator since it’s interpreted as an unsigned integer. Reported-by: Tiago Pascoal Signed-off-by: Kristoffer Haugsbakk --- builtin/column.c | 2 ++ t/t9002-column.sh | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/builtin/column.c b/builtin/column.c index e80218f81f9..10ff7e01668 100644 --- a/builtin/column.c +++ b/builtin/column.c @@ -45,6 +45,8 @@ int cmd_column(int argc, const char **argv, const char *prefix) memset(&copts, 0, sizeof(copts)); copts.padding = 1; argc = parse_options(argc, argv, prefix, options, builtin_column_usage, 0); + if (copts.padding < 0) + die(_("%s must be non-negative"), "--padding"); if (argc) usage_with_options(builtin_column_usage, options); if (real_command || command) { diff --git a/t/t9002-column.sh b/t/t9002-column.sh index 348cc406582..d5b98e615bc 100755 --- a/t/t9002-column.sh +++ b/t/t9002-column.sh @@ -196,4 +196,15 @@ EOF test_cmp expected actual ' +test_expect_success 'padding must be non-negative' ' + cat >input <<\EOF && +1 2 3 4 5 6 +EOF + cat >expected <<\EOF && +fatal: --padding must be non-negative +EOF + test_must_fail git column --mode=column --padding=-1 actual 2>&1 && + test_cmp expected actual +' + test_done From patchwork Tue Feb 13 16:01:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Kristoffer Haugsbakk X-Patchwork-Id: 13555320 Received: from fout5-smtp.messagingengine.com (fout5-smtp.messagingengine.com [103.168.172.148]) (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 36ED65F846 for ; Tue, 13 Feb 2024 16:02:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.148 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707840128; cv=none; b=Dh6OU2/81RqsjBoZ4u+IcD2qftiH50VXPyrIFlDz+PAIlEatU9JP93le3mVKBHbwShu8TScnArweE3D9A5ej4xn+F/qFPGlYOt1xOC96vLQ5DhO5BL9AWc8n5GkvPGCEKzhdiaMnB6CugaBYjJEtB8KLQLVEpE/g2fB1NSlfsDk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707840128; c=relaxed/simple; bh=xoRQkpZn9O489wtevK19oNVKz26qmpPVkFyXnZ3ysNg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=VIWw5MtTJX9coPmd7l+8W7el8Ut4BgBx6xB/8QeLzja/2gBM0Mp06b/lfw+XtyGl41uJj8gDbp26Yk9wQy0n9lIRc28aubfnlaibxl/ouEVh06fqxF+FlcAWpQfJTuOPb3ALlpUQs0s9EKhEA32GN9fXXlyHSxy0rsnf1/6aEXU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=khaugsbakk.name; spf=pass smtp.mailfrom=khaugsbakk.name; dkim=pass (2048-bit key) header.d=khaugsbakk.name header.i=@khaugsbakk.name header.b=cgcp2kkD; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=gvjA/CLq; arc=none smtp.client-ip=103.168.172.148 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=khaugsbakk.name Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=khaugsbakk.name Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=khaugsbakk.name header.i=@khaugsbakk.name header.b="cgcp2kkD"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="gvjA/CLq" Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailfout.nyi.internal (Postfix) with ESMTP id 7FB2813800B5; Tue, 13 Feb 2024 11:02:05 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute7.internal (MEProxy); Tue, 13 Feb 2024 11:02:05 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=khaugsbakk.name; 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=fm2; t=1707840125; x=1707926525; bh=N0d6g8aUFNm5pSLiq5R14Kb1uGfl4akU uhzG9KEOM24=; b=cgcp2kkD2vmP5OZz2JgTNmo/WDXzpMERMSE7uvZ7nFRT9+m0 K3TcpRRTFIsKg9O5/W7MDcjVZLNFOW/FVp3Ht4MM9oPZsQgCCJQv51dYMuuCOVyQ 6LF6VXFwrFO3T0lZdvjVgvIIz7f4L8PnjCTJ5+MhezPS47bjLT7YtwCOjUySFDwY LNID0asjki3SON7T2l8TzaalxXY417vQr+krW6sugdjMG7IEML2ufUk/1nG/O7Og sOEMEaZal9BCbPuuNrc5m1t0UxF6ilO/bYwbnl5CPyYXF5ERn9ryNmYnSTXN/pPq avh/8/KJNuGwXeWdtgCeYgvFg9josIp3cOmupw== 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-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1707840125; x= 1707926525; bh=N0d6g8aUFNm5pSLiq5R14Kb1uGfl4akUuhzG9KEOM24=; b=g vjA/CLq4J4fCPkbjygnPF7xvuvXJuR79+VlvHpYPh1FhZaJkQ2xa22FaYY64mNUk 58O3wphK7wgDIU2r1BSsqMUR8Lmu/Xz3LfxwqUG+/eIlUBWyU7uE1+D2L468IY5m fUk+V8VlU1+pkiPpTnLtk0zr65lF6ZkhwUIb10YeCuIwCTTQPtMws0CCDZVCnffP m3yksbdqM6ZUIHNjmaZsWOUPvsoSzRxhNrgQp6/jwWj+EyufUkETkpk0pCdFeLwA Xb2R/nra+9M7SL9TnzLVx92XsklvUivgQCV05W8CMxqEaahAOReCEFG7DdqQShpa 5ocYxPzJUr2fE7ckp8yTA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrudehgdekfecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvfevufffkffojghfgggtgfesthekredtredtjeenucfhrhhomhepmfhrihhs thhofhhfvghrucfjrghughhssggrkhhkuceotghouggvsehkhhgruhhgshgsrghkkhdrnh grmhgvqeenucggtffrrghtthgvrhhnpeevgfelveeikeegjeeikeeuvefhleeiuddvleeg feekjedtkeevtdetgfffveettdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmh epmhgrihhlfhhrohhmpegtohguvgeskhhhrghughhssggrkhhkrdhnrghmvg X-ME-Proxy: Feedback-ID: i2671468f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 13 Feb 2024 11:02:04 -0500 (EST) From: Kristoffer Haugsbakk To: git@vger.kernel.org Cc: Kristoffer Haugsbakk , =?utf-8?q?Rub=C3=A9n_Justo?= Subject: [PATCH v3 2/2] column: guard against negative padding Date: Tue, 13 Feb 2024 17:01:21 +0100 Message-ID: <9355fc98e3dac5768ecaf9e179be2f7a0e74d633.1707839454.git.code@khaugsbakk.name> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: <1c959378cf495d7a3d70d0c7bdf08cc501ed6e5d.1707679627.git.code@khaugsbakk.name> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Make sure that client code can’t pass in a negative padding by accident. Suggested-by: Rubén Justo Signed-off-by: Kristoffer Haugsbakk Signed-off-by: Rubén Justo --- Notes (series): Apparently these are the only publicly-visible functions that use this struct according to `column.h`. column.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/column.c b/column.c index ff2f0abf399..50bbccc92ee 100644 --- a/column.c +++ b/column.c @@ -182,6 +182,8 @@ void print_columns(const struct string_list *list, unsigned int colopts, { struct column_options nopts; + if (opts && (0 > opts->padding)) + BUG("padding must be non-negative"); if (!list->nr) return; assert((colopts & COL_ENABLE_MASK) != COL_AUTO); @@ -361,6 +363,8 @@ int run_column_filter(int colopts, const struct column_options *opts) { struct strvec *argv; + if (opts && (0 > opts->padding)) + BUG("padding must be non-negative"); if (fd_out != -1) return -1;