public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/26172]  New: generates wrong code for pam_lastlog w/o optimization
@ 2006-02-08 10:57 egmont at uhulinux dot hu
  2006-02-08 10:58 ` [Bug c/26172] " egmont at uhulinux dot hu
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: egmont at uhulinux dot hu @ 2006-02-08 10:57 UTC (permalink / raw)
  To: gcc-bugs

Take
ftp://ftp.kernel.org/pub/linux/libs/pam/pre/library/Linux-PAM-0.99.3.0.tar.gz
compile it with
export CFLAGS="-fPIC -march=i586 -mtune=i586"
./configure [args...]; make

The resulted pam_lastlog.so module is wrong, there's an off-by-8-bytes bug
during a strncpy. However, if -O2 is also included amongst the CFLAGS, the
generated code is okay.

I attach the pam_lastlog.c file with two debug fprintf's inserted as well as
preprocessed source. The miscompiled part of the source is at line 278:

fprintf(stderr, "tl = %s\n", terminal_line); /* GCC BUG BELOW THIS LINE */
    strncat(last_login.ll_line, terminal_line, sizeof(last_login.ll_line)-1);
fprintf(stderr, "ll = %s\n", last_login.ll_line); /* GCC BUG ABOVE THIS LINE */

Without -O2, the following is printed to stderr during a "su -":
tl = pts/2
ll = ?@????P*pts/2
     ^^^^^^^^ this is 8 bytes of binary garbage, always different.

With -O2, strncat copies the string as expected:
tl = pts/2
ll = pts/2

The gcc command line:
i586-uhu-linux-gcc -DHAVE_CONFIG_H -I. -I. -I../.. -I../../libpam/include
-I../../libpamc/include -fPIC -march=i586 -mtune=i586 -DPAM_DYNAMIC -W -Wall
-Wbad-function-cast -Wcast-align -Wcast-qual -Wmissing-declarations
-Wmissing-prototypes -Wpointer-arith -Wreturn-type -Wstrict-prototypes
-Wwrite-strings -Winline -Wshadow -MT pam_lastlog.lo -MD -MP -MF
.deps/pam_lastlog.Tpo -c pam_lastlog.c  -fPIC -DPIC -o .libs/pam_lastlog.o


-- 
           Summary: generates wrong code for pam_lastlog w/o optimization
           Product: gcc
           Version: 3.4.5
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: egmont at uhulinux dot hu
 GCC build triplet: i586-uhu-linux
  GCC host triplet: i586-uhu-linux
GCC target triplet: i586-uhu-linux


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26172


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c/26172] generates wrong code for pam_lastlog w/o optimization
  2006-02-08 10:57 [Bug c/26172] New: generates wrong code for pam_lastlog w/o optimization egmont at uhulinux dot hu
@ 2006-02-08 10:58 ` egmont at uhulinux dot hu
  2006-02-08 10:58 ` egmont at uhulinux dot hu
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: egmont at uhulinux dot hu @ 2006-02-08 10:58 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from egmont at uhulinux dot hu  2006-02-08 10:58 -------
Created an attachment (id=10800)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=10800&action=view)
pam_lastlog.c with two extra fprintf's inserted (search for "GCC BUG" to find
them)


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26172


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c/26172] generates wrong code for pam_lastlog w/o optimization
  2006-02-08 10:57 [Bug c/26172] New: generates wrong code for pam_lastlog w/o optimization egmont at uhulinux dot hu
  2006-02-08 10:58 ` [Bug c/26172] " egmont at uhulinux dot hu
@ 2006-02-08 10:58 ` egmont at uhulinux dot hu
  2006-02-08 11:03 ` egmont at uhulinux dot hu
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: egmont at uhulinux dot hu @ 2006-02-08 10:58 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from egmont at uhulinux dot hu  2006-02-08 10:58 -------
Created an attachment (id=10801)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=10801&action=view)
preproecessed source


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26172


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c/26172] generates wrong code for pam_lastlog w/o optimization
  2006-02-08 10:57 [Bug c/26172] New: generates wrong code for pam_lastlog w/o optimization egmont at uhulinux dot hu
  2006-02-08 10:58 ` [Bug c/26172] " egmont at uhulinux dot hu
  2006-02-08 10:58 ` egmont at uhulinux dot hu
@ 2006-02-08 11:03 ` egmont at uhulinux dot hu
  2006-02-08 11:07 ` rguenth at gcc dot gnu dot org
  2006-02-08 11:21 ` egmont at uhulinux dot hu
  4 siblings, 0 replies; 6+ messages in thread
From: egmont at uhulinux dot hu @ 2006-02-08 11:03 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from egmont at uhulinux dot hu  2006-02-08 11:03 -------
sorry, there's a typo.  s/strncpy/strncat/


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26172


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c/26172] generates wrong code for pam_lastlog w/o optimization
  2006-02-08 10:57 [Bug c/26172] New: generates wrong code for pam_lastlog w/o optimization egmont at uhulinux dot hu
                   ` (2 preceding siblings ...)
  2006-02-08 11:03 ` egmont at uhulinux dot hu
@ 2006-02-08 11:07 ` rguenth at gcc dot gnu dot org
  2006-02-08 11:21 ` egmont at uhulinux dot hu
  4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2006-02-08 11:07 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from rguenth at gcc dot gnu dot org  2006-02-08 11:07 -------
    /* copy to last_login */
    last_login.ll_host[0] = '\0';
               ^^^^^^^^^
this should probably be ll_line.  You'll just get uninitialized stack garbage
at -O0.

fprintf(stderr, "tl = %s\n", terminal_line); /* GCC BUG BELOW THIS LINE */
    strncat(last_login.ll_line, terminal_line, sizeof(last_login.ll_line)-1);
fprintf(stderr, "ll = %s\n", last_login.ll_line); /* GCC BUG ABOVE THIS LINE */
    terminal_line = NULL;


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26172


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c/26172] generates wrong code for pam_lastlog w/o optimization
  2006-02-08 10:57 [Bug c/26172] New: generates wrong code for pam_lastlog w/o optimization egmont at uhulinux dot hu
                   ` (3 preceding siblings ...)
  2006-02-08 11:07 ` rguenth at gcc dot gnu dot org
@ 2006-02-08 11:21 ` egmont at uhulinux dot hu
  4 siblings, 0 replies; 6+ messages in thread
From: egmont at uhulinux dot hu @ 2006-02-08 11:21 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from egmont at uhulinux dot hu  2006-02-08 11:21 -------
Shame on me... I spent some hours debugging the problem but didn't realize
that I'm always continuously mixing strcpy and strcat, I just thought the
other one was used there. You're perfectly right, thanks very much and sorry
for bothering you! I'll go and report it to the pam folks...


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26172


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2006-02-08 11:21 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-02-08 10:57 [Bug c/26172] New: generates wrong code for pam_lastlog w/o optimization egmont at uhulinux dot hu
2006-02-08 10:58 ` [Bug c/26172] " egmont at uhulinux dot hu
2006-02-08 10:58 ` egmont at uhulinux dot hu
2006-02-08 11:03 ` egmont at uhulinux dot hu
2006-02-08 11:07 ` rguenth at gcc dot gnu dot org
2006-02-08 11:21 ` egmont at uhulinux dot hu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).