Welcome, Guest.
Please login or register.
Buffer overflow in zipinfo.c
Forum Login
Login Name: Create a new account
Password:     Forgot password

Info-ZIP Discussion Forum    Info-ZIP Bugs    UnZip Bugs  ›  Buffer overflow in zipinfo.c

Buffer overflow in zipinfo.c  This thread currently has 895 views. Print
1 Pages 1 Recommend Thread
kklic
November 30, 2009, 10:13am Report to Moderator
Baby Member
Posts: 3
Hello,
There is a possible 1-byte overflow in zipinfo.c (both unzip 6.0 and unzip 5.52).
In function  zi_short(__G), the variable hostver is in range 0-255. There is a sprintf call in that function, that uses attribs[16] array to create a string:

sprintf(attribs, ".r.-...     %u.%u", hostver/10, hostver%10);

If hostver >= 100, hostver/10 uses 2 characters, and attribs[16] is not large enough.
There are multiple calls of sprintf(&attribs[12], "%u.%u", hostver/10, hostver%10); in the same function that are also affected.

Increasing the size of attribs by 1 is a sufficient fix.
Please see https://bugzilla.redhat.com/show_bug.cgi?id=532380 for more information and a test file.



Attachment: 0attribsoverflow_4819.patch
473 downloads   -   Size: 0.62 KB

Logged
Private Message
sms
November 30, 2009, 5:49pm Report to Moderator
Info-ZIP Team
Posts: 463
> Increasing the size of attribs by 1 is a sufficient fix.

   That depends on your definition of "sufficient".  It might be, if
your _only_ goal is preventing this particular array bounds overrun, and
you don't care what happens to the report format, or the other code
which thinks that it knows the size of attribs[] (like, for example, the
piece which NUL-terminates the thing: "attribs[15] = 0;").  It might do
less damage to enforce the current assumption that hostver < 100.  For
example, change:
    hostver = (unsigned)(G.pInfo->hostver);
to:
    hostver = MIN( 99, (unsigned)(G.pInfo->hostver));
(in two places), which would seem to me to solve the problem without
wrecking all the other code which deals with attribs[].
Logged
Private Message Reply: 1 - 4
kklic
December 7, 2009, 9:17am Report to Moderator
Baby Member
Posts: 3
Hi sms,
I see, hostver = MIN( 99, (unsigned)(G.pInfo->hostver)); is certainly better solution.
Thanks.
Logged
Private Message Reply: 2 - 4
sms
December 20, 2009, 8:19pm Report to Moderator
Info-ZIP Team
Posts: 463
> [...] is certainly better solution.

   So, which fix got pushed back into the code?
Logged
Private Message Reply: 3 - 4
kklic
December 21, 2009, 12:55pm Report to Moderator
Baby Member
Posts: 3
I assume the question is directed to unzip's maintainer.
The former fix is currently used in Fedora, as it was already in place.

I also have been thinking about enforcing the G.pInfo->hostver < 100 when it is loaded in process_cdir_file_hdr() (file process.c), with a warning message. That would make the assumption fulfilled for the whole unzip.
Logged
Private Message Reply: 4 - 4
1 Pages 1 Recommend Thread
Print

Info-ZIP Discussion Forum    Info-ZIP Bugs    UnZip Bugs  ›  Buffer overflow in zipinfo.c