[Top][All Lists]

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

[debbugs-tracker] bug#11675: closed (stty bad C semantics)

From: GNU bug Tracking System
Subject: [debbugs-tracker] bug#11675: closed (stty bad C semantics)
Date: Tue, 12 Jun 2012 16:45:02 +0000

Your message dated Tue, 12 Jun 2012 18:41:21 +0200
with message-id <address@hidden>
and subject line Re: bug#11675: stty bad C semantics
has caused the debbugs.gnu.org bug report #11675,
regarding stty bad C semantics
to be marked as done.

(If you believe you have received this mail in error, please contact

11675: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=11675
GNU Bug Tracking System
Contact address@hidden with problems
--- Begin Message --- Subject: stty bad C semantics Date: Mon, 11 Jun 2012 15:16:39 -0400

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, };


  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 (" 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.


Attachment: stty.patch
Description: Binary data

--- End Message ---
--- Begin Message --- Subject: Re: bug#11675: stty bad C semantics Date: Tue, 12 Jun 2012 18:41:21 +0200
Paul Eggert wrote:
> On 06/12/2012 07:33 AM, Jim Meyering wrote:
>> Here's a way to solve the problem that doesn't require restoring
>> the memset calls.  It feels slightly hackish
> But it's hackish in a good way!  It's a bit faster
> and smaller and more portable than the existing code,
> and it's faster and smaller than all the other proposed
> fixes.  It's clearly the best idea yet.  Thanks for
> cutting the Gordian knot.

Thanks.  With that, I've pushed it and marked this as done.

--- End Message ---

reply via email to

[Prev in Thread] Current Thread [Next in Thread]