tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: possible opendir bug?



>> I'm not sure to what extent use of uninitialized memory is
>> considered a bug when, as here, the code is correct regardless of
>> what value it contains.

> It is a bug (and should be detected in builds with proper -fsanitize=
> compiler options in -current at least).

There's a -fsanitize= option affecting malloc()ed block contents??

I wonder why it hasn't been picked up already, then.

> Do you have a reproducer handy?

I noticed it with...su, I think it was, but that's just an artifact of
which processes I happened to run after getting the emulator to that
point.  Anything that calls opendir() and readdir() on a should trigger
it.  Here's a tiny example.  This compiles and runs under the emulator,
but when malloc-undefinedness is turned on, it trips.

#include <dirent.h>

int main(void);
int main(void)
{
 DIR *d;
 struct dirent *e;

 d = opendir(".");
 if (d) e = readdir(d);
 // don't let the above be "optimized" away
 (void)((volatile struct dirent *)e)->d_fileno;
 return(0);
}

/~\ The ASCII				  Mouse
\ / Ribbon Campaign
 X  Against HTML		mouse%rodents-montreal.org@localhost
/ \ Email!	     7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B


Home | Main Index | Thread Index | Old Index