Bugzilla will be upgraded to version 5.0 on a still to be determined date in the near future. The original upgrade date has been delayed.
Bug 231019 - stat returns incorrect exit status
stat returns incorrect exit status
Product: Red Hat Enterprise Linux 4
Classification: Red Hat
Component: coreutils (Show other bugs)
All Linux
medium Severity medium
: ---
: ---
Assigned To: Tim Waugh
: 249465 (view as bug list)
Depends On:
  Show dependency treegraph
Reported: 2007-03-05 12:14 EST by Bryn M. Reeves
Modified: 2010-10-22 09:30 EDT (History)
2 users (show)

See Also:
Fixed In Version: RHBA-2007-0786
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2007-11-15 11:09:22 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)
patch to set G_fail=1 in error branches (679 bytes, patch)
2007-03-05 12:14 EST, Bryn M. Reeves
no flags Details | Diff

External Trackers
Tracker ID Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2007:0786 normal SHIPPED_LIVE coreutils bug fix update 2007-11-14 13:38:41 EST

  None (edit)
Description Bryn M. Reeves 2007-03-05 12:14:54 EST
Description of problem:
Under a couple of error conditions, the stat(1) command incorrectly returns with

1. xreadlink returns NULL:
          char *linkname = xreadlink (filename);
          if (linkname == NULL)
              error (0, errno, _("cannot read symbolic link %s"),
                     quote (filename));

2. statfs fails:
  int i = statfs (filename, &statfsbuf);

  if (i == -1)
      error (0, errno, _("cannot read file system information for %s"),
             quote (filename));

3. stat fails:
  int i = ((follow_links == 1)
           ? stat (filename, &statbuf)
           : lstat (filename, &statbuf));

  if (i == -1)
      error (0, errno, _("cannot stat %s"), quote (filename));

Version-Release number of selected component (if applicable):

How reproducible:

Steps to Reproduce:
Example for 3 above:
1. $ stat /foo/bar (/foo/bar must not exist)
2. $ echo $?
Actual results:
$ stat /foo/bar
stat: cannot stat `/foo/bar': No such file or directory
$ echo $?

Expected results:
$ stat /foo/bar
stat: cannot stat `/foo/bar': No such file or directory
$ echo $?

Additional info:
This bug does not exist in FC6's coreutils. Upstream has moved to using bool
return types for do_stat, print_stat & friends. This is propagated back to main
and checked here:

  for (i = optind; i < argc; i++)
    ok &= (fs
           ? do_statfs (argv[i], terse, secure, format)
           : do_stat (argv[i], follow_links, terse, secure, format));


In RHEL-4 there is a global G_fail that is checked in a similar way:

  for (i = optind; i < argc; i++)
      if (fs == 0)
        do_stat (argv[i], follow_links, terse, secure, format);
        do_statfs (argv[i], terse, secure, format);

  exit (G_fail ? EXIT_FAILURE : EXIT_SUCCESS);

Proposed patch attached that used G_fail to propagate the error back to main
where we exit with EXIT_FAILURE.
Comment 1 Bryn M. Reeves 2007-03-05 12:14:55 EST
Created attachment 149269 [details]
patch to set G_fail=1 in error branches
Comment 4 Tim Waugh 2007-07-30 10:29:06 EDT
*** Bug 249465 has been marked as a duplicate of this bug. ***
Comment 11 errata-xmlrpc 2007-11-15 11:09:22 EST
An advisory has been issued which should help the problem
described in this bug report. This report is therefore being
closed with a resolution of ERRATA. For more information
on the solution and/or where to find the updated files,
please follow the link below. You may reopen this bug report
if the solution does not work for you.


Note You need to log in before you can comment on or make changes to this bug.