pkt-line: fix packet_read_line() to handle len < 0 errors
authorBen Peart <peartben@gmail.com>
Fri, 5 May 2017 15:27:54 +0000 (11:27 -0400)
committerJunio C Hamano <gitster@pobox.com>
Mon, 8 May 2017 01:57:26 +0000 (10:57 +0900)
Update packet_read_line() to test for len > 0 to avoid potential bug
if read functions return lengths less than zero to indicate errors.

Signed-off-by: Ben Peart <benpeart@microsoft.com>
Found/Fixed-by: Lars Schneider <larsxschneider@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
pkt-line.c
index d4b6bfe076341d64bb948e4932655b927a369bc0..6f05b1a4a8bea31686f50ea906987a701148f166 100644 (file)
@@ -315,7 +315,7 @@ static char *packet_read_line_generic(int fd,
                              PACKET_READ_CHOMP_NEWLINE);
        if (dst_len)
                *dst_len = len;
-       return len ? packet_buffer : NULL;
+       return (len > 0) ? packet_buffer : NULL;
 }
 
 char *packet_read_line(int fd, int *len_p)