BusyBox Bug and Patch Tracking
BusyBox
  

Viewing Issue Simple Details Jump to Notes ] View Advanced ] Issue History ] Print ]
ID Category Severity Reproducibility Date Submitted Last Update
0004104 [BusyBox] Other major always 07-14-08 19:19 07-16-08 16:17
Reporter cristic View Status public  
Assigned To BusyBox
Priority normal Resolution fixed  
Status closed   Product Version
Summary 0004104: od bug: dangling pointer
Description Hello, I'm part of a research group at Stanford working on automatic
bug finding tools. We are currently using Busybox as one of our
benchmarks, and I would like to report a series of bugs we found.
Please let me know if this site is not the preferred way of reporting
bugs.

Here is a first bug we found in od: a potential dangling pointer bug,
which can lead to memory corruption. Here is a very small test case
which exposes the problem:

$ echo -n a >A
$ od A

The problem is in the rewrite() function in dump.c. Here is the
relevant snippet (dump.c: 234-252, busybox 1.11.1):

(A) pr->fmt = xstrdup(fmtp);
    *p2 = savech;
(B) pr->cchar = pr->fmt + (p1 - fmtp);

   /* DBU:[dave@cray.com] w/o this, trailing fmt text, space is lost.
    * Skip subsequent text and up to the next % sign and tack the
    * additional text onto fmt: eg. if fmt is "%x is a HEX number",
    * we lose the " is a HEX number" part of fmt.
    */
   for (p3 = p2; *p3 && *p3 != '%'; p3++);
   if (p3 > p2)
   {
    savech = *p3;
    *p3 = '\0';
(C) pr->fmt = xrealloc(pr->fmt, strlen(pr->fmt)+(p3-p2)+1);
    strcat(pr->fmt, p2);
    *p3 = savech;
    p2 = p3;
   }

Line (A) initializes pr->fmt to point to a new buffer. On line (B),
pr->cchar is also set to point into this buffer. Later on, pr->fmt is
realloc'ed, potentially pointing to a new region in memory. However,
pr->cchar is not reset, and it still points to the old buffer. Later
on, when pr->cchar is written into (for example, in bpad(),
dump.c:438), the write can lead to memory corruption, since pr->cchar
may now point to either freed memory or a new buffer which happened to
be allocated there.

Cristian
Additional Information
Attached Files  4.patch [^] (1,120 bytes) 07-16-08 00:13

- Relationships

- Notes
(0009364)
vda
07-16-08 00:14

Your code analyser is cool.

Please try attached 4.patch.
 
(0009434)
cristic
07-16-08 14:24

Thanks! This definitely fixes the dangling pointer issue.
 
(0009454)
vda
07-16-08 16:17

fixed in svn
 

- Issue History
Date Modified Username Field Change
07-14-08 19:19 cristic New Issue
07-14-08 19:19 cristic Status new => assigned
07-14-08 19:19 cristic Assigned To  => BusyBox
07-15-08 18:08 cristic Issue Monitored: cristic
07-16-08 00:13 vda File Added: 4.patch
07-16-08 00:14 vda Note Added: 0009364
07-16-08 14:24 cristic Note Added: 0009434
07-16-08 16:17 vda Status assigned => closed
07-16-08 16:17 vda Note Added: 0009454
07-16-08 16:17 vda Resolution open => fixed


Copyright © 2000 - 2006 Mantis Group
Powered by Mantis Bugtracker