From patchwork Fri Jun 19 20:23:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Randall S. Becker" X-Patchwork-Id: 11615025 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 71365912 for ; Fri, 19 Jun 2020 20:23:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 582C020890 for ; Fri, 19 Jun 2020 20:23:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=rogers.com header.i=@rogers.com header.b="Ux8QzaAy" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2392049AbgFSUXm (ORCPT ); Fri, 19 Jun 2020 16:23:42 -0400 Received: from sonic311-19.consmr.mail.bf2.yahoo.com ([74.6.131.193]:36494 "EHLO sonic311-19.consmr.mail.bf2.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391809AbgFSUXk (ORCPT ); Fri, 19 Jun 2020 16:23:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rogers.com; s=s2048; t=1592598219; bh=v3IyZAxmMC7FyOpAfrXilkZ5nd0THSrVlOHbwxPN0Rs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=Ux8QzaAyysKB3JP3rPO94tociDHPN/2QF5v1trIqWnHvbkoK2tupES/9vGyKLNgQ38IgN++FIFIZb3TpraoRVjiO0EDPYQCWYsmxyH/sXLhta8KIspEk6kxaZ85vX77f5Ex73aTylWyD30RU+YP9/S6rD9JqGOtPg3dKTpsn7sXdgmMwrF9xawNImwG2OpV5F+f1I+UKfGpo7cO4cgmbjblAxV5OIOGhcw+7QJPbPb1rTF3Om9r5EZ0+zGDd5bvvbsU7qbQ+xn6Xv0qbKOxaTaUKRfzZ6XDPQZkREgBW6+rjsdeOwb6WqiRiR2JKM6VJgkwMePafB70Lp9A6F3x3ZQ== X-YMail-OSG: j1ANJMQVM1mEgV8lcSslagBOZepsjMxQLHiwBmHTUhyV2gJlgk.Y3DnrgRMo05t 3eG3JifFVjug5iTNfv528W0yiHlsxtnAkupA7I5WuIO9aD44PhkxnvRESBqNwFXaYg16GUnQZgzN Y0.RuS249SHyI5sp8Xesz9gG7rjBB1_30sraEXRq68AzwtUzlur.rAW6Pl0IKr6QHBI5X_t6x_FU Qy3fIeT22xklYPym2rPoUh0GQAFAPXn8gvjLm7PBKRf8PBpJtJ4NjnN6yOTit9AC2zVYH.ERPBaa AKrckrZUuTYE8j7wPAuMeqDR5AvkhpvJWJEftOgzbYrmTC0io0Ux1wCALU7xJYIhzEDwCdfuSPFf T6GBYAYBQKS6T9INOozHnDWUuyCN4r4NwJ_Y15S1eP4e4IcIGI7o_zLtbU49grO.lKsqH_eAJVCm MRhyVXZgLXV6cM3fWsA6JX35.zsK18XV_dr37gAojK_6Gb7ishpgC1ASVu4nV4ALslBmJFG8AvHc snacv3_apUo2TiUQTkLA_ctVeSGVlsL8t7105evS0geb13mu606aU2FkEO5UNSRdp7B4stuKhMSF w1jYE.fh.Nvq38gHwH4ARx47vpB7vsBag33S6YF3bGMr_UagjobGNyo8BQ2NJHq3XizCVWnaEV8j kGD7_pHwghEGg3cIQi6syxurBzdVt1oaw_vkwWNyuiirzVMNY1JbqlBHKgwxBBFeZ.jja_2E0JyJ nNfEpQaegI7TZFnpnDOi4tkuTYQpbNJ61Vaeq93XI0QSbF7yN.Kt4c5HkYJ5w.WezqDH35uyev1l zcANfhx8ypYwvc19jHngYNUSnDCoY.LGbo.3jbPFXOPFuSy4zIV6_KxS.9s52n5X0KoX7ULvO31a W8kb2z8CibKjhrlXuZyU038HuLIeA_z0XFpWJlD9LXwEArEL7Tx.cww5f0CGb Received: from sonic.gate.mail.ne1.yahoo.com by sonic311.consmr.mail.bf2.yahoo.com with HTTP; Fri, 19 Jun 2020 20:23:39 +0000 Received: by smtp409.mail.bf1.yahoo.com (VZM Hermes SMTP Server) with ESMTPA ID f9cdc319e6c5c02f6098bff69147f340; Fri, 19 Jun 2020 20:23:35 +0000 (UTC) From: randall.s.becker@rogers.com To: git@vger.kernel.org Cc: "Randall S. Becker" , "Randall S . Becker" Subject: [Patch v2 1/2] bugreport.c: replace strbuf_write_fd with write_in_full Date: Fri, 19 Jun 2020 16:23:19 -0400 Message-Id: <20200619202320.4619-2-randall.s.becker@rogers.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200619202320.4619-1-randall.s.becker@rogers.com> References: <20200619202320.4619-1-randall.s.becker@rogers.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: "Randall S. Becker" The strbuf_write_fd method did not provide checks for buffers larger than MAX_IO_SIZE. Replacing with write_in_full ensures the entire buffer will always be written to disk or report an error and die. Signed-off-by: Randall S. Becker --- bugreport.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bugreport.c b/bugreport.c index aa8a489c35..1aefa4c6bc 100644 --- a/bugreport.c +++ b/bugreport.c @@ -174,7 +174,9 @@ int cmd_main(int argc, const char **argv) die(_("couldn't create a new file at '%s'"), report_path.buf); } - strbuf_write_fd(&buffer, report); + if (write_in_full(report, buffer.buf, buffer.len) < 0) + die_errno(_("unable to write to %s"), report_path.buf); + close(report); /* From patchwork Fri Jun 19 20:23:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Randall S. Becker" X-Patchwork-Id: 11615027 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 DE5F314B7 for ; Fri, 19 Jun 2020 20:23:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C88C1214D8 for ; Fri, 19 Jun 2020 20:23:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=rogers.com header.i=@rogers.com header.b="gcAC+QZd" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2392022AbgFSUXl (ORCPT ); Fri, 19 Jun 2020 16:23:41 -0400 Received: from sonic311-19.consmr.mail.bf2.yahoo.com ([74.6.131.193]:37668 "EHLO sonic311-19.consmr.mail.bf2.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391863AbgFSUXk (ORCPT ); Fri, 19 Jun 2020 16:23:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rogers.com; s=s2048; t=1592598218; bh=5mala9jDUgOnEzAGbKMLLm4X7ae8L3df5v5mCgU8aNk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=gcAC+QZdM9sYkH35AXlUNSyZltTitAHpmZK08+XmZbD94k0IoDy0rU0bqp2aiTeSelqVQOxKOlW01o13K+o+HUvUEu/rJincRO1Sp7NfX8dUT6bePVF9ERkhYzvZuZVkcPZGoxSATowVAXZVZUoI5oU62C5HtrzEtVhvKKLZGY/imfFkMtulcr6KVZdwNEOYugFIwmgcF9Ethbfce4ZXj2wcJsqfuCZPLrwlc2kXglNEpRWzTaXS+b1TztWMcseggQN0eGN+GX6p6LZVIgiQfk1f/ZEHQCG3g/Yfqk6B8h5PDwR2TP32EN5bnAr2QD9t/dL6mEL4ZZ92ryjKeuO2YA== X-YMail-OSG: wZ.1ArwVM1loBJ2AxnGmxiCYE27nHJqzOYI1XY4FMXHuDSTgNm0IxZltuWHpX_y qSx_7a3QTrYk8xrSViofw8uP8L71e0svnSPUig.nVruIQfE7O77pZJppel.Kx8hPk56U3nmDPALv CmB5eHFfSp92Phbl2oXDbcv.DaLkCz8rQfi6jJITJ32dMFpU9S9Gkd0dj_7hAJDKqm_4DUMesf5G 2tiIxXecb77N9Hsb6z0ouLnwBetasxxn5yh_7ynJwAH55Tw02bX3kMIAou1fyKLRKOxz.TRLZ6.E m5huG7UcQQffnY9JG45xIES5vRkeGNZrYmlopvIhHtVHGXR9aoQWSldxikzrUKQCfG9QGcfSObZZ s4i5.KoqCHrLoVCMgPmQqO6o5tMT_vDF4cpxLsf.4Dp4okWU_M.6W.eP72ncvdqp_3d7vTtER_vu Q_OoBB2FUPDJxOtlJbj9Ar3KZukZDC6RqmnmeR_eHj0nIe.Mrrz4Fl0CfNvLip_1nbIt1NF17K.A oLEP1ZCtVlqNtUKfAL9T4VmxN9iT4WqFsg_ilHjuyRgT9ZLfX4ch.vH26RdMas5DKQyrY6GuaXO8 DiCMk6o_9eflFHHeToT9T2eSL2K5XaXD5B2OvpaSYAoyCGFXW3uhWioqD700HG.OTnF2IYvhvrBH liweSyKKzOA.OYKdTrURAdpUKxXguBt0YGLAV4dpsgQzQEsWmndDk3Flqo7a9fgl528lmyMT6qNt hUvK7BcPSCqTtVuzwRHx4TvwUkh4S9yfw6cHLMp0sXbT.44IgaXRIhJ6FwOS2o0EkAUe_9hHZnbz Vlsqe5ztQOlK07IhrJ5z9AdZZYT8r543vr5j5FKPAR0qtAH3itMs3srIzIpwFcZ.psUsMOsJ1Nse Z9BYtSL8biFj6QEcS8ap0zZR73YD3vFhSleO9h_Q.78RCYww.9ACDte4RostS Received: from sonic.gate.mail.ne1.yahoo.com by sonic311.consmr.mail.bf2.yahoo.com with HTTP; Fri, 19 Jun 2020 20:23:38 +0000 Received: by smtp409.mail.bf1.yahoo.com (VZM Hermes SMTP Server) with ESMTPA ID f9cdc319e6c5c02f6098bff69147f340; Fri, 19 Jun 2020 20:23:36 +0000 (UTC) From: randall.s.becker@rogers.com To: git@vger.kernel.org Cc: "Randall S. Becker" , "Randall S . Becker" Subject: [Patch v2 2/2] strbuf: remove unreferenced strbuf_write_fd method. Date: Fri, 19 Jun 2020 16:23:20 -0400 Message-Id: <20200619202320.4619-3-randall.s.becker@rogers.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200619202320.4619-1-randall.s.becker@rogers.com> References: <20200619202320.4619-1-randall.s.becker@rogers.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: "Randall S. Becker" strbuf_write_fd was only used in bugreport.c. Since that file now uses write_in_full, this method is no longer needed. In addition, strbuf_write_fd did not guard against exceeding MAX_IO_SIZE for the platform, nor provided error handling in the event of a failure if only partial data was written to the file descriptor. Since already write_in_full has this capability and is in general use, it should be used instead. The change impacts strbuf.c and strbuf.h. Signed-off-by: Randall S. Becker --- strbuf.c | 5 ----- strbuf.h | 1 - 2 files changed, 6 deletions(-) diff --git a/strbuf.c b/strbuf.c index 2f1a7d3209..e3397cc4c7 100644 --- a/strbuf.c +++ b/strbuf.c @@ -556,11 +556,6 @@ ssize_t strbuf_write(struct strbuf *sb, FILE *f) return sb->len ? fwrite(sb->buf, 1, sb->len, f) : 0; } -ssize_t strbuf_write_fd(struct strbuf *sb, int fd) -{ - return sb->len ? write(fd, sb->buf, sb->len) : 0; -} - #define STRBUF_MAXLINK (2*PATH_MAX) int strbuf_readlink(struct strbuf *sb, const char *path, size_t hint) diff --git a/strbuf.h b/strbuf.h index 7062eb6410..223ee2094a 100644 --- a/strbuf.h +++ b/strbuf.h @@ -473,7 +473,6 @@ int strbuf_readlink(struct strbuf *sb, const char *path, size_t hint); * NUL bytes. */ ssize_t strbuf_write(struct strbuf *sb, FILE *stream); -ssize_t strbuf_write_fd(struct strbuf *sb, int fd); /** * Read a line from a FILE *, overwriting the existing contents of