busybox/coreutils
Ari Sundholm e111a16404 truncate: always set mode when opening file to avoid fortify errors
Busybox crashes due to no mode being given when opening:
$ ./busybox truncate -s 1M foo
*** invalid open64 call: O_CREAT without mode ***: ./busybox terminated
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x7338f)[0x7f66d921338f]
/lib/x86_64-linux-gnu/libc.so.6(__fortify_fail+0x5c)[0x7f66d92aac9c]
/lib/x86_64-linux-gnu/libc.so.6(+0xeb6aa)[0x7f66d928b6aa]
./busybox[0x4899f9]
======= Memory map: ========
00400000-004d0000 r-xp 00000000 00:1a 137559                             /home/ari/busybox/busybox
006cf000-006d0000 r--p 000cf000 00:1a 137559                             /home/ari/busybox/busybox
006d0000-006d1000 rw-p 000d0000 00:1a 137559                             /home/ari/busybox/busybox
006d1000-006d4000 rw-p 00000000 00:00 0
014e7000-01508000 rw-p 00000000 00:00 0                                  [heap]
7f66d8f8a000-7f66d8fa0000 r-xp 00000000 08:07 1579008                    /lib/x86_64-linux-gnu/libgcc_s.so.1
7f66d8fa0000-7f66d919f000 ---p 00016000 08:07 1579008                    /lib/x86_64-linux-gnu/libgcc_s.so.1
7f66d919f000-7f66d91a0000 rw-p 00015000 08:07 1579008                    /lib/x86_64-linux-gnu/libgcc_s.so.1
7f66d91a0000-7f66d935b000 r-xp 00000000 08:07 1578994                    /lib/x86_64-linux-gnu/libc-2.19.so
7f66d935b000-7f66d955a000 ---p 001bb000 08:07 1578994                    /lib/x86_64-linux-gnu/libc-2.19.so
7f66d955a000-7f66d955e000 r--p 001ba000 08:07 1578994                    /lib/x86_64-linux-gnu/libc-2.19.so
7f66d955e000-7f66d9560000 rw-p 001be000 08:07 1578994                    /lib/x86_64-linux-gnu/libc-2.19.so
7f66d9560000-7f66d9565000 rw-p 00000000 00:00 0
7f66d9565000-7f66d966a000 r-xp 00000000 08:07 1579020                    /lib/x86_64-linux-gnu/libm-2.19.so
7f66d966a000-7f66d9869000 ---p 00105000 08:07 1579020                    /lib/x86_64-linux-gnu/libm-2.19.so
7f66d9869000-7f66d986a000 r--p 00104000 08:07 1579020                    /lib/x86_64-linux-gnu/libm-2.19.so
7f66d986a000-7f66d986b000 rw-p 00105000 08:07 1579020                    /lib/x86_64-linux-gnu/libm-2.19.so
7f66d986b000-7f66d988e000 r-xp 00000000 08:07 1578981                    /lib/x86_64-linux-gnu/ld-2.19.so
7f66d9a64000-7f66d9a67000 rw-p 00000000 00:00 0
7f66d9a8a000-7f66d9a8d000 rw-p 00000000 00:00 0
7f66d9a8d000-7f66d9a8e000 r--p 00022000 08:07 1578981                    /lib/x86_64-linux-gnu/ld-2.19.so
7f66d9a8e000-7f66d9a8f000 rw-p 00023000 08:07 1578981                    /lib/x86_64-linux-gnu/ld-2.19.so
7f66d9a8f000-7f66d9a90000 rw-p 00000000 00:00 0
7ffc47761000-7ffc47782000 rw-p 00000000 00:00 0                          [stack]
7ffc477ab000-7ffc477ad000 r-xp 00000000 00:00 0                          [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]
Aborted (core dumped)
$

Fix this by simply always setting the mode, as it doesn't hurt even
when O_CREAT is not specified.

This bug is a regression introduced in fc3e40e, as xopen(), which
was originally used, would automatically set the mode.

