GNU bug report logs - #11675
stty bad C semantics

Previous Next

Package: coreutils;

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


View this message in rfc822 format

From: help-debbugs <at> gnu.org (GNU bug Tracking System)
To: Jim Meyering <jim <at> meyering.net>
Cc: tracker <at> debbugs.gnu.org
Subject: bug#11675: closed (stty bad C semantics)
Date: Tue, 12 Jun 2012 16:45:02 +0000
[Message part 1 (text/plain, inline)]
Your message dated Tue, 12 Jun 2012 18:41:21 +0200
with message-id <87haug32ku.fsf <at> rho.meyering.net>
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
help-debbugs <at> gnu.org.)


-- 
11675: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=11675
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
From: Edward Schwartz <edmcman <at> cmu.edu>
To: bug-coreutils <at> gnu.org
Subject: stty bad C semantics
Date: Mon, 11 Jun 2012 15:16:39 -0400
[Message part 3 (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)]
[Message part 5 (message/rfc822, inline)]
From: Jim Meyering <jim <at> meyering.net>
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: Edward Schwartz <edmcman <at> cmu.edu>, 11675-done <at> debbugs.gnu.org
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.


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.