summaryrefslogtreecommitdiffstats
path: root/lib
Commit message (Collapse)AuthorAgeFilesLines
* misc: fix some printf format stringsRuediger Meier2017-08-161-2/+4
| | | | | | Noticed on xcode/OSX. Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* lib/randutils: reset lose counterKarel Zak2017-08-141-1/+1
| | | | | | | It's probaly good idea to reset lose counter when we fallback from getrandom() to /dev/urandom. Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/randutils: improve getrandom() usageKarel Zak2017-08-141-18/+46
| | | | | | | | | | | | | | | | | | | | The getrandom() does not have to return all requested bytes (missing entropy or when interrupted by signal). The current implementation in util-linux stupidly asks for all random data again, rather than only for missing bytes. The current code also does not care if we repeat our requests for ever; that's bad. This patch uses the same way as we already use for reading from /dev/urandom. It means: * repeat getrandom() for only missing bytes * limit number of unsuccessful request (16 times) * fallback to /dev/urandom on ENOSYS (old kernel or so...) Addresses: https://github.com/karelzak/util-linux/issues/496 Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/randutils.c: More paranoia in getrandom() call.Christopher James Halse Rogers2017-08-081-1/+1
| | | | | | | | If getrandom() is called with nbytes ≥ 256 then it can return with less than the requested bytes filled. In this case we *could* adjust the buffer by the number of bytes actually read, but it's simpler to just redo the call.
* lib/randutils.c: Fall back gracefully when kernel doesn't support getrandom(2).Christopher James Halse Rogers2017-08-081-18/+26
| | | | | | | The 3.16 kernel is supported until 2020, and various distros have kernels of the same vintage. It's entirely possible for code built against newer headers to be run against these kernels, so fall-back to the old “read /dev/{u,}random” method if the kernel doesn' support getrandom()
* parse-date: fix printf formatRuediger Meier2017-07-181-1/+1
| | | | | | | | | | warning on 32bit systems: ../lib/parse-date.y: In function 'parse_date': ../lib/parse-date.y:1509:7: warning: format '%ld' expects argument of type 'long int', but argument 4 has type 'intmax_t' [-Wformat=] abs_time_zone_min); ^ Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* libblkid: don't use CDROM_GET_CAPABILITY ioctl for DM devicesKarel Zak2017-07-121-7/+11
| | | | | | | | | For some reason kernel commit e980f62353c697cbf0c4325e43df6e44399aeb64 add extra warning when the ioctl is used for DM devices. It seems we can avoid this ioctl when the device has dm/uuid. Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1469532 Signed-off-by: Karel Zak <kzak@redhat.com>
* Merge branch 'path-fixes' of https://github.com/rudimeier/util-linuxKarel Zak2017-06-292-17/+40
|\ | | | | | | | | | | | | | | | | | | | | | | * 'path-fixes' of https://github.com/rudimeier/util-linux: hwclock: don't ifdef printf arguments setpriv: align --help tools: add segfault detection for checkusage.sh misc: avoid some dead initialization warnings lscpu: make clang analyzer happy lsmem: fix, using freed memory lib/path: add error handling to path_vcreate() lib/path: fix crash, pathbuf overflow
| * misc: avoid some dead initialization warningsRuediger Meier2017-06-291-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Clang analyzer warnings: Dead store, Dead initialization: lib/mbsedit.c:154:8: warning: Value stored to 'in' during its initialization is never read char *in = (char *) &c; ^~ ~~~~~~~~~~~ misc-utils/findmnt-verify.c:129:14: warning: Value stored to 'cn' during its initialization is never read const char *cn = tgt; ^~ ~~~ Dead store, Dead increment: sys-utils/hwclock.c:1461:2: warning: Value stored to 'argv' is never read argv += optind; ^ ~~~~~~ Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
| * lsmem: fix, using freed memoryRuediger Meier2017-06-291-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | Simply avoiding strdup(). Error handling improved. This was the Clang Analyzer warning: Memory Error, Use-after-free sys-utils/lsmem.c:259:3: warning: Use of memory after it is freed err(EXIT_FAILURE, _("Failed to open %s"), path); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
| * lib/path: add error handling to path_vcreate()Ruediger Meier2017-06-291-9/+25
| | | | | | | | | | | | | | Do not operate on truncated/random paths. Note, path_strdup() can now really return NULL, to be handled in next commit. Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
| * lib/path: fix crash, pathbuf overflowRuediger Meier2017-06-271-4/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Before: $ lscpu -s "$(tr '\0' 'x' < /dev/zero | head -c 10000)" Segmentation fault (core dumped) After: $ lscpu -s "$(tr '\0' 'x' < /dev/zero | head -c 10000)" lscpu: invalid argument to --sysroot: File name too long Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* | lib/blkdev: remove support for Linux < 2.6Ruediger Meier2017-06-291-11/+2Star
|/ | | | | | Remove a hack for kernels between 2.4.15 and 2.4.17 Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* lib: fix strutils.h, remove STRTOXX_EXIT_CODERuediger Meier2017-06-221-0/+6
| | | | | | | | | As discussed on the mailing list. We fix all places where the non-working define STRTOXX_EXIT_CODE was used. Regarding tunelp, also see 7e3c80a7. Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* Merge branch '170424' of github.com:jwpi/util-linuxKarel Zak2017-06-201-103/+77Star
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | * '170424' of github.com:jwpi/util-linux: parse-date: time_zone_hhmm() bug fixes parse-date: remove unused ordinal_day_seen parse-date: remove unused year_seen parse-date: refactor tm_diff() parse-date: use to_uchar() instead of assignment. parse-date: use uintmax_t where appropriate parse-date: use int where appropriate parse-date: use intmax_t where appropriate parse-date: remove unused EPOCH_YEAR parse-date: replace ISDIGIT with c_isdigit
| * parse-date: time_zone_hhmm() bug fixesJ William Piggott2017-06-151-35/+33Star
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * fix incorrect arg type used for abs(). * prevent integer arithmetic overflow by limiting offset to 4 digits. * don't accept malformed offset values like: -4:3 +12:719 +0000001:23 -9:00000001 +0000001123 Reported-by: Ruediger Meier <ruediger.meier@ga-group.nl> Influenced-by: gnulib 30784c4 Paul Eggert <eggert@cs.ucla.edu> Signed-off-by: J William Piggott <elseifthen@gmx.com>
| * parse-date: remove unused ordinal_day_seenJ William Piggott2017-06-151-6/+0Star
| | | | | | | | Signed-off-by: J William Piggott <elseifthen@gmx.com>
| * parse-date: remove unused year_seenJ William Piggott2017-06-151-3/+0Star
| | | | | | | | Signed-off-by: J William Piggott <elseifthen@gmx.com>
| * parse-date: refactor tm_diff()J William Piggott2017-06-151-3/+2Star
| | | | | | | | | | | | Reported-by: Ruediger Meier <ruediger.meier@ga-group.nl> Influenced-by: gnulib 30784c4 Paul Eggert <eggert@cs.ucla.edu> Signed-off-by: J William Piggott <elseifthen@gmx.com>
| * parse-date: use to_uchar() instead of assignment.J William Piggott2017-06-151-4/+2Star
| | | | | | | | | | | | Reported-by: Ruediger Meier <ruediger.meier@ga-group.nl> Influenced-by: gnulib 30784c4 Paul Eggert <eggert@cs.ucla.edu> Signed-off-by: J William Piggott <elseifthen@gmx.com>
| * parse-date: use uintmax_t where appropriateJ William Piggott2017-06-151-4/+4
| | | | | | | | | | | | Reported-by: Ruediger Meier <ruediger.meier@ga-group.nl> Influenced-by: gnulib 30784c4 Paul Eggert <eggert@cs.ucla.edu> Signed-off-by: J William Piggott <elseifthen@gmx.com>
| * parse-date: use int where appropriateJ William Piggott2017-06-151-6/+6
| | | | | | | | | | | | Reported-by: Ruediger Meier <ruediger.meier@ga-group.nl> Influenced-by: gnulib 30784c4 Paul Eggert <eggert@cs.ucla.edu> Signed-off-by: J William Piggott <elseifthen@gmx.com>
| * parse-date: use intmax_t where appropriateJ William Piggott2017-06-151-28/+28
| | | | | | | | | | | | Reported-by: Ruediger Meier <ruediger.meier@ga-group.nl> Influenced-by: gnulib 30784c4 Paul Eggert <eggert@cs.ucla.edu> Signed-off-by: J William Piggott <elseifthen@gmx.com>
| * parse-date: remove unused EPOCH_YEARJ William Piggott2017-06-151-1/+0Star
| | | | | | | | | | | | Reported-by: Ruediger Meier <ruediger.meier@ga-group.nl> Influenced-by: gnulib 30784c4 Paul Eggert <eggert@cs.ucla.edu> Signed-off-by: J William Piggott <elseifthen@gmx.com>
| * parse-date: replace ISDIGIT with c_isdigitJ William Piggott2017-06-151-18/+7Star
| | | | | | | | | | | | Reported-by: Ruediger Meier <ruediger.meier@ga-group.nl> Influenced-by: gnulib 30784c4 Paul Eggert <eggert@cs.ucla.edu> Signed-off-by: J William Piggott <elseifthen@gmx.com>
* | lib: style cosmetics plymouth-ctrl.cRuediger Meier2017-06-151-11/+7Star
|/ | | | Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* lib: remove _RLD_ from forbid environment variable listSami Kerola2017-06-141-1/+0Star
| | | | | | | | | | | The RLD environment variables are related to runtime linker vulnerability in TELNET on systems running Silicon Graphics IRIX. It is extremely unlikely current util-linux would be compiled on such system. Reference: http://www.cert.org/historical/advisories/CA-1995-14.cfm Reference: http://signatures.juniper.net/documentation/signatures/TELNET%3AEXPLOIT%3ASGI-RLD.html Refefence: http://www.polarhome.com/service/man/?qf=rld&tf=2&of=IRIX&sf=1 Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* lib: simplify cpuset if clauses that returnSami Kerola2017-06-141-7/+5Star
| | | | | | | | There is no need for 'else' when 'if' will return. In same go move call of tolower() to last possible moment in char_to_val(), a lot of time hex values should hit 0-9 range, and it can be omitted. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* misc: remove stray semicolonsSami Kerola2017-06-141-1/+1
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* misc: fix gcc-7 snprintf warnings -Wformat-truncationRuediger Meier2017-06-142-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ../lib/loopdev.c: In function 'loopcxt_next_from_sysfs': ../lib/loopdev.c:545:32: warning: '/loop/backing_file' directive output may be truncated writing 18 bytes into a region of size between 1 and 256 [-Wformat-truncation=] snprintf(name, sizeof(name), "%s/loop/backing_file", d->d_name); ^~~~~~~~~~~~~~~~~~~~~~ ../lib/loopdev.c:545:3: note: 'snprintf' output between 19 and 274 bytes into a destination of size 256 snprintf(name, sizeof(name), "%s/loop/backing_file", d->d_name); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../lib/sysfs.c: In function 'sysfs_is_partition_dirent': ../lib/sysfs.c:343:31: warning: '/start' directive output may be truncated writing 6 bytes into a region of size between 1 and 256 [-Wformat-truncation=] snprintf(path, sizeof(path), "%s/start", d->d_name); ^~~~~~~~~~ ../lib/sysfs.c:343:2: note: 'snprintf' output between 7 and 262 bytes into a destination of size 256 snprintf(path, sizeof(path), "%s/start", d->d_name); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../lib/sysfs.c: In function 'sysfs_partno_to_devno': ../lib/sysfs.c:372:32: warning: '/partition' directive output may be truncated writing 10 bytes into a region of size between 1 and 256 [-Wformat-truncation=] snprintf(path, sizeof(path), "%s/partition", d->d_name); ^~~~~~~~~~~~~~ ../lib/sysfs.c:372:3: note: 'snprintf' output between 11 and 266 bytes into a destination of size 256 snprintf(path, sizeof(path), "%s/partition", d->d_name); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../lib/sysfs.c:377:33: warning: '/dev' directive output may be truncated writing 4 bytes into a region of size between 1 and 256 [-Wformat-truncation=] snprintf(path, sizeof(path), "%s/dev", d->d_name); ^~~~~~~~ ../lib/sysfs.c:377:4: note: 'snprintf' output between 5 and 260 bytes into a destination of size 256 snprintf(path, sizeof(path), "%s/dev", d->d_name); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* lib/ttyutils: return terminal lines tooKarel Zak2017-06-121-19/+49
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/pager: use xallocKarel Zak2017-06-021-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/pager: don't use pager if command not availableKarel Zak2017-06-011-0/+36
| | | | | | | | | | | | | | | | | | for example: # PAGER=foo dmesg -H sh: foo: command not found the same problem is we have with fdisk 'l' command: # PAGER=foo fdisk /dev/sda Welcome to fdisk (util-linux 2.30-rc2-33-41b71). ... Command (m for help): l sh: foo: command not found It seems better to don't use pager at all if not available. Signed-off-by: Karel Zak <kzak@redhat.com>
* misc: fix some warningsRuediger Meier2017-06-011-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | sys-utils/prlimit.c: In function 'do_prlimit': sys-utils/prlimit.c:367:16: warning: format '%ju' expects argument of type 'uintmax_t', but argument 2 has type 'rlim_t {aka long long unsigned int}' [-Wformat=] printf("<%ju", new->rlim_cur); lib/plymouth-ctrl.c: In function 'open_un_socket_and_connect': lib/plymouth-ctrl.c:88:20: warning: passing argument 2 of 'connect' from incompatible pointer type [-Wincompatible-pointer-types] ret = connect(fd, &su, offsetof(struct sockaddr_un, sun_path) + 1 + strlen(su.sun_path+1)); ^ In file included from lib/plymouth-ctrl.c:35:0: /usr/include/sys/socket.h:314:5: note: expected 'const struct sockaddr *' but argument is of type 'struct sockaddr_un *' int connect (int, const struct sockaddr *, socklen_t); login-utils/last.c: In function 'list': login-utils/last.c:506:54: warning: pointer targets in passing argument 4 of 'dns_lookup' differ in signedness [-Wpointer-sign] r = dns_lookup(domain, sizeof(domain), ctl->useip, p->ut_addr_v6); ^ login-utils/last.c:291:12: note: expected 'int32_t * {aka int *}' but argument is of type 'unsigned int *' static int dns_lookup(char *result, int size, int useip, int32_t *a) ^~~~~~~~~~ In file included from sys-utils/hwclock-cmos.c:92:0: sys-utils/hwclock.h:67:32: warning: 'struct timeval' declared inside parameter list will not be visible outside of this definition or declaration extern double time_diff(struct timeval subtrahend, struct timeval subtractor); misc-utils/test_uuidd.c: In function 'create_nthreads': misc-utils/test_uuidd.c:187:19: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast] proc->pid, (int) th->tid, th->index)); Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* build-sys: fix library order when linkingRuediger Meier2017-06-011-1/+1
| | | | | | | | | | We got some errors on Alpine Linux where $LTLIBINTL is non-empty: ./.libs/libcommon.a(libcommon_la-blkdev.o): In function `open_blkdev_or_file': lib/blkdev.c:282: undefined reference to `libintl_gettext collect2: error: ld returned 1 exit status Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* build-sys: ncurses headers cleanupKarel Zak2017-05-311-4/+11
| | | | | | | | | * assume ncursesw headers in ncursesw/ directory only * prefer long paths, <term.h> and <ncurses.h> should be last possibility * fix typos Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/colors: fix test compilationKarel Zak2017-05-311-2/+2
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/colors: ncurses cleanupKarel Zak2017-05-302-9/+27
| | | | | | | | | * use proper paths to term.h * keep ncurses support optional * link with TINFO_LIBS (-ltinfo), or fallback to NCURSES_LIBS (-ltinfo -lncurses) * don't include unnecessary ncurses.h (term.h is enough) Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/loopdev: remove unnecessary headerKarel Zak2017-05-301-1/+0Star
| | | | | Reported-by: Assaf Gordon <assafgordon@gmail.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/parse-date: don't use xalloc in lib-like codeKarel Zak2017-05-121-3/+12
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* build-sys: remove duplicate includesKarel Zak2017-05-121-1/+0Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/mbsedit: fix typo in commentSami Kerola2017-05-101-1/+1
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* lib/timer: add commentKarel Zak2017-04-281-0/+17
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/timer.c: prevent pathological race conditionRasmus Villemoes2017-04-261-4/+6
| | | | | | | | | | | | | | | | | | | | | | | | | flock(1) uses the timer facility to interrupt a blocking flock(2) call. However, in a pathological case (or with a sufficiently short timeout), the timer may fire and the signal be delivered after the timer is set up, but before we get around to doing the flock(2) call. In that case, we'd block forever. Checking timeout_expired right before calling flock(2) does not eliminate that race, so the only option is to make the timer fire repeatedly. Having the timer fire after we've returned from flock(2) is not a problem, since we only check timeout_expired in case of EINTR (also, this firing after return could also happen with the current code). There is currently one other user of setup_timer (misc-utils/uuidd.c), but in that case the signal handler simply exits. Future users of setup_timer obviously need to ensure that they can tolerate multiple signal deliveries. Choosing 1% of the initial timeout as the repeating interval is somewhat arbitrary. However, I put a lower bound of 0.01s, since setting the interval much smaller than this may end up effectively live-locking the process, handling a never-ending stream of signals. Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
* lib/timer.c: remove bogus SA_SIGINFO from timer_settime callRasmus Villemoes2017-04-261-1/+1
| | | | | | | | | The only valid flag for timer_settime is TIMER_ABSTIME, which we certainly don't want here. This seems to be harmless since timer_settime doesn't validate the flags parameter, TIMER_ABSTIME is universally 0x1, and no architecture has SA_SIGINFO == 1. Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
* parse-date: remove extraneous form feedJ William Piggott2017-04-101-2/+0Star
| | | | | | * lib/parse-date.y: Remove extraneous form feed (FF, 0x0C, ^L). Signed-off-by: J William Piggott <elseifthen@gmx.com>
* Merge branch '2017wk13' of https://github.com/kerolasa/lelux-utiliteetitKarel Zak2017-04-041-1/+0Star
|\ | | | | | | | | | | | | | | * '2017wk13' of https://github.com/kerolasa/lelux-utiliteetit: docs: improve agetty.8 manual page agetty: make --remote to forward --nohostname as -H to login lib/cpuset: stop changing variable that is not read agetty: remove variable that is set but not read
| * lib/cpuset: stop changing variable that is not readSami Kerola2017-04-011-1/+0Star
| | | | | | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* | lib/strutils: fix typos in huge size suffixesKarel Zak2017-04-031-3/+3
|/ | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* agetty: fix characters reorder in login promptKarel Zak2017-03-271-4/+0Star
| | | | | | | | | | | | | | The current agetty uses TIOCSTI ioctl to return already read chars from login name back to the terminal (without read() before tcsetattr() we will lost data already written by user). The ioctl based solution is fragile due to race -- we can return chars when terminal already contains another new chars. The result is reordered chars in login name. The solution is to use extra buffer for already read data. Reported-by: Michael Tretter <m.tretter@pengutronix.de> Signed-off-by: Karel Zak <kzak@redhat.com>