From f64b6a1f750e65ca90435f714d9350493aad836d Mon Sep 17 00:00:00 2001 From: "Randall S. Becker" Date: Fri, 19 Jun 2020 16:23:19 -0400 Subject: [PATCH 1/2] bugreport.c: replace strbuf_write_fd with write_in_full 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 Signed-off-by: Junio C Hamano --- bugreport.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bugreport.c b/bugreport.c index acacca8fef..0cc71dcc6f 100644 --- a/bugreport.c +++ b/bugreport.c @@ -122,7 +122,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 5f2b643e76d9a1330c1a02489c0787ca7d818633 Mon Sep 17 00:00:00 2001 From: "Randall S. Becker" Date: Fri, 19 Jun 2020 16:23:20 -0400 Subject: [PATCH 2/2] strbuf: remove unreferenced strbuf_write_fd method. 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 Signed-off-by: Junio C Hamano --- strbuf.c | 5 ----- strbuf.h | 1 - 2 files changed, 6 deletions(-) diff --git a/strbuf.c b/strbuf.c index f1d66c7848..4bbaff2bda 100644 --- a/strbuf.c +++ b/strbuf.c @@ -539,11 +539,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 1eaa944a4f..bfa66569a4 100644 --- a/strbuf.h +++ b/strbuf.h @@ -450,7 +450,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