Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 322421 - >=sys-apps/coreutils-7.5: touch -r gives spurious --file obsolete warning
Summary: >=sys-apps/coreutils-7.5: touch -r gives spurious --file obsolete warning
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Core system (show other bugs)
Hardware: All Linux
: High major (vote)
Assignee: Gentoo's Team for Core System packages
URL: http://git.savannah.gnu.org/cgit/core...
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-06-02 01:44 UTC by Robin Johnson
Modified: 2010-10-26 01:58 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
getopt_long_test.c (getopt_long_test.c,867 bytes, text/plain)
2010-06-02 01:45 UTC, Robin Johnson
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Robin Johnson archtester Gentoo Infrastructure gentoo-dev Security 2010-06-02 01:44:28 UTC
If you use the short version "-r" for a reference file, the value of longindex is not trustable (as per all getopt_long calls), and so sometimes the warning triggers, and sometimes it doesn't.

Minimal testcase attached.

Notice that long_index is not trustable with short option -r, and in the original src/touch.c, this can spuriously give the --file obsolete warning.

Test output:
======
CMD ./getopt_long_test -f foo bar
opt c=f optarg=NULL long_idx=-1(INVALID)
arg foo
arg bar
CMD ./getopt_long_test --file foo bar
opt c=r optarg=foo long_idx=1 lo[idx].val=r lo[idx].name=file
arg bar
CMD ./getopt_long_test -r foo bar
opt c=r optarg=foo long_idx=-1(INVALID)
arg bar
CMD ./getopt_long_test --reference foo bar
opt c=r optarg=foo long_idx=2 lo[idx].val=r lo[idx].name=reference
arg bar
======

As a fix:
- change the val field of the --file longoption to be 'f', and put the handling for the obsolete case there.
- always reset longindex to an invalid value after each iteration of the getopt_long loop, and check it for being valid before using it.
Comment 1 Robin Johnson archtester Gentoo Infrastructure gentoo-dev Security 2010-06-02 01:45:04 UTC
Created attachment 233799 [details]
getopt_long_test.c
Comment 2 Robin Johnson archtester Gentoo Infrastructure gentoo-dev Security 2010-06-02 01:49:41 UTC
Filed with upstream contributor that introduced the bug: meyering@redhat.com
Comment 3 Robin Johnson archtester Gentoo Infrastructure gentoo-dev Security 2010-06-02 04:05:33 UTC
Additional notes:

The documentation for glibc's _getopt_internal_r includes this block, that is NOT anywhere else that I can find:
   LONGIND returns the index in LONGOPT of the long-named option found.
   It is only valid when a long-named option has been found by the most
   recent call.
Comment 4 Robin Johnson archtester Gentoo Infrastructure gentoo-dev Security 2010-06-02 18:23:07 UTC
Upstream patch now available.
vapier: any objections to applying that patch to current ~arch and stable?
Comment 5 SpanKY gentoo-dev 2010-06-02 22:11:59 UTC
current stable is pointless.  dont care about adding to unstable patchset.
Comment 6 SpanKY gentoo-dev 2010-10-26 01:58:19 UTC
coreutils-8.6 is in the tree now and should already have this fix