public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/98905] New: lstat() confused with wrong struct stat
@ 2021-01-31 17:46 gcc at madler dot net
  2021-01-31 21:57 ` [Bug target/98905] " redi at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: gcc at madler dot net @ 2021-01-31 17:46 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98905

            Bug ID: 98905
           Summary: lstat() confused with wrong struct stat
           Product: gcc
           Version: 5.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gcc at madler dot net
  Target Milestone: ---

When compiling on Solaris (SunOS gcc-solaris11 5.11 11.3 sun4u sparc
SUNW,SPARC-Enterprise) using gcc 5.5.0 with a particular set of macros defined,
lstat() thinks its writing to a different struct stat than the struct stat that
is declared. This result in bogus values for the struct elements. Here is a
sample program:

#define _FILE_OFFSET_BITS 64
#define _XOPEN_SOURCE 600
#include <stdio.h>
#include <sys/stat.h>

int main(int argc, char **argv) {
    for (int i = 1; i < argc; i++) {
        struct stat st;
        int ret = lstat(argv[i], &st);
        printf("%s: lstat() returned %d, mode = %lx, size = %llu\n",
               argv[i], ret, st.st_mode, st.st_size);
    }
    return 0;
}

This will generally print a value like 1 or 2 for mode (should be 0x8zzz for a
file), and a giant number for size. Three things are required together to
manifest the bug: the two #define's and the use of lstat(). If either of the
defines is removed or stat() is used, the bug does not manifest.

Example output:

lstat-bug: lstat() returned 0, mode = 1, size = 6923981885842223364
lstat-bug.c: lstat() returned 0, mode = 1, size = 6923981159521138040

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

* [Bug target/98905] lstat() confused with wrong struct stat
  2021-01-31 17:46 [Bug c/98905] New: lstat() confused with wrong struct stat gcc at madler dot net
@ 2021-01-31 21:57 ` redi at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: redi at gcc dot gnu.org @ 2021-01-31 21:57 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98905

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2021-01-31
             Status|UNCONFIRMED                 |WAITING
     Ever confirmed|0                           |1

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
GCC 5.5 has been unsupported and unmaintained for several years, please try a
current release.

The lstat function and struct stat are nothing to do with GCC, they come from
Solaris headers.

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

end of thread, other threads:[~2021-01-31 21:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-31 17:46 [Bug c/98905] New: lstat() confused with wrong struct stat gcc at madler dot net
2021-01-31 21:57 ` [Bug target/98905] " redi at gcc dot gnu.org

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).