]> granicus.if.org Git - sysstat/commit
Fixed random crash with iostat when called with
authorSebastien Godard <sysstat@orange.fr>
Sun, 20 Nov 2011 15:29:07 +0000 (16:29 +0100)
committerSebastien Godard <sysstat@orange.fr>
Sun, 20 Nov 2011 15:29:07 +0000 (16:29 +0100)
commitce378d3ec93d5edddb1d2081ce6ee9b07f6da287
treeed90e16d22c416465e27cf607da8b7aee6fccffd
parentb8112c86d56c37b76c34a3116da5db702e111151
Fixed random crash with iostat when called with
option -N [NOVELL Bug#729130].

Mail from Petr Uzel <petr.uzel@suse.cz> 11/13/2011 11:45 AM:

> > On 11/09/2011 01:34 PM, Petr Uzel wrote:
>> > >attached patch fixes
>> > >https://bugzilla.novell.com/show_bug.cgi?id=729130
>> > >
Hi Sebastien,

As far as I understand (please correct me if I'm wrong), sysstat is
hitting unspecified behavior, which might explain why you can not
reproduce the bug.

Check out transfrom_devmapname() function:

while ((dp = readdir(dm_dir)) != NULL) {
/* For each file in DEVMAP_DIR */

snprintf(filen, MAX_FILE_LEN, "%s/%s", DEVMAP_DIR, dp->d_name);
filen[MAX_FILE_LEN - 1] = '\0';

if (stat(filen, &aux) == 0) {
/* Get its minor and major numbers */

dm_major = major(aux.st_rdev);
dm_minor = minor(aux.st_rdev);

if ((dm_minor == minor) && (dm_major == major)) {
[********>]  dm_name = dp->d_name;
break;
}
}
}
closedir(dm_dir);

dm_name points to the memory returned by readdir(), but from 'man
readdir', this memory is not guaranteed to be valid after next call
to readdir or after closedir().

man readdir:

       ....
       The data returned by readdir() may be overwritten by subsequent
       calls to readdir() for the same directory stream.
       ....

man closedir:

       ....
       The  closedir()  function closes the directory stream
       associated with dirp.  A successful call to closedir() also
       closes the underlying file descriptor associated with dirp.
       The directory stream descriptor dirp is not available after
       this call.
       ....

[It is not very clear to me if this also invalidates the dirent
structure]

So the solution is to strncpy the memory before it gets invalidated by
next readdir() or closedir().

Unrelated to this bug:
Could you please add something like make install_nostrip to the
Makefile? By default, the buildsystem uses LDFLAGS = -s, which always
strips the resulting binary. In openSUSE, we have to patch this,
because we need to strip the binaries on our own (to create
sysstat-debug{source,info} packages).

Thanks for your support,

Petr.
CHANGES
ioconf.c
iostat.c
pidstat.c
rndr_stats.c