git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [Patch v2 0/2] Replace strbuf_write_fd with write_in_full
       [not found] <20200619202320.4619-1-randall.s.becker.ref@rogers.com>
@ 2020-06-19 20:23 ` randall.s.becker
  2020-06-19 20:23   ` [Patch v2 1/2] bugreport.c: replace " randall.s.becker
                     ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: randall.s.becker @ 2020-06-19 20:23 UTC (permalink / raw)
  To: git; +Cc: Randall S. Becker

From: "Randall S. Becker" <randall.becker@nexbridge.ca>

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(-)

-- 
2.21.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Patch v2 1/2] bugreport.c: replace strbuf_write_fd with write_in_full
  2020-06-19 20:23 ` [Patch v2 0/2] Replace strbuf_write_fd with write_in_full randall.s.becker
@ 2020-06-19 20:23   ` randall.s.becker
  2020-06-19 20:23   ` [Patch v2 2/2] strbuf: remove unreferenced strbuf_write_fd method randall.s.becker
  2020-06-19 20:51   ` [Patch v2 0/2] Replace strbuf_write_fd with write_in_full Junio C Hamano
  2 siblings, 0 replies; 4+ messages in thread
From: randall.s.becker @ 2020-06-19 20:23 UTC (permalink / raw)
  To: git; +Cc: Randall S. Becker, Randall S . Becker

From: "Randall S. Becker" <randall.becker@nexbridge.ca>

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 <rsbecker@nexbridge.com>
---
 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);
 
 	/*
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [Patch v2 2/2] strbuf: remove unreferenced strbuf_write_fd method.
  2020-06-19 20:23 ` [Patch v2 0/2] Replace strbuf_write_fd with write_in_full randall.s.becker
  2020-06-19 20:23   ` [Patch v2 1/2] bugreport.c: replace " randall.s.becker
@ 2020-06-19 20:23   ` randall.s.becker
  2020-06-19 20:51   ` [Patch v2 0/2] Replace strbuf_write_fd with write_in_full Junio C Hamano
  2 siblings, 0 replies; 4+ messages in thread
From: randall.s.becker @ 2020-06-19 20:23 UTC (permalink / raw)
  To: git; +Cc: Randall S. Becker, Randall S . Becker

From: "Randall S. Becker" <randall.becker@nexbridge.ca>

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 <rsbecker@nexbridge.com>
---
 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
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [Patch v2 0/2] Replace strbuf_write_fd with write_in_full
  2020-06-19 20:23 ` [Patch v2 0/2] Replace strbuf_write_fd with write_in_full randall.s.becker
  2020-06-19 20:23   ` [Patch v2 1/2] bugreport.c: replace " randall.s.becker
  2020-06-19 20:23   ` [Patch v2 2/2] strbuf: remove unreferenced strbuf_write_fd method randall.s.becker
@ 2020-06-19 20:51   ` Junio C Hamano
  2 siblings, 0 replies; 4+ messages in thread
From: Junio C Hamano @ 2020-06-19 20:51 UTC (permalink / raw)
  To: randall.s.becker; +Cc: git, Randall S. Becker

randall.s.becker@rogers.com writes:

> From: "Randall S. Becker" <randall.becker@nexbridge.ca>
>
> 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.

Excellent.  Thanks.

Will queue.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-06-19 20:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20200619202320.4619-1-randall.s.becker.ref@rogers.com>
2020-06-19 20:23 ` [Patch v2 0/2] Replace strbuf_write_fd with write_in_full randall.s.becker
2020-06-19 20:23   ` [Patch v2 1/2] bugreport.c: replace " randall.s.becker
2020-06-19 20:23   ` [Patch v2 2/2] strbuf: remove unreferenced strbuf_write_fd method randall.s.becker
2020-06-19 20:51   ` [Patch v2 0/2] Replace strbuf_write_fd with write_in_full Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).