[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#11675: stty bad C semantics
From: |
Edward Schwartz |
Subject: |
bug#11675: stty bad C semantics |
Date: |
Mon, 11 Jun 2012 15:16:39 -0400 |
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
Description: Binary data
- bug#11675: stty bad C semantics,
Edward Schwartz <=
bug#11675: stty bad C semantics, Jim Meyering, 2012/06/12