GNU bug report logs -
#11675
stty bad C semantics
Previous Next
Reported by: Edward Schwartz <edmcman <at> cmu.edu>
Date: Mon, 11 Jun 2012 19:27:01 UTC
Severity: normal
Done: Jim Meyering <jim <at> meyering.net>
Bug is archived. No further changes may be made.
Full log
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Hi,
I think there is a bug in main() of stty in coreutils 8.17. The gist
of the problem is that two structures are initialized:
struct termios mode = { 0, };
and
struct termios new_mode = { 0, };
They are then both modified, and then compared with memcmp. The
problem is that the structs contain padding bytes. The C99 standard
says "The value of padding bytes when storing values in structures or
unions (6.2.6.1)." is unspecified, so the padding bytes may not be set
to zero.
I don't have any problem compiling with gcc. On my machine, gcc
initializes the entire struct memory with a loop that writes 0.
I came across the bug when compiling coreutils under CIL, which
rewrites many C language constructs to make them easier to analyze.
CIL writes 0 to each struct field, leaving padding bytes untouched.
Both are correct, under my interpretation of the C99 standard.
However, CIL's behavior violates the assumptions of stty's memcmp,
which assumes padding bytes are set to zero.
The problem is easily fixed by using memset, instead of implied
initializations. I am attaching a patch that does this. While it
won't affect most coreutils users, it might save some time for someone
using a non-standard compiler or analysis platform.
Thanks,
Ed
[stty.patch (application/octet-stream, attachment)]
This bug report was last modified 12 years and 342 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.