Skip to content

Commit f48ecd3

Browse files
peffgitster
authored andcommitted
read_pack_header: handle signed/unsigned comparison in read result
The result of read_in_full() may be -1 if we saw an error. But in comparing it to a sizeof() result, that "-1" will be promoted to size_t. In fact, the largest possible size_t which is much bigger than our struct size. This means that our "< sizeof(header)" error check won't trigger. In practice, we'd go on to read uninitialized memory and compare it to the PACK signature, which is likely to fail. But we shouldn't get there. We can fix this by making a direct "!=" comparison to the requested size, rather than "<". This means that errors get lumped in with short reads, but that's sufficient for our purposes here. There's no PH_ERROR tp represent our case. And anyway, this function reads from pipes and network sockets. A network error may racily appear as EOF to us anyway if there's data left in the socket buffers. Signed-off-by: Jeff King <[email protected]> Reviewed-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d9bd4cb commit f48ecd3

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

sha1_file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3722,7 +3722,7 @@ int index_path(unsigned char *sha1, const char *path, struct stat *st, unsigned
37223722

37233723
int read_pack_header(int fd, struct pack_header *header)
37243724
{
3725-
if (read_in_full(fd, header, sizeof(*header)) < sizeof(*header))
3725+
if (read_in_full(fd, header, sizeof(*header)) != sizeof(*header))
37263726
/* "eof before pack header was fully read" */
37273727
return PH_ERROR_EOF;
37283728

0 commit comments

Comments
 (0)