summaryrefslogtreecommitdiffstats
path: root/lib
Commit message (Collapse)AuthorAgeFilesLines
...
* | lib/sha1: use ul_/UL_prefix for symbolsKarel Zak2017-12-121-17/+17
| | | | | | | | | | | | | | | | Unfortunately, the symbols are visible in statically compiled libuuid and the names are too generic. Addresses: https://github.com/karelzak/util-linux/issues/548 Signed-off-by: Karel Zak <kzak@redhat.com>
* | lib/timeutils.c: warn format_iso_time() overflowJ William Piggott2017-12-101-6/+9
| | | | | | | | | | | | | | | | | | Print a message when the format_iso_time() buffer is exceeded, because there is more than one type of failure that returns -1. Also remove the corresponding message from hwclock.c. Signed-off-by: J William Piggott <elseifthen@gmx.com>
* | lib/timeutils.c:strxxx_iso: do not wrap tm_yearJ William Piggott2017-12-091-4/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Year can wrap when adding the tm struct epoch during iso formatting: hwclock --utc --noadjfile --predict --date '67768034678844900 seconds' -2147481749-12-31 23:59:59.000000-05:00 Patched: hwclock --utc --noadjfile --predict --date '67768034678844900 seconds' 2147485547-12-31 23:59:59.000000-05:00 Comparable to date(1): date -Ins --date '67768034678844900 seconds' 2147485547-12-31T23:59:59,547886165-0500 Note: the 'seconds' argument is relative to the current time, so reaching this max year output is a moving target. The values shown above were invalid one second later. They then overflow tm_year upon conversion with localtime(3) and friends, which causes them to return NULL indicating that an error occurred. Signed-off-by: J William Piggott <elseifthen@gmx.com>
* | lib/timeutils.c:strxxx_iso: test conversion errorsJ William Piggott2017-12-091-6/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Test for libc time conversion errors in ISO time format functions. hwclock --utc --noadjfile --predict --date '67768034678846520 seconds' Segmentation fault Patched: hwclock --utc --noadjfile --predict --date '67768034678846520 seconds' hwclock: time 67768036191695381 is out of range. Comparable to date(1): date --date '67768034678846520 seconds' date: time 67768036191695384 is out of range Signed-off-by: J William Piggott <elseifthen@gmx.com>
* | lib/timeutils.c: bug fix Segmentation faultJ William Piggott2017-12-091-4/+4
|/ | | | | | | | | | | | | | | Use reentrant time functions to avoid sending a NULL pointer to format_iso_time() (and to be reentrant ;). Followup commits test for errors and tm_year wrapping (illustrated below). hwclock --utc --noadjfile --predict --date '67768034678849400 seconds' Segmentation fault Patched hwclock --utc --noadjfile --predict --date '67768034678849400 seconds' -2147481748-01-00 00:10:46.000000-05:00 Signed-off-by: J William Piggott <elseifthen@gmx.com>
* lib/signames: remove unused functionSami Kerola2017-11-281-5/+0Star
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* lib/mbsalign: add mbs_invalid_encode()Karel Zak2017-11-221-0/+80
| | | | | | Like mbs_safe_encode(), but it does not care about control chars. Signed-off-by: Karel Zak <kzak@redhat.com>
* lib: Add simple crc32c() functionJohn Groves2017-11-162-0/+103
| | | | | | | | Source: freebsd/sys/libkern/crc32.c This code is an unmodified fragment from the source. Will fixup comments / naming in next commit Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/timeutils: add common ISO timestamp masksJ William Piggott2017-11-101-17/+15Star
| | | | | | | | | | | | | | | | | | | | | | * Start the ISO format flags at bit 0 instead of bit 1. * Remove unnecessary _8601 from ISO format flag names to avoid line wrapping and to ease readability. * ISO timestamps have date-time-timzone in common, so move the TIMEZONE flag to bit 2 causing all timestamp masks to have the first three bits set and the last four bits as timestamp 'options'. * Change the 'SPACE' flag to a 'T' flag, because it makes the code and comments more concise. * Add common ISO timestamp masks. * Implement the ISO timestamp masks in all applicable code using the strxxx_iso() functions. Signed-off-by: J William Piggott <elseifthen@gmx.com>
* lib/timeutils: add get_gmtoff()J William Piggott2017-11-101-2/+66
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This new function returns the GMT offset relative to its argument. It is used in this patch to fix two bugs: 1) On platforms that the tm struct excludes tm_gmtoff, hwclock assumes a one hour DST offset. This can cause an incorrect kernel timezone setting. For example: Master branch tested with tm_gmtoff illustrates the correct offset: $ TZ="Australia/Lord_Howe" hwclock --hctosys --test | grep settimeofday Calling settimeofday(1507494204.192398, -660) Master branch tested without tm_gmtoff has an incorrect offset: $ TZ="Australia/Lord_Howe" hwclock --hctosys --test | grep settimeofday Calling settimeofday(1507494249.193852, -690) Patched tested without tm_gmtoff has the correct offset: $ TZ="Australia/Lord_Howe" hwclock --hctosys --test | grep settimeofday Calling settimeofday(1507494260.194208, -660) 2) ISO 8601 'extended' format requires all time elements to use a colon (:). Current invalid ISO 8601: $ hwclock 2017-10-08 16:25:17.895462-0400 Patched: $ hwclock 2017-10-08 16:25:34.141895-04:00 Also required by this change: login-utils/last.c: increase ISO out_len and in_len by one to accommodate the addition of the timezone colon. Signed-off-by: J William Piggott <elseifthen@gmx.com>
* md5: declare byteReverse as staticLuca Ceresoli2017-11-081-2/+2
| | | | | | | | | | | | | byteReverse() is an internal function in md5.c, and is not exposed via any header file, but it is not declared as static. This is a problem with the md5.c file since it is copied more or less verbatim in other programs (fontconfig and pjsip among others), causing a link error when linking two of them together. Fixes link failures such as: http://autobuild.buildroot.net/results/419ab2c0e034cc68991281c51caa8271b0fadbab/build-end.log Signed-off-by: Luca Ceresoli <luca@lucaceresoli.net>
* lib/mangle: return size of the decoded bufferKarel Zak2017-11-011-2/+4
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/path: make path_set_prefix() independent on cpu_set_tKarel Zak2017-10-231-15/+14Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/signames: fix redefinition of 'sys_signame' on OSXKarel Zak2017-10-231-12/+12
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/signames: remove signame array from header fileKarel Zak2017-10-231-1/+115
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* signames: Make input char buffers constNiklas Hambüchen2017-10-141-2/+2
|
* kill: Extract signal names into signames.h/signames.cNiklas Hambüchen2017-10-142-1/+97
|
* lib/pager: check open() return code [coverity scan]Karel Zak2017-10-111-0/+2
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/mbsedit: check wctomb() return code [coverity scan]Karel Zak2017-10-111-0/+2
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* losetup: fix conflicting types for ‘loopcxt_set_blocksize’Karel Zak2017-10-041-2/+6
| | | | | Reported-by: Lars Wendler <polynomial-c@gentoo.org> Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/randutils: remove superfluous continueKarel Zak2017-10-021-6/+3Star
| | | | | Addresses: https://github.com/karelzak/util-linux/commit/fa949792072530b49ef5760d7ecd6d250c66e35f#commitcomment-24678670 Signed-off-by: Karel Zak <kzak@redhat.com>
* losetup: Add support for logical block sizeStanislav Brabec2017-09-271-0/+50
| | | | | | | | | | | | | | | | | | | | Kernel since 4.14 supports setting of logical block size[1]. It allows to create loop devices that report logical block size different from 512. Add support for this feature to losetup. References: [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/drivers/block/loop.c?id=89e4fdecb51cf5535867026274bc97de9480ade5 [kzak@redhat.com: - fix loopcxt_get_blocksize() - remove lo_blocksize from loop_info64] Signed-off-by: Stanislav Brabec <sbrabec@suse.cz> Cc: Ming Lei <ming.lei@redhat.com> Cc: Hannes Reinecke <hare@suse.com> Cc: Omar Sandoval <osandov@fb.com> Cc: Jens Axboe <axboe@kernel.dk> Signed-off-by: Karel Zak <kzak@redhat.com>
* setproctitle: fix out of boundary accessTobias Stoeckmann2017-09-261-5/+6
| | | | | | | | | | | | | A program using setproctitle can trigger an out of boundary access if an attacker was able to clear the environment before execution. The check in setproctitle prevents overflows, but does not take into account that the whole length of the arguments could be 1, which is possible by supplying such a program name to execlp(3) or using a symbolic link, e.g. argv[0] = "l", argv[1] = NULL. Only login uses setproctitle, which is not affected by this problem due to initializing the environment right before the call.
* lib/pwdutils: add xgetlogin()Karel Zak2017-09-181-3/+35
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* login: add xgetpwnam()Karel Zak2017-09-182-0/+69
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libuuid: add support for hash-based UUIDsPhilip Prindeville2017-09-052-1/+298
| | | | | | | | | Adding V3 and V5 UUIDs per RFC-4122. [kzak@redhat.com: - fix symbols file] Signed-off-by: Philip Prindeville <philipp@redfish-solutions.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/match: make match_fstype() case insensitiveKarel Zak2017-08-311-2/+2
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* 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>