[RFC PATCH v4 03/26] pkt-line: Make packet_read_line easier to debug
- From
Shawn O. Pearce <spearce@spearce.org>
- Date
- Oct 29, 2009, 00:00 UTC
- Message-ID
- <1256774448-7625-4-git-send-email-spearce@spearce.org>
- In-Reply-To
- <1256774448-7625-1-git-send-email-spearce@spearce.org>
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 <spearce@spearce.org> --- pkt-line.c | 8 +++++--- 1 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/pkt-line.c b/pkt-line.c index bd603f8..893dd3c 100644 --- a/pkt-line.c +++ b/pkt-line.c @@ -124,12 +124,14 @@ static int packet_length(const char *linelen) int packet_read_line(int fd, char *buffer, unsigned size) { int len; - char linelen[4]; + char linelen[5]; safe_read(fd, linelen, 4); len = packet_length(linelen); - if (len < 0) - die("protocol error: bad line length character"); + if (len < 0) { + linelen[4] = '\0'; + die("protocol error: bad line length character: %s", linelen); + } if (!len) return 0; len -= 4;
-- 1.6.5.2.181.gd6f41