Thread (36 messages) flat view 36 messages, 8 authors, 2016-06-15
STALE3734d

Revision v2 of 5 in this series.

Revisions (5)
  1. rfc [diff vs current]
  2. v2 current
  3. v3 [diff vs current]
  4. v4 [diff vs current]
  5. v5 [diff vs current]

[RFC PATCH v2 02/16] pkt-line: Make packet_read_line easier to debug

From: Shawn O. Pearce <hidden>
Date: 2016-06-15 22:47:32
Subsystem: the rest · Maintainer: Linus Torvalds

When there is an error parsing the 4 byte length component we now
NUL terminate the string and display it as part of the die message,
this may hint as to what data was misunderstood by the application.

Signed-off-by: Shawn O. Pearce <redacted>
---
 pkt-line.c |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/pkt-line.c b/pkt-line.c
index 2333d96..350f173 100644
--- a/pkt-line.c
+++ b/pkt-line.c
@@ -125,11 +125,13 @@ static int packet_length(unsigned *ret_len, const char *linelen)
 int packet_read_line(int fd, char *buffer, unsigned size)
 {
 	unsigned len;
-	char linelen[4];
+	char linelen[5];
 
 	safe_read(fd, linelen, 4);
-	if (packet_length(&len, linelen))
-		die("protocol error: bad line length character");
+	if (packet_length(&len, linelen)) {
+		linelen[4] = '\0';
+		die("protocol error: bad line length character: %s", linelen);
+	}
 	if (!len)
 		return 0;
 	len -= 4;
-- 
1.6.5.52.g0ff2e
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help