Karel Zak [Tue, 9 Dec 2014 10:53:39 +0000 (11:53 +0100)]
Merge branch '2014wk48' of git://github.com/kerolasa/lelux-utiliteetit
* '2014wk48' of git://github.com/kerolasa/lelux-utiliteetit:
getopt: avoid re-terminating long_option list at every update
getopt: change --shell argument parsing function
getopt: prefer switch-case rather than long if statement
getopt: remove unnecessary code
getopt: make normalize() print strings
getopt: use xstrdup rather than malloc + strcpy
getopt: add struct getopt_control and remove global variables
getopt: remove function prototypes
getopt: make nonoptions optstring comment correct
tests: add more getopt tests
tests: copy test-suite from Frodo Looijaard's getopt
getopt: sync with 1.1.6 release
line: use util-linux conventions
textual: improve error messages
login-utils: use libc error printing facility
Sami Kerola [Mon, 8 Dec 2014 22:20:56 +0000 (22:20 +0000)]
lslogins: align usage() and manual with struct option longopts
Short option -G goes together with long option --supp-groups, while
neither of -m or --groups-info has worked in a release so remove them
from usage() and manual.
Sami Kerola [Sun, 7 Dec 2014 10:13:04 +0000 (10:13 +0000)]
line: use util-linux conventions
This change add --help and --version print outs, checking at exit the
stdout write was successful, and as a minor thing the command is made to
use wide char functions to read and write inputs.
Sami Kerola [Sun, 7 Dec 2014 09:55:08 +0000 (09:55 +0000)]
getopt: avoid re-terminating long_option list at every update
Terminating the ctl->long_options list once when adding options is
completed is enough. This also allows moving ctl->long_options_nr
increment to more appropriate location.
CC: Frodo Looijaard <frodo@frodo.looijaard.name> Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Sami Kerola [Sat, 6 Dec 2014 10:47:53 +0000 (10:47 +0000)]
getopt: make nonoptions optstring comment correct
From manual 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.'
Reference: http://man7.org/linux/man-pages/man3/getopt.3.html CC: Frodo Looijaard <frodo@frodo.looijaard.name> Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Sami Kerola [Thu, 4 Dec 2014 22:39:21 +0000 (22:39 +0000)]
tests: copy test-suite from Frodo Looijaard's getopt
The test cases and their names are the same, but the surrounding testing
facility with Frodo's svn and util-linux are pretty different so this is
not exactly 1:1 copy.
Reference: svn://svn.frodo.looijaard.name/public/getopt/trunk/tests CC: Frodo Looijaard <frodo@frodo.looijaard.name> Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Sami Kerola [Thu, 4 Dec 2014 21:49:13 +0000 (21:49 +0000)]
line: use util-linux conventions
This change add --help and --version print outs, checking at exit the
stdout write was successful, and as a minor thing the command is made to
use wide char functions to read and write inputs.
Karel Zak [Fri, 5 Dec 2014 14:30:04 +0000 (15:30 +0100)]
libmount: add new libmnt_monitor API
It's usually enough to us [e]poll() to monitor kernel mount table, but
there is no way how to monitor changes in userspace mount options
(e.g. _netdev). The management of these mount options is completely
hidden in libmount and /rub/mount/utab is private libmount file.
This patch introduces new libmnt_mount API to monitor also userspace
mount table.
While digging deeper into libblk probing, I found that some
computations might wrap and allocate too few buffer space which then
overflows. In particular on 32bit systems (chromebook) where size_t is
32bit, this is problematic (for 64bit the result fits into the calloc
size_t).
Karel Zak [Thu, 4 Dec 2014 09:27:39 +0000 (10:27 +0100)]
libfdisk: fix cfdisk freespace analyze
The problem is how fdisk_partition_cmp_start() compare numbers, the
function returns result from "a->start - b->start", unfortunately the
numbers are uint64, but function returns "int".
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1170191 Signed-off-by: Karel Zak <kzak@redhat.com>
such string is later incorrectly parsed and blkid(8) returns
nonsenses. And for use-cases like
# eval $(blkid -o export /dev/sdb1)
it's also insecure.
Note that mount, udevd and blkid -p are based on low-level libblkid
API, it bypass the cache and directly read data from the devices.
The current udevd upstream does not depend on blkid(8) output at all,
it's directly linked with the library and all unsafe chars are encoded by
\x<hex> notation.
Karel Zak [Thu, 20 Nov 2014 12:11:38 +0000 (13:11 +0100)]
libfdisk: (dos) allow to maximize partition
The struct fdisk_partition has special flag "end_follow_default" to
make the partition large as much as possible. This patch makes this
flag usable for fdisk_set_partition() function.
Command line example (enlarge the first partition):
# echo ',+' | ./sfdisk -N1 /dev/sdb
...
Disk /dev/sdb: 100 MiB, 104857600 bytes, 204800 sectors
...
Old situation:
Device Boot Start End Sectors Size Id Type
/dev/sdb1 2048 22527 20480 10M 83 Linux
^^^^^
New situation:
Device Boot Start End Sectors Size Id Type
/dev/sdb1 2048 204799 202752 99M 83 Linux
^^^^^^
Karel Zak [Thu, 20 Nov 2014 09:56:03 +0000 (10:56 +0100)]
aggety: always set default serial line speed
* makes speeds table usage more robust
* don't call next_speed() for empty speeds table to avoid division by zero
* default to 9600 when port baud unspecified
Addresses: https://github.com/karelzak/util-linux/pull/131 Signed-off-by: Karel Zak <kzak@redhat.com>
The error path was a bit unclear on the semantics. The seq argument
would get freed but not the name argument. Then the caller frees
them both when the function returns an error.
This fixes the problem my making the function not touch the arguments
unless we're going to return success. Also improve the description
for this function to make it more obvious what the callers should expect.
Addresses: CID#77487 (on scan.coverity.com for JIghtuse/util-linux) Signed-off-by: Andreas Henriksson <andreas@fatal.se>
Direct leak of 8 byte(s) in 1 object(s) allocated from:
#0 0x49d12b in __interceptor_malloc (/home/src/util-linux/.libs/lt-mkswap+0x49d12b)
#1 0x7faf2a5069c9 in __GI___strdup (/usr/lib/libc.so.6+0x819c9)
#2 0xffff96e7e33 (<unknown module>)
SUMMARY: AddressSanitizer: 8 byte(s) leaked in 1 allocation(s).
And another one that valgrind found.
==6316== 8 bytes in 1 blocks are definitely lost in loss record 1 of 1
==6316== at 0x4C29F90: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==6316== by 0x5E3F9C9: strdup (in /usr/lib/libc-2.20.so)
==6316== by 0x43A25F: size_to_human_string (strutils.c:495)
==6316== by 0x42B35C: main (mkswap.c:488)
Sami Kerola [Sun, 9 Nov 2014 15:26:05 +0000 (15:26 +0000)]
libmount: fix memory overflow [AddressSanitizer]
==10918==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7fffd795b680 at pc 0x0000004447c6 bp 0x7fffd795b3e0 sp 0x7fffd795ab78
WRITE of size 129 at 0x7fffd795b680 thread T0
#0 0x4447c5 in scanf_common(void*, int, bool, char const*, __va_list_tag*) (/home/src/util-linux/.libs/lt-mount+0x4447c5)
#1 0x445892 in sscanf (/home/src/util-linux/.libs/lt-mount+0x445892)
#2 0x7fe78709a3d3 in get_filesystems /home/src/util-linux/libmount/src/utils.c:581:7
#3 0x7fe78709a1ba in mnt_get_filesystems /home/src/util-linux/libmount/src/utils.c:622:7
#4 0x7fe7870aa78f in do_mount_by_pattern /home/src/util-linux/libmount/src/context_mount.c:833:7
#5 0x7fe7870a9534 in mnt_context_do_mount /home/src/util-linux/libmount/src/context_mount.c:951:9
#6 0x7fe7870aab2b in mnt_context_mount /home/src/util-linux/libmount/src/context_mount.c:1051:8
#7 0x4ba9f5 in main /home/src/util-linux/sys-utils/mount.c:1107:7
#8 0x7fe785caa03f in __libc_start_main (/usr/lib/libc.so.6+0x2003f)
#9 0x4b9f9c in _start (/home/src/util-linux/.libs/lt-mount+0x4b9f9c)
Signed-off-by: Sami Kerola <kerolasa@iki.fi> Signed-off-by: Karel Zak <kzak@redhat.com>
Sami Kerola [Sun, 2 Nov 2014 22:06:15 +0000 (22:06 +0000)]
build-sys: make scanf_cv_alloc_modifier to work [LeakSanitizer]
The tests failed with following message in config.log
ERROR: LeakSanitizer: detected memory leaks
Direct leak of 2 byte(s) in 1 object(s) allocated from:
#0 0x49a40e in realloc (/home/src/util-linux/conftest+0x49a40e)
#1 0x7fbe48633e69 in __GI__IO_vfscanf (/usr/lib/libc.so.6+0x56e69)
#2 0x7fbe48649786 in _IO_vsscanf (/usr/lib/libc.so.6+0x6c786)
which knocked out libmount from build, and commands depending on it.
The reason this change makes sense is that AddressSanitizer seems like a
good addition to set of tools that util-linux package can use, when and
if needed.
Reference: https://code.google.com/p/address-sanitizer/wiki/AddressSanitizer Reviewed-by: Mike Frysinger <vapier@gentoo.org> Signed-off-by: Sami Kerola <kerolasa@iki.fi>
there is a theoretical buffer overflow possible in the hypervisor
parsing code of lscpu. It would require a proc entry to return way more
than expected so it's no high priority. But better be safe than sorry.
At first I thought about switching to fgets but there is another
code file that adds a format specifier. The diff is less intrusive
that way, too.
Boris Egorov [Fri, 14 Nov 2014 05:27:16 +0000 (11:27 +0600)]
libfdisk: fix get_partition_unused_primary()
Was:
Mentioned function returns -1 if adding of primary partition is
impossible. Caller treats this value as size_t (res variable) and then
compares it for negative values, totally ignoring errors.
Becomes:
Now function takes address to variable and fills it with partition
number. Caller treats return value as int and use it appropriately.
[kzak@redhat.com: - don't mix return code and partno at all]
Signed-off-by: Boris Egorov <egorov@linux.com> Signed-off-by: Karel Zak <kzak@redhat.com>