diff options
author | René Scharfe <l.s.r@web.de> | 2023-07-08 00:47:55 +0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2023-07-08 01:30:16 +0300 |
commit | 3e81b896f769dfdb479363acb00bdc6b076cfd55 (patch) | |
tree | 97313f778c6f5c790f27df7f467a3c2a6c50a209 /pkt-line.h | |
parent | fb7d80edcae482f4fa5d4be0227dc3054734e5f3 (diff) |
pkt-line: add size parameter to packet_length()
hex2chr() takes care not to run over the end of a NUL-terminated string.
It's used in packet_length(), but both callers of that function pass a
four-byte buffer, making NUL-checks unnecessary. packet_length() could
accidentally be used with a pointer to a buffer of unknown size at new
call-sites, though, and the compiler wouldn't complain.
Add a size parameter plus check, and remove the NUL-checks by calling
hexval() directly. This trades three NUL checks against one size check
and the ability to report the use of a short buffer at runtime.
If any of the four bytes is NUL or -- more generally -- not a
hexadecimal digit, then packet_length() still returns a negative value.
Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'pkt-line.h')
-rw-r--r-- | pkt-line.h | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/pkt-line.h b/pkt-line.h index 7c23a4bfaf..954eec8719 100644 --- a/pkt-line.h +++ b/pkt-line.h @@ -94,7 +94,7 @@ int packet_read(int fd, char *buffer, unsigned size, int options); * If lenbuf_hex contains non-hex characters, return -1. Otherwise, return the * numeric value of the length header. */ -int packet_length(const char lenbuf_hex[4]); +int packet_length(const char lenbuf_hex[4], size_t size); /* * Read a packetized line into a buffer like the 'packet_read()' function but |