git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] stream_to_pack: xread does not guarantee to read all requested bytes

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 20, 2013, 18:52 UTC
Message-ID
<xmqq4nak6vpv.fsf@gitster.dls.corp.google.com>
In-Reply-To
<xmqqsiy476h4.fsf@gitster.dls.corp.google.com>
Junio C Hamano <gitster@pobox.com> writes:
> I wonder if there are more like this broken caller or xread and/or
> xwrite.
Here is a result of a quick audit (of 1.8.0.x codebase).

As xwrite() will not be splitting a single-byte request, the patch to cat-file is more or less a theoretical fix, but if writing the date string can fail in I/O error, writing a terminating LF after it can fail the same way, so we should be consistent.

Everybody supports the side-band tranfer these days, so the patches to receive-pack and upload-pack are also theoretical fixes, I think. Note that in the more recent codebase, safe_write() is gone and we use write_or_die() instead in upload-pack.

 builtin/cat-file.c     | 2 +-
 builtin/receive-pack.c | 2 +-
 upload-pack.c          | 5 -----
 3 files changed, 2 insertions(+), 7 deletions(-)
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index 00528dd..4beb4d8 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -63,7 +63,7 @@ static void pprint_tag(const unsigned char *sha1, const char *buf, unsigned long
 					tz = strtol(ep, NULL, 10);
 					sp = show_date(date, tz, 0);
 					write_or_die(1, sp, strlen(sp));
-					xwrite(1, "\n", 1);
+					write_or_die(1, "\n", 1);
 					break;
 				}
 			}
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index ff781fe..a41740d 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -202,7 +202,7 @@ static void report_message(const char *prefix, const char *err, va_list params)
 	if (use_sideband)
 		send_sideband(1, 2, msg, sz, use_sideband);
 	else
-		xwrite(2, msg, sz);
+		write_in_full(2, msg, sz);
 }
 
 static void rp_warning(const char *err, ...)
diff --git a/upload-pack.c b/upload-pack.c
index 2e90ccb..7a3e4fd 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -64,11 +64,6 @@ static ssize_t send_client_data(int fd, const char *data, ssize_t sz)
 	if (fd == 3)
 		/* emergency quit */
 		fd = 2;
-	if (fd == 2) {
-		/* XXX: are we happy to lose stuff here? */
-		xwrite(fd, data, sz);
-		return sz;
-	}
 	return safe_write(fd, data, sz);
 }
 
Previous: Johannes SixtNext: Johannes Sixt
Message 7 of 8 in “stream_to_pack: xread does not guarantee to read all requested bytes”
  1. stream_to_pack: xread does not guarantee to read all requested bytesJohannes Sixt, Aug 20, 2013
  2. Junio C HamanoAug 20, 2013
  3. Antoine PelisseAug 20, 2013
  4. Junio C HamanoAug 20, 2013
  5. Johannes SixtAug 20, 2013
  6. Johannes SixtAug 20, 2013
  7. Junio C HamanoAug 20, 2013
  8. Johannes SixtAug 20, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.