Note: This is a beta release of Red Hat Bugzilla 5.0. The data contained within is a snapshot of the live data so any changes you make will not be reflected in the production Bugzilla. Also email is disabled so feel free to test any aspect of the site that you want. File any problems you find or give feedback here.
Bug 231019 - stat returns incorrect exit status
Summary: stat returns incorrect exit status
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 4
Classification: Red Hat
Component: coreutils
Version: 4.4
Hardware: All
OS: Linux
medium
medium
Target Milestone: ---
: ---
Assignee: Tim Waugh
QA Contact:
URL:
Whiteboard:
: 249465 (view as bug list)
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2007-03-05 17:14 UTC by Bryn M. Reeves
Modified: 2018-10-19 21:08 UTC (History)
2 users (show)

Fixed In Version: RHBA-2007-0786
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2007-11-15 16:09:22 UTC


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


Links
System ID Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2007:0786 normal SHIPPED_LIVE coreutils bug fix update 2007-11-14 18:38:41 UTC

Description Bryn M. Reeves 2007-03-05 17:14:54 UTC
Description of problem:
Under a couple of error conditions, the stat(1) command incorrectly returns with
EXIT_SUCCESS instead of EXIT_FAILURE:

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

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

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

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));
      return;
    }


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

How reproducible:
100%

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 $?
0


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


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

  exit (ok ? EXIT_SUCCESS : EXIT_FAILURE);

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);
      else
        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 17:14:55 UTC
Created attachment 149269 [details]
patch to set G_fail=1 in error branches

Comment 4 Tim Waugh 2007-07-30 14:29:06 UTC
*** Bug 249465 has been marked as a duplicate of this bug. ***

Comment 11 errata-xmlrpc 2007-11-15 16:09:22 UTC
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.

http://rhn.redhat.com/errata/RHBA-2007-0786.html



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