[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug #61009] xargs need option to immediately stop on command fail
From: |
Bernhard Voelker |
Subject: |
[bug #61009] xargs need option to immediately stop on command fail |
Date: |
Tue, 10 Aug 2021 02:46:23 -0400 (EDT) |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:90.0) Gecko/20100101 Firefox/90.0 |
Follow-up Comment #7, bug #61009 (project findutils):
>> find . -type f | xargs -F -IX -n1 cp -f X $IMGDIR_DST/X
>>
>> I can't find any problem with unsafe filenames. Am i wrong?
Yes:
The idiom 'find -type f | xargs -IX cp X ...' is per se unsafe:
`xargs -I` reads the input line by line - but yes, files can
have a newline in their name!
Here's a reproducer using exactly your command line (without the
hypothetical -F option, obviously) to copy /etc/passwd ... although
that's for sure not what the user wants:
$ rm -rf src dst # cleanup.
# Create a directory with in the SRC directory with a newline in the name,
# and initialize the DST directory.
$ mkdir -pv src/file$'\n'/etc dst/etc
mkdir: created directory 'src'
mkdir: created directory 'src/file'$'\n'
mkdir: created directory 'src/file'$'\n''/etc'
mkdir: created directory 'dst'
mkdir: created directory 'dst/etc'
$ cd src
$ IMGDIR_DST=../dst
# Create a dummy 'passwd' file therein.
$ echo DUMMY > file$'\n'/etc/passwd
# Add a dummy file which will hide that cp(1) will copy the wrong file.
$ echo HACKED > file
# Run the vulnerable command.
$ find . -type f | xargs -IX -n1 cp -f X $IMGDIR_DST/X
$ grep -R HACKED $IMGDIR_DST
../dst/file:HACKED
$ grep -RF $(whoami) $IMGDIR_DST
../dst/etc/passwd:victim:x:1003:100::/home/victim:/bin/bash
The safest way to avoid this problem is to let find(1) execute the program
directly, i.e., without the 'find | xargs' idiom.
Alternatively, use 'find ... -print0 | xargs -0 ...' instead.
_______________________________________________________
Reply to this item at:
<https://savannah.gnu.org/bugs/?61009>
_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/
- [bug #61009] xargs need option to immediately stop on command fail, anonymous, 2021/08/04
- [bug #61009] xargs need option to immediately stop on command fail, Bernhard Voelker, 2021/08/04
- [bug #61009] xargs need option to immediately stop on command fail, anonymous, 2021/08/05
- [bug #61009] xargs need option to immediately stop on command fail, anonymous, 2021/08/05
- [bug #61009] xargs need option to immediately stop on command fail, James Youngman, 2021/08/07
- [bug #61009] xargs need option to immediately stop on command fail, James Youngman, 2021/08/07
- [bug #61009] xargs need option to immediately stop on command fail, anonymous, 2021/08/09
- [bug #61009] xargs need option to immediately stop on command fail,
Bernhard Voelker <=
- [bug #61009] xargs need option to immediately stop on command fail, anonymous, 2021/08/10
- [bug #61009] xargs need option to immediately stop on command fail, Geoff Clare, 2021/08/11