From patchwork Fri Jul 17 03:43:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Spooren X-Patchwork-Id: 1330718 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.openwrt.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=aparcar.org Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=merlin.20170209 header.b=x6lBV3mQ; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4B7H8g3Ph0z9sRk for ; Fri, 17 Jul 2020 13:45:55 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=b+1AlN0QUzDXW12dNOulr2P5QvLve2OunxC9FPzDQUM=; b=x6lBV3mQTEe63lGYB93+TBhG2I kiezG5Sr9bFyMvFUQIy4Xdv+o86fti1bUV9cLYr3wDlvx7XE1WYjIPBTXPb2kspnbVodcaRlnwkJD s8u0TutazJ97xhq8vM0JUQKQsTdLMwk4wvM7O8/F2L3IKz6J8rvnGrroptfOtz9xNl5DMqoe6Yt2K kaf1OAbLFPWeRmxFWVUDRPw8egPG7LciApyzLMqHjs+kaLFTQZSS7BspmRXpbUPsq9vPWhbyrRmTx ZzBm6EblIgOMWlslmP5E2g4KXWHutPoG5GQrcwrWct9NBp4HnR1dk6IYVzFfRHIGgx4S3W6xbx5jY T06xGXPg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jwHHs-0003QW-Nk; Fri, 17 Jul 2020 03:43:52 +0000 Received: from relay9-d.mail.gandi.net ([217.70.183.199]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jwHHo-0003Q5-Hv for openwrt-devel@lists.openwrt.org; Fri, 17 Jul 2020 03:43:49 +0000 X-Originating-IP: 72.234.141.215 Received: from dawn.lan (udp224251uds.hawaiiantel.net [72.234.141.215]) (Authenticated sender: mail@aparcar.org) by relay9-d.mail.gandi.net (Postfix) with ESMTPA id 37F0BFF803; Fri, 17 Jul 2020 03:43:42 +0000 (UTC) From: Paul Spooren To: openwrt-devel@lists.openwrt.org Subject: [PATCH 1/3] scripts: mkhash show -n option in usage Date: Thu, 16 Jul 2020 17:43:30 -1000 Message-Id: <20200717034332.3726979-1-mail@aparcar.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200716_234348_700793_BFE7D5A8 X-CRM114-Status: UNSURE ( 6.33 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -0.7 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at https://www.dnswl.org/, low trust [217.70.183.199 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [217.70.183.199 listed in wl.mailspike.net] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paul Spooren , nbd@nbd.name Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org The -n option prints the filename of hashed files next to the calculated checksum. Reflect that in the usage message. user@dawn:~/src/openwrt/openwrt$ ./a.out md5 -n .config eb06db36e7b6751cb18801945e46bf5d .config Signed-off-by: Paul Spooren --- scripts/mkhash.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/mkhash.c b/scripts/mkhash.c index 0f5815f242..e26ca3a350 100644 --- a/scripts/mkhash.c +++ b/scripts/mkhash.c @@ -736,7 +736,10 @@ static int usage(const char *progname) { int i; - fprintf(stderr, "Usage: %s [...]\n" + fprintf(stderr, "Usage: %s [options] [...]\n" + "Options:\n" + " -n Print filename(s)\n" + "\n" "Supported hash types:", progname); for (i = 0; i < ARRAY_SIZE(types); i++) From patchwork Fri Jul 17 03:43:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Spooren X-Patchwork-Id: 1330716 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.openwrt.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=aparcar.org Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=merlin.20170209 header.b=tdd38x8m; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4B7H8g2zx6z9sRW for ; Fri, 17 Jul 2020 13:45:54 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=vM1ux2zcoQoGvYH0d3vkP6NXjhDXjEQDC1gbTcx1d88=; b=tdd38x8mfO7pmdvzdOLwZNI1E KikDSnG+/V84dSIuYOFBmOonxfHHxbp79zU1L1gZHSqFRXG+8b+Yt4jMODE1TYceMzoGwkhsv1N9u x32DokE3Ha90XKcGOZgJR5lvRjygHIdwbpiUMP/3AWhfiURoO8q1e80wacDhS977THII7/Ir6Zyry BL4ZbPt3k5h4dJBBrLJvxvMqK2dGDIYNL5wKHdNjryu44n2XuStGU2+lLbcj1uLiT4Nmr0RwTuPZJ uFp5RWHia6VS5nPB1JuUe6/YEEbu4S/Ctv/C1a0PJzw0ECL1OXKYAuHgOm/3JbFWUfGfQL//cHOFZ xhx9O+VEg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jwHI0-0003RC-TO; Fri, 17 Jul 2020 03:44:00 +0000 Received: from relay9-d.mail.gandi.net ([217.70.183.199]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jwHHy-0003Qp-Cz for openwrt-devel@lists.openwrt.org; Fri, 17 Jul 2020 03:43:59 +0000 X-Originating-IP: 72.234.141.215 Received: from dawn.lan (udp224251uds.hawaiiantel.net [72.234.141.215]) (Authenticated sender: mail@aparcar.org) by relay9-d.mail.gandi.net (Postfix) with ESMTPA id 8286DFF804; Fri, 17 Jul 2020 03:43:55 +0000 (UTC) From: Paul Spooren To: openwrt-devel@lists.openwrt.org Subject: [PATCH 2/3] scripts: mkhash fix return code handling Date: Thu, 16 Jul 2020 17:43:31 -1000 Message-Id: <20200717034332.3726979-2-mail@aparcar.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200717034332.3726979-1-mail@aparcar.org> References: <20200717034332.3726979-1-mail@aparcar.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200716_234358_580552_94145772 X-CRM114-Status: UNSURE ( 8.04 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -0.7 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at https://www.dnswl.org/, low trust [217.70.183.199 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [217.70.183.199 listed in wl.mailspike.net] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paul Spooren , nbd@nbd.name Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org If hashing a file fails mkhash shouldn't just silently fail. Now check after each call of `hash_file()` the return and exit early in case of errors. The return value which was previously ignored and would always return 0. Signed-off-by: Paul Spooren --- scripts/mkhash.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/mkhash.c b/scripts/mkhash.c index e26ca3a350..96f92e42b5 100644 --- a/scripts/mkhash.c +++ b/scripts/mkhash.c @@ -797,7 +797,7 @@ int main(int argc, char **argv) { struct hash_type *t; const char *progname = argv[0]; - int i, ch; + int i, ch, hash_return; bool add_filename = false; while ((ch = getopt(argc, argv, "n")) != -1) { @@ -824,7 +824,8 @@ int main(int argc, char **argv) return hash_file(t, NULL, add_filename); for (i = 0; i < argc - 1; i++) - hash_file(t, argv[1 + i], add_filename); + if ((hash_return = hash_file(t, argv[1 + i], add_filename))) + return hash_return; return 0; } From patchwork Fri Jul 17 03:43:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Spooren X-Patchwork-Id: 1330717 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.openwrt.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=aparcar.org Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=merlin.20170209 header.b=g3r9uEvA; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4B7H8g2C4Qz9sRN for ; Fri, 17 Jul 2020 13:45:54 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=GZuzZrXgOlLAT893WmF9i/2ZMaR46DjuDb0n0m4DX94=; b=g3r9uEvAV8OKmrY1glcTDg1iv Tr1Sa1ABD8Cp8q5J28P3UuW5NzxhixhGQiJ8k7rpzYGuNHyF5oVnE5CDMRhdo6dhN3QMQGsxui1Br Jw/qrcidbYJS86XzeLkJRDmewlkYLCpk6nYbld9/Lv6JNt3vpmul7Tjgc+yyDkmCD9lJagrV/UByg juQ1dLCHXlNP6QJ9IOWXinvUujCpmv6XfIsYJn/vJSWk3unGLznEAt6cwk5QBIjy3aFMv2/q01jrI U/of4NaEr3kd5URMWom1m/9NzPGCDNNC6Rn2HzAF427ndYZgpqCe1Fv9f72BZqIut5nPKF55M7+yo hRgxD/jnA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jwHI5-0003Rk-FZ; Fri, 17 Jul 2020 03:44:05 +0000 Received: from relay9-d.mail.gandi.net ([217.70.183.199]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jwHI2-0003RS-UE for openwrt-devel@lists.openwrt.org; Fri, 17 Jul 2020 03:44:03 +0000 X-Originating-IP: 72.234.141.215 Received: from dawn.lan (udp224251uds.hawaiiantel.net [72.234.141.215]) (Authenticated sender: mail@aparcar.org) by relay9-d.mail.gandi.net (Postfix) with ESMTPA id 5E00EFF804; Fri, 17 Jul 2020 03:44:00 +0000 (UTC) From: Paul Spooren To: openwrt-devel@lists.openwrt.org Subject: [PATCH 3/3] scripts: mkhash fail on hashing a folder Date: Thu, 16 Jul 2020 17:43:32 -1000 Message-Id: <20200717034332.3726979-3-mail@aparcar.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200717034332.3726979-1-mail@aparcar.org> References: <20200717034332.3726979-1-mail@aparcar.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200716_234403_106513_BEE6CE7E X-CRM114-Status: UNSURE ( 9.80 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -0.7 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at https://www.dnswl.org/, low trust [217.70.183.199 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [217.70.183.199 listed in wl.mailspike.net] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paul Spooren , nbd@nbd.name Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org mkhash currently returns the hash of an empty input when trying to hash a folder. This can be missleading in caseswhere e.g. an env variable is undefined which should contain a filename. `mkhash ./path/to/$FILE` would exit with code 0 and return a legit looking checksum. A better behaviour would be to fail with exit code 1, which imitates the behaviour of `md5sum` and `sha256sum`. To avoid hashing of folders `fopen()` is called in `r+` mode which fails on folders, as their are not writeable. Regular files work as before. Hashing empty inputs result in the following checksums: md5: d41d8cd98f00b204e9800998ecf8427e sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 Signed-off-by: Paul Spooren --- scripts/mkhash.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/mkhash.c b/scripts/mkhash.c index 96f92e42b5..4d1ff1c166 100644 --- a/scripts/mkhash.c +++ b/scripts/mkhash.c @@ -770,7 +770,7 @@ static int hash_file(struct hash_type *t, const char *filename, bool add_filenam if (!filename || !strcmp(filename, "-")) { str = t->func(stdin); } else { - FILE *f = fopen(filename, "r"); + FILE *f = fopen(filename, "r+"); if (!f) { fprintf(stderr, "Failed to open '%s'\n", filename);