Signed-off-by: Ari Sundholm <ari@tuxera.com>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2016-01-13 13:28:01 -05:00
..
libcoreutils libbb: more compact API for bb_parse_mode() 2015-10-07 17:55:33 +02:00
basename.c trim extra newlines in help texts 2015-01-24 19:46:45 +01:00
cal.c Use unsigned printf/scanf conversion where more appropriate 2013-11-29 16:45:45 +01:00
cat.c move help text from include/usage.src.h to coreutils/*.c 2011-03-31 14:43:25 +02:00
catv.c catv: suppress compiler warning 2014-02-03 03:27:53 +01:00
chgrp.c *: remove "Options:" string from help texts 2011-06-05 03:58:28 +02:00
chmod.c libbb: more compact API for bb_parse_mode() 2015-10-07 17:55:33 +02:00
chown.c libbb: make parse_chown_usergroup_or_die() set unspecified uid/gid to -1 2015-10-19 04:37:19 +02:00
chroot.c libbb: make xchroot do a chdir("/") after chroot 2012-03-08 00:28:24 +01:00
cksum.c move help text from include/usage.src.h to coreutils/*.c 2011-03-31 14:43:25 +02:00
comm.c *: remove "Options:" string from help texts 2011-06-05 03:58:28 +02:00
Config.src stat: make -f optional. This allows to build stat for non-linux systems 2015-10-30 22:10:44 +01:00
cp.c Add conditional support for -v / --verbose 2014-05-19 16:23:50 +02:00
cut.c whitespace fixes. no code changes 2013-01-14 01:34:48 +01:00
date.c libbb: introduce and use is_prefixed_with() 2015-03-12 17:48:34 +01:00
dd.c libiproute: rename invarg(a,b) to invarg_1_to_2(a,b) 2015-10-14 13:21:01 +02:00
df.c df: fix -T option when ENABLE_FEATURE_HUMAN_READABLE=0 2014-09-20 18:55:17 +02:00
dirname.c move help text from include/usage.src.h to coreutils/*.c 2011-03-31 14:43:25 +02:00
dos2unix.c *: remove "Options:" string from help texts 2011-06-05 03:58:28 +02:00
du.c du: extra compat: with -k and -m, round sizes up 2015-10-15 21:33:34 +02:00
echo.c echo: make escape sequences depend on fancy mode 2015-07-31 03:47:49 +02:00
env.c *: remove "Options:" string from help texts 2011-06-05 03:58:28 +02:00
expand.c expand: use printable_string instead of hard-coding implementation 2013-12-16 03:38:24 +01:00
expr.c add INIT_G()'s. No code changes. 2011-09-21 01:59:15 +02:00
false.c special-case {true,false,test} --help 2015-04-21 16:00:41 +02:00
fold.c *: remove "Options:" string from help texts 2011-06-05 03:58:28 +02:00
fsync.c *: remove "Options:" string from help texts 2011-06-05 03:58:28 +02:00
head.c Commonalize typical [b,]k,m suffix struct 2013-07-13 23:49:45 +02:00
hostid.c hostid: do not output sign-extended host id. Closes 6056 2013-03-04 03:04:38 +01:00
id_test.sh id: coreutils compat by Tito + test script 2008-10-29 00:27:31 +00:00
id.c platform: use KERNEL_VERSION to simplify uClibc version checking 2013-03-12 11:13:22 -04:00
install.c libbb: more compact API for bb_parse_mode() 2015-10-07 17:55:33 +02:00
Kbuild.src sync: add support for -d -f FILE 2015-07-21 19:50:48 +02:00
length.c.disabled move help text from include/usage.src.h to debianutils/*.c e2fsprogs/*.c editors/*.c loginutils/*.c mailutils/*.c 2011-04-03 01:33:55 +02:00
ln.c Removes stray empty line from code 2015-07-13 03:25:46 +02:00
logname.c move help text from include/usage.src.h to coreutils/*.c 2011-03-31 14:43:25 +02:00
ls.c libbb: factor out code which queries screen width 2015-10-23 01:44:22 +02:00
md5_sha1_sum.c foo*sum: Correct syntax error 2013-07-04 11:33:42 +02:00
mkdir.c libbb: more compact API for bb_parse_mode() 2015-10-07 17:55:33 +02:00
mkfifo.c *: remove "Options:" string from help texts 2011-06-05 03:58:28 +02:00
mknod.c whitespace cleanup. no code changes 2013-01-14 15:57:44 +01:00
mv.c Add conditional support for -v / --verbose 2014-05-19 16:23:50 +02:00
nice.c *: remove "Options:" string from help texts 2011-06-05 03:58:28 +02:00
nohup.c move help text from include/usage.src.h to coreutils/*.c 2011-03-31 14:43:25 +02:00
od_bloaty.c od: get rid of (almost all) statics 2015-10-19 02:51:56 +02:00
od.c od: code shrink, fix "od --traditional FILE" 2011-05-21 17:43:06 +02:00
printenv.c move help text from include/usage.src.h to coreutils/*.c 2011-03-31 14:43:25 +02:00
printf.c printf: fix this case: printf "%b" '\0057usr\0057bin\n' 2012-03-07 11:57:47 +01:00
pwd.c whitespace fixes 2011-10-28 14:07:44 +02:00
readlink.c readlink: note that our -f is really -e 2013-03-12 11:38:03 -04:00
realpath.c move help text from include/usage.src.h to coreutils/*.c 2011-03-31 14:43:25 +02:00
rm.c Add conditional support for -v / --verbose 2014-05-19 16:23:50 +02:00
rmdir.c Add conditional support for -v / --verbose 2014-05-19 16:23:50 +02:00
seq.c *: remove "Options:" string from help texts 2011-06-05 03:58:28 +02:00
shuf.c fix whitespaces 2015-06-07 18:19:47 +02:00
sleep.c move help text from include/usage.src.h to coreutils/*.c 2011-03-31 14:43:25 +02:00
sort.c sort: fix ENDCHAR handling in "-kSTART,N.ENDCHAR" 2015-10-19 19:27:26 +02:00
split.c Commonalize typical [b,]k,m suffix struct 2013-07-13 23:49:45 +02:00
stat.c stat: make -f optional. This allows to build stat for non-linux systems 2015-10-30 22:10:44 +01:00
stty.c libbb: factor out code which queries screen width 2015-10-23 01:44:22 +02:00
sum.c Use unsigned printf/scanf conversion where more appropriate 2013-11-29 16:45:45 +01:00
sync.c sync: add support for -d -f FILE 2015-07-21 19:50:48 +02:00
tac.c move help text from include/usage.src.h to coreutils/*.c 2011-03-31 14:43:25 +02:00
tail.c tail: adjust help/usage texts 2014-01-10 16:26:15 +01:00
tee.c *: remove "Options:" string from help texts 2011-06-05 03:58:28 +02:00
test_ptr_hack.c *: make GNU licensing statement forms more regular 2010-08-16 20:14:46 +02:00
test.c special-case {true,false,test} --help 2015-04-21 16:00:41 +02:00
touch.c touch: add conditional support for -h 2013-09-11 11:58:33 +02:00
tr.c tr: support octal ranges 2015-10-26 17:18:07 +01:00
true.c special-case {true,false,test} --help 2015-04-21 16:00:41 +02:00
truncate.c truncate: always set mode when opening file to avoid fortify errors 2016-01-13 13:28:01 -05:00
tty.c *: remove "Options:" string from help texts 2011-06-05 03:58:28 +02:00
uname.c uname: make OS name configurable 2015-08-03 18:09:18 +02:00
uniq.c build system: -fno-builtin-printf 2015-10-07 22:42:45 +02:00
unlink.c unlink: new applet 2014-06-22 20:44:25 +02:00
usleep.c usleep: do not check for usleep error, it should never fail 2011-07-08 08:37:57 +02:00
uudecode.c uudecode: tolerate text input with CR+LF line ends 2015-10-05 15:10:44 +02:00
uuencode.c uuencode: tweak help text 2012-03-05 14:22:33 +01:00
wc.c *: remove "Options:" string from help texts 2011-06-05 03:58:28 +02:00
who.c build system: -fno-builtin-printf 2015-10-07 22:42:45 +02:00
whoami.c move help text from include/usage.src.h to coreutils/*.c 2011-03-31 14:43:25 +02:00
yes.c *: make GNU licensing statement forms more regular 2010-08-16 20:14:46 +02:00