diff options
Diffstat (limited to 'pkt-line.c')
-rw-r--r-- | pkt-line.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/pkt-line.c b/pkt-line.c index 62b4208b66..af83a19f4d 100644 --- a/pkt-line.c +++ b/pkt-line.c @@ -5,7 +5,6 @@ #include "hex.h" #include "run-command.h" #include "trace.h" -#include "wrapper.h" #include "write-or-die.h" char packet_buffer[LARGE_PACKET_MAX]; @@ -373,10 +372,14 @@ static int get_packet_data(int fd, char **src_buf, size_t *src_size, return ret; } -int packet_length(const char lenbuf_hex[4]) +int packet_length(const char lenbuf_hex[4], size_t size) { - int val = hex2chr(lenbuf_hex); - return (val < 0) ? val : (val << 8) | hex2chr(lenbuf_hex + 2); + if (size < 4) + BUG("buffer too small"); + return hexval(lenbuf_hex[0]) << 12 | + hexval(lenbuf_hex[1]) << 8 | + hexval(lenbuf_hex[2]) << 4 | + hexval(lenbuf_hex[3]); } static char *find_packfile_uri_path(const char *buffer) @@ -419,7 +422,7 @@ enum packet_read_status packet_read_with_status(int fd, char **src_buffer, return PACKET_READ_EOF; } - len = packet_length(linelen); + len = packet_length(linelen, sizeof(linelen)); if (len < 0) { if (options & PACKET_READ_GENTLE_ON_READ_ERROR) |