I found that behavior of bash depends on uninitialized values in
memory.
In function file_mod_date_changed (mailcheck.c), if mailstat returns a
non-zero
value, we are checking condition finfo.st_size == 0, where
finfo.st_size is
uninitialized. In those rare cases when finfo.st_size is zero and
mailfiles[i]->file_size > 0 we update mailfiles array with some random
values
(while the file may even not exist).
Consider following scenario:
I have no specified mailbox path, so it defaults to /var/mail/szymon,
which
does not exist.
Then I run bash:
./bash
[szymon@harmony bash]$ export MAILCHECK=0
[szymon@harmony bash]$ mkdir /var/mail/szymon
You have mail in /var/mail/szymon
[szymon@harmony bash]$ rm -r /var/mail/szymon
[szymon@harmony bash]$ mkdir /var/mail/szymon
[szymon@harmony bash]$
[szymon@harmony bash]$ rm -r /var/mail/szymon
[szymon@harmony bash]$
[szymon@harmony bash]$ mkdir /var/mail/szymon
[szymon@harmony bash]$
[szymon@harmony bash]$ exit
If I modify mailstat to put some specific values into struct stat *st
(st_size = 0 and st_mtime = 1) when stat() fails, I get the following:
./bash
[szymon@harmony bash]$ export MAILCHECK=0
[szymon@harmony bash]$ mkdir /var/mail/szymon
You have mail in /var/mail/szymon
[szymon@harmony bash]$ rm -r /var/mail/szymon
[szymon@harmony bash]$ mkdir /var/mail/szymon
You have mail in /var/mail/szymon
[szymon@harmony bash]$ rm -r /var/mail/szymon
[szymon@harmony bash]$ mkdir /var/mail/szymon
You have mail in /var/mail/szymon
[szymon@harmony bash]$ rm -r /var/mail/szymon
[szymon@harmony bash]$ mkdir /var/mail/szymon
You have mail in /var/mail/szymon
[szymon@harmony bash]$ rm -r /var/mail/szymon
[szymon@harmony bash]$ exit
So behavior of bash depends on these values. valgrind confirms that
problem:
==13079== Conditional jump or move depends on uninitialised value(s)
==13079== at 0x809B922: check_mail (mailcheck.c:273)
==13079== by 0x806D0E3: yyparse (parse.y:2504)
==13079== by 0x80650AC: parse_command (eval.c:228)
==13079== by 0x806516D: read_command (eval.c:272)
==13079== by 0x80653A5: reader_loop (eval.c:137)
==13079== by 0x40DE482: (below main) (in /lib/libc-2.15.so)
==13079==
It seems to be a minor bug, however, still a bug.
For my convenience, I've added some debug printfs to mailcheck.c and
mailstat.c.