bugreport.c: replace strbuf_write_fd with write_in_full
A message that is not in the archive (sent off-list or not yet received): [email protected]
v2 cover Replace strbuf_write_fd with write_in_full
From: "Randall S. Becker" <[email protected]>
The strbuf_write_fd method does not check whether the buffer exceeds MAX_IO_SIZE on the target platform. This fix replaces the use of that method with write_in_full, which does. Since this is the only use of strbuf_write_fd, and since the method was unsafe, it has been removed from strbuf.c and strbuf.h.
Randall S. Becker (2):
bugreport.c: replace strbuf_write_fd with write_in_full
strbuf: remove unreferenced strbuf_write_fd method.
bugreport.c | 4 +++- strbuf.c | 5 ----- strbuf.h | 1 - 3 files changed, 3 insertions(+), 7 deletions(-)
Signature · 1 line
2.21.0
PATCH v2 1/2 bugreport.c: replace strbuf_write_fd with write_in_full
From: "Randall S. Becker" <[email protected]>
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.
--- bugreport.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
bugreport.c +3 -1
@@ -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);/*
Signature · 1 line
2.21.0
PATCH v2 2/2 strbuf: remove unreferenced strbuf_write_fd method.
In reply to [email protected]From: "Randall S. Becker" <[email protected]>
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.
--- strbuf.c | 5 ----- strbuf.h | 1 - 2 files changed, 6 deletions(-)
strbuf.c +0 -5
@@ -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)
strbuf.h +0 -1
@@ -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
Signature · 1 line
2.21.0
Re: [Patch v2 0/2] Replace strbuf_write_fd with write_in_full
In reply to [email protected]Quoted 7 lines · [email protected] writes:
From: "Randall S. Becker" <[email protected]>
The
strbuf_write_fdmethod does not check whether the buffer exceedsMAX_IO_SIZEon the target platform. This fix replaces the use of that method withwrite_in_full, which does. Since this is the only use ofstrbuf_write_fd, and since the method was unsafe, it has been removed fromstrbuf.candstrbuf.h.
Excellent. Thanks.
Will queue.