Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 699550 - sys-apps/install-xattr - install-xattr incorrectly processes -Z flag
Summary: sys-apps/install-xattr - install-xattr incorrectly processes -Z flag
Status: CONFIRMED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal major
Assignee: Gentoo's Team for Core System packages
URL:
Whiteboard:
Keywords:
: 690836 (view as bug list)
Depends on:
Blocks: 699552
  Show dependency tree
 
Reported: 2019-11-07 17:03 UTC by Raimonds Cicans
Modified: 2023-01-28 20:21 UTC (History)
2 users (show)

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


Attachments
Workaround - works for me (install-xattr-Z.patch,915 bytes, patch)
2019-11-07 17:03 UTC, Raimonds Cicans
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Raimonds Cicans 2019-11-07 17:03:44 UTC
Created attachment 595242 [details, diff]
Workaround - works for me

“install-xattr” allow “-Z” flag to have option(s) (unlike “install” from package “sys-apps/coreutils” which it tries to mimic) which leads to strange behaviour in some cases – in subsequent call to “install” some parameters switch places which may lead to error.

Test case (works on any Linux profile,  not only selinux):
strace -f install-xattr -Z  -m 755 -d  /tmp/213  2>&1 | grep execve

Result:
execve("/usr/bin/install-xattr", ["install-xattr", "-Z", "-m", "755", "-d", "/tmp/213"], 0x7ffe5034fdb0 /* 51 vars */) = 0
[pid 578966] execve("/usr/bin/install", ["/usr/bin/install", "-Z", "-m", "-d", "755", "/tmp/213"], 0x7ffdeca8aac0 /* 51 vars */) = 0

Parameters “755”  and “-d” switched places!!!

This is caused by one of calls to glibc’s function “getopt_long”, which mangle program’s “argv” variable.

I’m  not competent to say which one is root cause: bug in glibc or wrong parameters sent to function “getopt_long”.

After fixing, it may be good idea to review all build bugs on selinux profiles which fail with strange errors in install stage…
Comment 1 Anthony Basile gentoo-dev 2019-11-08 15:47:53 UTC
Good catch.  I'll commit, cut a new release and test over the weekend.
Comment 2 Anthony Basile gentoo-dev 2019-11-09 20:02:02 UTC
(In reply to Raimonds Cicans from comment #0)
> This is caused by one of calls to glibc’s function “getopt_long”, which
> mangle program’s “argv” variable.
> 
> I’m  not competent to say which one is root cause: bug in glibc or wrong
> parameters sent to function “getopt_long”.
> 

Your patch doesn't fix the issue for me.  The root problem is getopt_long() mangling argv.  I need to make a copy of argv for parsing to avoid this :(
Comment 3 Raimonds Cicans 2019-11-10 11:20:44 UTC
Hmmm....

Yes. My patch is wrong.

It is expected behaviour from getopt* family of functions.

Excerpt from getopt man page:
> By default, getopt() permutes the contents of argv as it scans, so that eventually all the nonoptions are at the end.

But is copying of argv really necessary?
According to getopt man page:
>  If the first character of optstring is '-', then each nonoption argv-element is handled as if it were the argument of an option with character code 1.
> (This is used by programs that were written to expect options and other argv-elements in any order and that care about the ordering of the two.)

My simple test showed that adding '-' to begining of optstring will result in preserved argv content.
But i'm not sure how it affect rest of code.
Comment 4 Anthony Basile gentoo-dev 2019-11-10 13:06:49 UTC
(In reply to Raimonds Cicans from comment #3)
> Hmmm....
> 
> Yes. My patch is wrong.
> 

Please test install-xattr-0.8 which I added to the tree.
Comment 5 Raimonds Cicans 2019-11-10 15:30:38 UTC
profile: default/linux/amd64/17.1/desktop/plasma/systemd
test case & app-emulation/libpod: Ok (as before,no regression)

profile: default/linux/amd64/17.1/no-multilib/hardened/selinux
test case: now Ok
app-emulation/libpod: still fails, but little more further (looks one more bug, not related to this bug)
Comment 6 Zac Medico gentoo-dev 2019-11-10 18:01:15 UTC
*** Bug 690836 has been marked as a duplicate of this bug. ***
Comment 7 Mike Gilbert gentoo-dev 2019-11-11 20:56:07 UTC
Moving bug 699548 to See Also as there is no real dependency here.