{"thread":{"id":"53721","subject":"[Patch v2 1/2] bugreport.c: replace strbuf_write_fd with write_in_full","startedAt":"2020-06-19T20:23:42Z","lastAt":"2020-06-19T20:51:47Z","messageCount":4,"participants":["randall.s.becker@rogers.com","Junio C Hamano"],"isPatch":true,"patchVersion":2,"patchTotal":2},"messages":[{"id":"400217","messageId":"20200619202320.4619-2-randall.s.becker@rogers.com","threadId":"53721","inReplyTo":"20200619202320.4619-1-randall.s.becker@rogers.com","subject":"[Patch v2 1/2] bugreport.c: replace strbuf_write_fd with write_in_full","fromName":"","fromEmail":"randall.s.becker@rogers.com","sentAt":"2020-06-19T20:23:19Z","receivedAt":"2020-06-19T20:23:42Z","isPatch":true,"sender":{"key":"randall.s.becker@rogers.com","avatar":null},"body":"From: \"Randall S. Becker\" <randall.becker@nexbridge.ca>\n\nThe strbuf_write_fd method did not provide checks for buffers larger\nthan MAX_IO_SIZE. Replacing with write_in_full ensures the entire\nbuffer will always be written to disk or report an error and die.\n\nSigned-off-by: Randall S. Becker <rsbecker@nexbridge.com>\n---\n bugreport.c | 4 +++-\n 1 file changed, 3 insertions(+), 1 deletion(-)\n\ndiff --git a/bugreport.c b/bugreport.c\nindex aa8a489c35..1aefa4c6bc 100644\n--- a/bugreport.c\n+++ b/bugreport.c\n@@ -174,7 +174,9 @@ int cmd_main(int argc, const char **argv)\n \t\tdie(_(\"couldn't create a new file at '%s'\"), report_path.buf);\n \t}\n \n-\tstrbuf_write_fd(&buffer, report);\n+\tif (write_in_full(report, buffer.buf, buffer.len) < 0)\n+\t\tdie_errno(_(\"unable to write to %s\"), report_path.buf);\n+\n \tclose(report);\n \n \t/*\n-- \n2.21.0\n\n"},{"id":"400218","messageId":"20200619202320.4619-1-randall.s.becker@rogers.com","threadId":"53721","inReplyTo":"20200619202320.4619-1-randall.s.becker.ref@rogers.com","subject":"[Patch v2 0/2] Replace strbuf_write_fd with write_in_full","fromName":"","fromEmail":"randall.s.becker@rogers.com","sentAt":"2020-06-19T20:23:18Z","receivedAt":"2020-06-19T20:23:45Z","isPatch":true,"sender":{"key":"randall.s.becker@rogers.com","avatar":null},"body":"From: \"Randall S. Becker\" <randall.becker@nexbridge.ca>\n\nThe strbuf_write_fd method does not check whether the buffer exceeds\nMAX_IO_SIZE on the target platform. This fix replaces the use of that\nmethod with write_in_full, which does. Since this is the only use of\nstrbuf_write_fd, and since the method was unsafe, it has been removed\nfrom strbuf.c and strbuf.h.\n\nRandall S. Becker (2):\n  bugreport.c: replace strbuf_write_fd with write_in_full\n  strbuf: remove unreferenced strbuf_write_fd method.\n\n bugreport.c | 4 +++-\n strbuf.c    | 5 -----\n strbuf.h    | 1 -\n 3 files changed, 3 insertions(+), 7 deletions(-)\n\n-- \n2.21.0\n\n"},{"id":"400219","messageId":"20200619202320.4619-3-randall.s.becker@rogers.com","threadId":"53721","inReplyTo":"20200619202320.4619-1-randall.s.becker@rogers.com","subject":"[Patch v2 2/2] strbuf: remove unreferenced strbuf_write_fd method.","fromName":"","fromEmail":"randall.s.becker@rogers.com","sentAt":"2020-06-19T20:23:20Z","receivedAt":"2020-06-19T20:23:45Z","isPatch":true,"sender":{"key":"randall.s.becker@rogers.com","avatar":null},"body":"From: \"Randall S. Becker\" <randall.becker@nexbridge.ca>\n\nstrbuf_write_fd was only used in bugreport.c. Since that file now uses\nwrite_in_full, this method is no longer needed. In addition, strbuf_write_fd\ndid not guard against exceeding MAX_IO_SIZE for the platform, nor\nprovided error handling in the event of a failure if only partial data\nwas written to the file descriptor. Since already write_in_full has this \ncapability and is in general use, it should be used instead. The change\nimpacts strbuf.c and strbuf.h.\n\nSigned-off-by: Randall S. Becker <rsbecker@nexbridge.com>\n---\n strbuf.c | 5 -----\n strbuf.h | 1 -\n 2 files changed, 6 deletions(-)\n\ndiff --git a/strbuf.c b/strbuf.c\nindex 2f1a7d3209..e3397cc4c7 100644\n--- a/strbuf.c\n+++ b/strbuf.c\n@@ -556,11 +556,6 @@ ssize_t strbuf_write(struct strbuf *sb, FILE *f)\n \treturn sb->len ? fwrite(sb->buf, 1, sb->len, f) : 0;\n }\n \n-ssize_t strbuf_write_fd(struct strbuf *sb, int fd)\n-{\n-\treturn sb->len ? write(fd, sb->buf, sb->len) : 0;\n-}\n-\n #define STRBUF_MAXLINK (2*PATH_MAX)\n \n int strbuf_readlink(struct strbuf *sb, const char *path, size_t hint)\ndiff --git a/strbuf.h b/strbuf.h\nindex 7062eb6410..223ee2094a 100644\n--- a/strbuf.h\n+++ b/strbuf.h\n@@ -473,7 +473,6 @@ int strbuf_readlink(struct strbuf *sb, const char *path, size_t hint);\n  * NUL bytes.\n  */\n ssize_t strbuf_write(struct strbuf *sb, FILE *stream);\n-ssize_t strbuf_write_fd(struct strbuf *sb, int fd);\n \n /**\n  * Read a line from a FILE *, overwriting the existing contents of\n-- \n2.21.0\n\n"},{"id":"400222","messageId":"xmqqo8peg4o4.fsf@gitster.c.googlers.com","threadId":"53721","inReplyTo":"20200619202320.4619-1-randall.s.becker@rogers.com","subject":"Re: [Patch v2 0/2] Replace strbuf_write_fd with write_in_full","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-06-19T20:51:39Z","receivedAt":"2020-06-19T20:51:47Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"randall.s.becker@rogers.com writes:\n\n> From: \"Randall S. Becker\" <randall.becker@nexbridge.ca>\n>\n> The strbuf_write_fd method does not check whether the buffer exceeds\n> MAX_IO_SIZE on the target platform. This fix replaces the use of that\n> method with write_in_full, which does. Since this is the only use of\n> strbuf_write_fd, and since the method was unsafe, it has been removed\n> from strbuf.c and strbuf.h.\n\nExcellent.  Thanks.\n\nWill queue.\n"}]}