]> granicus.if.org Git - check/commit
Fix segfault when memmoving with negative/enormous n
authorJan Pokorný <jpokorny@redhat.com>
Tue, 1 Mar 2016 17:41:58 +0000 (18:41 +0100)
committerJan Pokorný <jpokorny@redhat.com>
Tue, 1 Mar 2016 19:30:01 +0000 (20:30 +0100)
commit25a87067860e0cb14ceb1066564aeac0b64ee789
treee0a1362e0c8f6d39d2ec9b852119d708999ca549
parent766ab2c9a7c18ca2faff5dd5b95b3598efd3aa65
Fix segfault when memmoving with negative/enormous n

I observed a segmentation fault caused by trying to memmove by -15,
which makes 18446744073709551601 on my 64-bit platform after an argument
type promotion (from int into size_t).  In my case, this was connected
with filling up disk during the test facilitated by check, hence I derive
that the main issue was that not enough bytes for particular type of
message was actually read (and previously written, for that matter) and
because of this incompleteness, get_result happily consumed more bytes
than was read.

Additional debugging info at the point of segfault (src/check_pack.c):

> 468│         /* Move remaining data in buffer to the beginning */
> 469├>        memmove(buf, buf + n, nparse);
> 470│         /* If EOF has not been seen */
> 471│         if(nread > 0)
>
> (gdb) p nparse
> $1 = -15
> (gdb) p n
> $2 = 23
> (gdb) p nread
> $3 = 0
src/check_pack.c