]> git.ipfire.org Git - thirdparty/util-linux.git/log
thirdparty/util-linux.git
11 months agolib/path: fix typos
Tobias Stoeckmann [Sun, 8 Oct 2023 18:51:07 +0000 (20:51 +0200)] 
lib/path: fix typos

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
11 months agolib/path: remove ul_prefix_fopen
Tobias Stoeckmann [Sun, 8 Oct 2023 18:49:31 +0000 (20:49 +0200)] 
lib/path: remove ul_prefix_fopen

The function ul_prefix_fopen does not properly check for paths which are
too long. Since the only caller of ul_prefix_fopen can be easily
converted to ul_path_fopen, remove the function.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
11 months agolib/path: set errno in case of error
Tobias Stoeckmann [Sun, 8 Oct 2023 18:47:53 +0000 (20:47 +0200)] 
lib/path: set errno in case of error

Some programs like lscpu expect errno to be set if ul_path_cpuparse
fails.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
11 months agolib/path: fix possible out of boundary access
Tobias Stoeckmann [Sun, 8 Oct 2023 18:41:29 +0000 (20:41 +0200)] 
lib/path: fix possible out of boundary access

If fgets reads from a file starting with a NUL byte in ul_path_cpuparse,
then the check for newline leads to an out of boundary access.

Proof of Concept (compile with --enable-asan):

1. Prepare /tmp/poc with required files
```
$ install -d /tmp/poc/sys/devices/system/cpu
$ dd if=/dev/zero of=/tmp/poc/sys/devices/system/cpu/possible bs=1 count=1
$ install -D /dev/null /tmp/poc/proc/cpuinfo
```

2. Run lscpu with sysroot option
```
$ lscpu --sysroot /tmp/poc
=================================================================
==78238==ERROR: AddressSanitizer: heap-buffer-overflow
```

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
11 months agoMerge branch 'libblkid/align' of https://github.com/t-8ch/util-linux
Karel Zak [Wed, 4 Oct 2023 18:08:06 +0000 (20:08 +0200)] 
Merge branch 'libblkid/align' of https://github.com/t-8ch/util-linux

* 'libblkid/align' of https://github.com/t-8ch/util-linux:
  libblkid: (probe) remove chunking from blkid_probe_get_idmag()
  libblkid: (probe) read data in chunks
  swapon: (tests) abort test on failing commands
  libblkid: reset errno before calling probefuncs
  libfdisk: reset errno before calling read()

11 months agolibblkid: (probe) remove chunking from blkid_probe_get_idmag()
Thomas Weißschuh [Sun, 1 Oct 2023 12:24:04 +0000 (14:24 +0200)] 
libblkid: (probe) remove chunking from blkid_probe_get_idmag()

blkid_probe_get_buffer is doing the same thing internally now.

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
11 months agolibblkid: (probe) read data in chunks
Thomas Weißschuh [Sat, 30 Sep 2023 21:59:44 +0000 (23:59 +0200)] 
libblkid: (probe) read data in chunks

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
11 months agoMerge branch 'libmount/tab-uaf' of https://github.com/t-8ch/util-linux
Karel Zak [Wed, 4 Oct 2023 18:03:02 +0000 (20:03 +0200)] 
Merge branch 'libmount/tab-uaf' of https://github.com/t-8ch/util-linux

* 'libmount/tab-uaf' of https://github.com/t-8ch/util-linux:
  Revert "libmount: (tab) avoid leaking memory allocated in loop"

11 months agoMerge branch 'setpriv/completion' of https://github.com/t-8ch/util-linux
Karel Zak [Wed, 4 Oct 2023 17:57:21 +0000 (19:57 +0200)] 
Merge branch 'setpriv/completion' of https://github.com/t-8ch/util-linux

* 'setpriv/completion' of https://github.com/t-8ch/util-linux:
  setpriv: fix group argument completion

11 months agoMerge branch 'libfdisk/errno' of https://github.com/t-8ch/util-linux
Karel Zak [Wed, 4 Oct 2023 17:56:39 +0000 (19:56 +0200)] 
Merge branch 'libfdisk/errno' of https://github.com/t-8ch/util-linux

* 'libfdisk/errno' of https://github.com/t-8ch/util-linux:
  libfdisk: reset errno before calling read()

11 months agoMerge branch 'ci/musl' of https://github.com/t-8ch/util-linux
Karel Zak [Wed, 4 Oct 2023 17:35:26 +0000 (19:35 +0200)] 
Merge branch 'ci/musl' of https://github.com/t-8ch/util-linux

* 'ci/musl' of https://github.com/t-8ch/util-linux:
  ci: run full testsuite under musl libc
  build-sys: only build col on glibc
  lib/timeutils: don't use glibc strptime extension

11 months agoRevert "libmount: (tab) avoid leaking memory allocated in loop"
Thomas Weißschuh [Wed, 4 Oct 2023 15:21:47 +0000 (17:21 +0200)] 
Revert "libmount: (tab) avoid leaking memory allocated in loop"

coverity claims that this is now a use-after-free.
Let's revert the original change and make the code clearer before trying
another fix.

This reverts commit d36306a560fd6d747e18ab22fc1279f4a373f43d.

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
11 months agoswapon: (tests) abort test on failing commands
Thomas Weißschuh [Mon, 2 Oct 2023 16:17:01 +0000 (18:17 +0200)] 
swapon: (tests) abort test on failing commands

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
11 months agolibblkid: reset errno before calling probefuncs
Thomas Weißschuh [Mon, 2 Oct 2023 20:24:21 +0000 (22:24 +0200)] 
libblkid: reset errno before calling probefuncs

The probers optionally use errno to communicate error details.
When a leftover errno is set from libblkid internally this can confuse
the probers.

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
11 months agosetpriv: fix group argument completion
Thomas Weißschuh [Mon, 2 Oct 2023 13:52:33 +0000 (15:52 +0200)] 
setpriv: fix group argument completion

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
11 months agolibfdisk: reset errno before calling read()
Thomas Weißschuh [Mon, 2 Oct 2023 11:01:47 +0000 (13:01 +0200)] 
libfdisk: reset errno before calling read()

The else branch will be executed on short reads.
For those errno is not reset so a random left-over errno value may be
checked.

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
11 months agolibfdisk: reset errno before calling read()
Thomas Weißschuh [Mon, 2 Oct 2023 11:01:47 +0000 (13:01 +0200)] 
libfdisk: reset errno before calling read()

The else branch will be executed on short reads.
For those errno is not reset so a random left-over errno value may be
checked.

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
11 months agoMerge branch 'blkid/exclusive-opts' of https://github.com/t-8ch/util-linux
Karel Zak [Mon, 2 Oct 2023 10:42:11 +0000 (12:42 +0200)] 
Merge branch 'blkid/exclusive-opts' of https://github.com/t-8ch/util-linux

* 'blkid/exclusive-opts' of https://github.com/t-8ch/util-linux:
  blkid: fix call to err_exclusive_options

11 months agoMerge branch 'https-everywhere' of https://github.com/jwilk-forks/util-linux
Karel Zak [Mon, 2 Oct 2023 10:41:51 +0000 (12:41 +0200)] 
Merge branch 'https-everywhere' of https://github.com/jwilk-forks/util-linux

* 'https-everywhere' of https://github.com/jwilk-forks/util-linux:
  docs: use HTTPS for GitHub clone URLs

11 months agoMerge branch 'libblkid/lvm-small-device' of https://github.com/t-8ch/util-linux
Karel Zak [Mon, 2 Oct 2023 10:41:17 +0000 (12:41 +0200)] 
Merge branch 'libblkid/lvm-small-device' of https://github.com/t-8ch/util-linux

* 'libblkid/lvm-small-device' of https://github.com/t-8ch/util-linux:
  libblkid: (lvm2) read complete superblock

11 months agoMerge branch 'libblkid/drbd-simplify' of https://github.com/t-8ch/util-linux
Karel Zak [Mon, 2 Oct 2023 10:40:55 +0000 (12:40 +0200)] 
Merge branch 'libblkid/drbd-simplify' of https://github.com/t-8ch/util-linux

* 'libblkid/drbd-simplify' of https://github.com/t-8ch/util-linux:
  libblkid: (drbd) avoid unaligned accesses
  include/c.h: add helpers for unaligned structure access
  libblkid: (drbd) use magics
  libblkid: (probe) allow superblock offset from end of device
  libblkid: (cramfs) use magic hint
  libblkid: (probe) add magic hint
  libblkid: (drbd) validate size in standard minsz predicate
  libblkid: (via_raid) validate size in standard minsz predicate
  libblkid: (silicon_raid) validate size in standard minsz predicate
  libblkid: (promise_raid) validate size in standard minsz predicate
  libblkid: (nvidia_raid) validate size in standard minsz predicate
  libblkid: (lsi_raid) validate size in standard minsz predicate
  libblkid: (jmicron_raid) validate size in standard minsz predicate
  libblkid: (isw_raid) validate size in standard minsz predicate
  libblkid: (highpoint_raid) validate size in standard minsz predicate
  libblkid: (ddf_raid) validate size in standard minsz predicate
  libblkid: (adapted_raid) validate size in standard minsz predicate
  libblkid: (probe) remove duplicate log

11 months agoMerge branch 'analyzer2' of https://github.com/t-8ch/util-linux
Karel Zak [Mon, 2 Oct 2023 10:40:38 +0000 (12:40 +0200)] 
Merge branch 'analyzer2' of https://github.com/t-8ch/util-linux

* 'analyzer2' of https://github.com/t-8ch/util-linux:
  libblkid: (probe) handle probe without chain gracefully
  libsmartcols: (cell) consistently handle NULL argument
  lib/idcache: always gracefully handle null cache
  script-playutils: close filestream in case ignore_line() fails
  lib/colors: correct documentation of colors_add_scheme()
  treewide: use reallocarray to allocated memory that will be reallocated

11 months agoMerge branch 'libmount/tab-leak' of https://github.com/t-8ch/util-linux
Karel Zak [Mon, 2 Oct 2023 10:37:52 +0000 (12:37 +0200)] 
Merge branch 'libmount/tab-leak' of https://github.com/t-8ch/util-linux

* 'libmount/tab-leak' of https://github.com/t-8ch/util-linux:
  libmount: (tab) avoid leaking memory allocated in loop

11 months agoMerge branch 'lsfd--bpf-name#in-flight' of https://github.com/masatake/util-linux
Karel Zak [Mon, 2 Oct 2023 10:37:30 +0000 (12:37 +0200)] 
Merge branch 'lsfd--bpf-name#in-flight' of https://github.com/masatake/util-linux

* 'lsfd--bpf-name#in-flight' of https://github.com/masatake/util-linux:
  tests: (lsfd) extend the cases for testing BPF.NAME column
  lsfd.1.adoc: document BPF.NAME column
  lsfd: add BPF.NAME column
  lsfd: add xstrfappend and xstrvfappend
  lib/strutils: add strfappend and strvfappend
  tests: (test_mkfds::{bpf-prog,bpf-map}) fix memory leaks
  tests: (test_mkfds) add missing PARAM_END marker
  tests: (test_mkfds) use SYS_bpf instead of __NR_bpf
  tests: (test_mkfds) revise the usage of " __attribute__((__unused__))"
  tests: (lsfd::mkfds-bpf-map) chmod a+x

11 months agolsblk: improve --tree description
Karel Zak [Mon, 2 Oct 2023 09:51:56 +0000 (11:51 +0200)] 
lsblk: improve --tree description

Addresses: https://github.com/util-linux/util-linux/issues/2516
Signed-off-by: Karel Zak <kzak@redhat.com>
11 months agoblkid: fix call to err_exclusive_options
Thomas Weißschuh [Mon, 2 Oct 2023 09:39:53 +0000 (11:39 +0200)] 
blkid: fix call to err_exclusive_options

err_exclusive_options needs to be passed the long options array,
otherwise it will crash.

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
11 months agodocs: use HTTPS for GitHub clone URLs
Jakub Wilk [Mon, 2 Oct 2023 05:22:54 +0000 (07:22 +0200)] 
docs: use HTTPS for GitHub clone URLs

GitHub has dropped support for the git:// protocol:
https://github.blog/changelog/2022-03-15-removed-unencrypted-git-protocol-and-certain-ssh-keys/

11 months agolibmount: (tab) avoid leaking memory allocated in loop
Thomas Weißschuh [Wed, 27 Sep 2023 18:37:22 +0000 (20:37 +0200)] 
libmount: (tab) avoid leaking memory allocated in loop

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
11 months agolibblkid: (lvm2) read complete superblock
Thomas Weißschuh [Sun, 1 Oct 2023 09:48:01 +0000 (11:48 +0200)] 
libblkid: (lvm2) read complete superblock

The lvm2_calc_crc() will create a checksum over LVM2_LABEL_SIZE bytes,
which all need to be read.

Currently this works because the superblock is cached by
blkid_probe_get_idmag() which always reads 1024 bytes.

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
11 months agolibblkid: (drbd) avoid unaligned accesses
Thomas Weißschuh [Sun, 1 Oct 2023 11:57:43 +0000 (13:57 +0200)] 
libblkid: (drbd) avoid unaligned accesses

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
11 months agoinclude/c.h: add helpers for unaligned structure access
Thomas Weißschuh [Sun, 1 Oct 2023 11:57:12 +0000 (13:57 +0200)] 
include/c.h: add helpers for unaligned structure access

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
11 months agolibblkid: (drbd) use magics
Thomas Weißschuh [Sat, 30 Sep 2023 21:58:05 +0000 (23:58 +0200)] 
libblkid: (drbd) use magics

Reuse more of the standard prober functionality.
This also avoids a potential unaligned access when comparing the
superblock magic as a number.
In case the superblock was already cached by a different loader the
return address may have been unaligned leading to undefined behavior.

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
11 months agolibblkid: (probe) allow superblock offset from end of device
Thomas Weißschuh [Sat, 30 Sep 2023 21:56:46 +0000 (23:56 +0200)] 
libblkid: (probe) allow superblock offset from end of device

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
11 months agolibblkid: (cramfs) use magic hint
Thomas Weißschuh [Sun, 1 Oct 2023 08:29:48 +0000 (10:29 +0200)] 
libblkid: (cramfs) use magic hint

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
11 months agolibblkid: (probe) add magic hint
Thomas Weißschuh [Sat, 30 Sep 2023 21:55:31 +0000 (23:55 +0200)] 
libblkid: (probe) add magic hint

This hint can be used by the probing callback to make decision based on
the matched magic. This avoids a awkward memcmp() on the magic string.

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
11 months agolibblkid: (drbd) validate size in standard minsz predicate
Thomas Weißschuh [Sat, 30 Sep 2023 21:21:33 +0000 (23:21 +0200)] 
libblkid: (drbd) validate size in standard minsz predicate

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
11 months agolibblkid: (via_raid) validate size in standard minsz predicate
Thomas Weißschuh [Sat, 30 Sep 2023 22:08:40 +0000 (00:08 +0200)] 
libblkid: (via_raid) validate size in standard minsz predicate

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
11 months agolibblkid: (silicon_raid) validate size in standard minsz predicate
Thomas Weißschuh [Sat, 30 Sep 2023 22:08:31 +0000 (00:08 +0200)] 
libblkid: (silicon_raid) validate size in standard minsz predicate

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
11 months agolibblkid: (promise_raid) validate size in standard minsz predicate
Thomas Weißschuh [Sat, 30 Sep 2023 22:08:23 +0000 (00:08 +0200)] 
libblkid: (promise_raid) validate size in standard minsz predicate

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
11 months agolibblkid: (nvidia_raid) validate size in standard minsz predicate
Thomas Weißschuh [Sat, 30 Sep 2023 22:08:12 +0000 (00:08 +0200)] 
libblkid: (nvidia_raid) validate size in standard minsz predicate

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
11 months agolibblkid: (lsi_raid) validate size in standard minsz predicate
Thomas Weißschuh [Sat, 30 Sep 2023 22:08:06 +0000 (00:08 +0200)] 
libblkid: (lsi_raid) validate size in standard minsz predicate

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
11 months agolibblkid: (jmicron_raid) validate size in standard minsz predicate
Thomas Weißschuh [Sat, 30 Sep 2023 22:07:59 +0000 (00:07 +0200)] 
libblkid: (jmicron_raid) validate size in standard minsz predicate

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
11 months agolibblkid: (isw_raid) validate size in standard minsz predicate
Thomas Weißschuh [Sat, 30 Sep 2023 22:07:22 +0000 (00:07 +0200)] 
libblkid: (isw_raid) validate size in standard minsz predicate

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
11 months agolibblkid: (highpoint_raid) validate size in standard minsz predicate
Thomas Weißschuh [Sat, 30 Sep 2023 22:07:13 +0000 (00:07 +0200)] 
libblkid: (highpoint_raid) validate size in standard minsz predicate

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
11 months agolibblkid: (ddf_raid) validate size in standard minsz predicate
Thomas Weißschuh [Sat, 30 Sep 2023 22:07:02 +0000 (00:07 +0200)] 
libblkid: (ddf_raid) validate size in standard minsz predicate

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
11 months agolibblkid: (adapted_raid) validate size in standard minsz predicate
Thomas Weißschuh [Sat, 30 Sep 2023 22:06:53 +0000 (00:06 +0200)] 
libblkid: (adapted_raid) validate size in standard minsz predicate

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
11 months agolibblkid: (probe) remove duplicate log
Thomas Weißschuh [Sat, 30 Sep 2023 21:05:21 +0000 (23:05 +0200)] 
libblkid: (probe) remove duplicate log

remove_buffer() already emits the same message.

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
11 months agotests: (lsfd) extend the cases for testing BPF.NAME column
Masatake YAMATO [Tue, 26 Sep 2023 16:15:21 +0000 (01:15 +0900)] 
tests: (lsfd) extend the cases for testing BPF.NAME column

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
11 months agolsfd.1.adoc: document BPF.NAME column
Masatake YAMATO [Tue, 26 Sep 2023 15:51:26 +0000 (00:51 +0900)] 
lsfd.1.adoc: document BPF.NAME column

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
11 months agolsfd: add BPF.NAME column
Masatake YAMATO [Tue, 26 Sep 2023 16:12:16 +0000 (01:12 +0900)] 
lsfd: add BPF.NAME column

An example output:

  $ sudo  ./lsfd -oCOMMAND,PID,ASSOC,TYPE,BPF.NAME,NAME -Q '(TYPE =~ "bpf-*")' -p 1
  COMMAND PID ASSOC     TYPE        BPF.NAME NAME
  systemd   1     9 bpf_link                 anon_inode:bpf_link
  systemd   1    13  bpf-map     cgroup_hash id=391 type=hash-of-maps name=cgroup_hash
  systemd   1    14 bpf-prog restrict_filesy id=8210 type=lsm name=restrict_filesy
  systemd   1    28 bpf-prog      sd_devices id=8298 type=cgroup_device name=sd_devices
  systemd   1    29 bpf-prog      sd_devices id=8299 type=cgroup_device name=sd_devices
  systemd   1    30 bpf-prog      sd_devices id=8300 type=cgroup_device name=sd_devices
  ...

Using memset was suggested by Thomas Weißschuh
<thomas@t-8ch.de>.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
11 months agolsfd: add xstrfappend and xstrvfappend
Masatake YAMATO [Fri, 29 Sep 2023 20:26:48 +0000 (05:26 +0900)] 
lsfd: add xstrfappend and xstrvfappend

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
11 months agolib/strutils: add strfappend and strvfappend
Masatake YAMATO [Fri, 29 Sep 2023 20:21:40 +0000 (05:21 +0900)] 
lib/strutils: add strfappend and strvfappend

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
11 months agotests: (test_mkfds::{bpf-prog,bpf-map}) fix memory leaks
Masatake YAMATO [Tue, 26 Sep 2023 16:04:54 +0000 (01:04 +0900)] 
tests: (test_mkfds::{bpf-prog,bpf-map}) fix memory leaks

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
11 months agotests: (test_mkfds) add missing PARAM_END marker
Masatake YAMATO [Tue, 26 Sep 2023 16:01:58 +0000 (01:01 +0900)] 
tests: (test_mkfds) add missing PARAM_END marker

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
11 months agotests: (test_mkfds) use SYS_bpf instead of __NR_bpf
Masatake YAMATO [Tue, 26 Sep 2023 16:01:12 +0000 (01:01 +0900)] 
tests: (test_mkfds) use SYS_bpf instead of __NR_bpf

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
11 months agotests: (test_mkfds) revise the usage of " __attribute__((__unused__))"
Masatake YAMATO [Tue, 26 Sep 2023 15:58:55 +0000 (00:58 +0900)] 
tests: (test_mkfds) revise the usage of " __attribute__((__unused__))"

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
11 months agotests: (lsfd::mkfds-bpf-map) chmod a+x
Masatake YAMATO [Fri, 29 Sep 2023 20:28:58 +0000 (05:28 +0900)] 
tests: (lsfd::mkfds-bpf-map) chmod a+x

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
11 months agolibblkid: (probe) handle probe without chain gracefully
Thomas Weißschuh [Wed, 27 Sep 2023 22:51:42 +0000 (00:51 +0200)] 
libblkid: (probe) handle probe without chain gracefully

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
11 months agolibsmartcols: (cell) consistently handle NULL argument
Thomas Weißschuh [Thu, 28 Sep 2023 06:24:10 +0000 (08:24 +0200)] 
libsmartcols: (cell) consistently handle NULL argument

Some functions allow passing NULL, some don't.
Even users internal to util-linux are passing NULL parameters to these
functions, even for ones where it is not allowed.

Unify the API. As there may be external users that rely on the
NULL-accepting behavior for some functions use it everywhere.

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
11 months agolib/idcache: always gracefully handle null cache
Thomas Weißschuh [Wed, 27 Sep 2023 22:40:28 +0000 (00:40 +0200)] 
lib/idcache: always gracefully handle null cache

The "get" functions already do this and some callers rely on it also for
"add" ones.

For completeness also handle it in free_idcache().

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
11 months agoscript-playutils: close filestream in case ignore_line() fails
Thomas Weißschuh [Wed, 27 Sep 2023 21:30:27 +0000 (23:30 +0200)] 
script-playutils: close filestream in case ignore_line() fails

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
11 months agolib/colors: correct documentation of colors_add_scheme()
Thomas Weißschuh [Wed, 27 Sep 2023 20:04:40 +0000 (22:04 +0200)] 
lib/colors: correct documentation of colors_add_scheme()

The function does not take ownership of its arguments and it does not
require those arguments to be heap-allocated.
In fact there is only one caller and it passed stack-allocated values.

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
11 months agotreewide: use reallocarray to allocated memory that will be reallocated
Thomas Weißschuh [Wed, 27 Sep 2023 19:03:08 +0000 (21:03 +0200)] 
treewide: use reallocarray to allocated memory that will be reallocated

GCC 13 -fanalyzer expects memory that is passed to reallocarray() to
have been allocated with reallocarray() in the first place and not with
malloc().

While this requirement seems to contradict the documentation, the usage
of reallocarray() is better than the current plain malloc() in any case.

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
11 months agoci: run full testsuite under musl libc
Thomas Weißschuh [Sat, 16 Sep 2023 10:03:06 +0000 (12:03 +0200)] 
ci: run full testsuite under musl libc

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
11 months agobuild-sys: only build col on glibc
Thomas Weißschuh [Wed, 27 Sep 2023 17:53:55 +0000 (19:53 +0200)] 
build-sys: only build col on glibc

col expects an EILSEQ failure of getwchar() to leave the undecoded data
in the buffer to be read by a subsequent getchar().

This is not guaranteed by the standard and for example musl libc does
not conform to this expectation.

As col is deprecated anyways just disable it on non-glibc instead of fixing it.

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
11 months agolib/timeutils: don't use glibc strptime extension
Thomas Weißschuh [Sat, 23 Sep 2023 08:24:58 +0000 (10:24 +0200)] 
lib/timeutils: don't use glibc strptime extension

strptime("%s") is a glibc extension and for example not available on
musl. Reimplement the functionality in a cross-platform way.

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
12 months agoMerge branch 'libblkid/vxfs-endianness' of https://github.com/t-8ch/util-linux
Karel Zak [Wed, 27 Sep 2023 08:35:12 +0000 (10:35 +0200)] 
Merge branch 'libblkid/vxfs-endianness' of https://github.com/t-8ch/util-linux

* 'libblkid/vxfs-endianness' of https://github.com/t-8ch/util-linux:
  libblkid: (vxfs) report endianness

12 months agoMerge branch 'libblkid/bcachefs/label_sub' of https://github.com/t-8ch/util-linux
Karel Zak [Wed, 27 Sep 2023 08:34:47 +0000 (10:34 +0200)] 
Merge branch 'libblkid/bcachefs/label_sub' of https://github.com/t-8ch/util-linux

* 'libblkid/bcachefs/label_sub' of https://github.com/t-8ch/util-linux:
  libblkid: (bcachefs) add support for sub-device labels

12 months agolibblkid: (vxfs) report endianness
Thomas Weißschuh [Tue, 26 Sep 2023 22:49:04 +0000 (00:49 +0200)] 
libblkid: (vxfs) report endianness

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
12 months agolibblkid: (bcachefs) add support for sub-device labels
Thomas Weißschuh [Tue, 26 Sep 2023 07:43:35 +0000 (09:43 +0200)] 
libblkid: (bcachefs) add support for sub-device labels

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
12 months agolibblkid: (ntfs) validate that sector_size is a power of two
Thomas Weißschuh [Mon, 25 Sep 2023 22:27:22 +0000 (00:27 +0200)] 
libblkid: (ntfs) validate that sector_size is a power of two

The NTFS prober reads data based off an offset of the sector size.
If the sector size is unaligned and the read data is cached then other
probers can read unaligned values.

Sector sizes for NTFS actually only make sense as power-of-two so
validate that and as a sideeffect avoid the unaligned reads.

Also add the reproducer from OSS-Fuzz that found this issue.

Fixes #2509

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
12 months agoMerge branch 'login-terminal' of https://github.com/stoeckmann/util-linux
Karel Zak [Mon, 25 Sep 2023 10:44:46 +0000 (12:44 +0200)] 
Merge branch 'login-terminal' of https://github.com/stoeckmann/util-linux

* 'login-terminal' of https://github.com/stoeckmann/util-linux:
  login: prevent undefined ioctl and tcsetattr calls
  login: use correct terminal fd during setup

12 months agoMerge branch 'timestamp' of https://github.com/t-8ch/util-linux
Karel Zak [Mon, 25 Sep 2023 10:35:48 +0000 (12:35 +0200)] 
Merge branch 'timestamp' of https://github.com/t-8ch/util-linux

* 'timestamp' of https://github.com/t-8ch/util-linux:
  lib/timeutils: (parse_timestamp_reference) report errors on overflow
  lib/timeutils: print error if timestamp can't be parsed
  lib/timeutils: test epoch timestamp

12 months agoMerge branch 'ci/cache-openwrt-sdk' of https://github.com/t-8ch/util-linux
Karel Zak [Mon, 25 Sep 2023 10:34:47 +0000 (12:34 +0200)] 
Merge branch 'ci/cache-openwrt-sdk' of https://github.com/t-8ch/util-linux

* 'ci/cache-openwrt-sdk' of https://github.com/t-8ch/util-linux:
  ci: cache openwrt sdk

12 months agoMerge branch 'ci/gcc-13' of https://github.com/t-8ch/util-linux
Karel Zak [Mon, 25 Sep 2023 10:33:29 +0000 (12:33 +0200)] 
Merge branch 'ci/gcc-13' of https://github.com/t-8ch/util-linux

* 'ci/gcc-13' of https://github.com/t-8ch/util-linux:
  ci: also use GCC 13 for sanitizer builds
  ci: don't combine -Werror and -fsanitize

12 months agoMerge branch 'analyzer1' of https://github.com/t-8ch/util-linux
Karel Zak [Mon, 25 Sep 2023 10:32:25 +0000 (12:32 +0200)] 
Merge branch 'analyzer1' of https://github.com/t-8ch/util-linux

* 'analyzer1' of https://github.com/t-8ch/util-linux:
  libsmartcols: handle nameless tables in export format
  ldattach: don't call exit() from signal handler
  lslogins: fix realloc() loop allocation size
  more: avoid out-of-bound access
  libfdisk: handle allocation failure in fdisk_new_partition
  lib/env: fix function name remote_entry -> remove_entry
  libmount: gracefully handle NULL path in mnt_resolve_target()
  libblkid: avoid memory leak of cachefile path
  lib/env: avoid underflow of read_all_alloc() return value

12 months agoMerge branch 'realloc' of https://github.com/t-8ch/util-linux
Karel Zak [Mon, 25 Sep 2023 10:30:37 +0000 (12:30 +0200)] 
Merge branch 'realloc' of https://github.com/t-8ch/util-linux

* 'realloc' of https://github.com/t-8ch/util-linux:
  treewide: use (x)reallocarray() when applicable

12 months agoMerge branch 'ci/clang-17' of https://github.com/t-8ch/util-linux
Karel Zak [Mon, 25 Sep 2023 10:29:38 +0000 (12:29 +0200)] 
Merge branch 'ci/clang-17' of https://github.com/t-8ch/util-linux

* 'ci/clang-17' of https://github.com/t-8ch/util-linux:
  ci: build with clang 17

12 months agoMerge branch 'login-comment' of https://github.com/stoeckmann/util-linux
Karel Zak [Mon, 25 Sep 2023 10:28:07 +0000 (12:28 +0200)] 
Merge branch 'login-comment' of https://github.com/stoeckmann/util-linux

* 'login-comment' of https://github.com/stoeckmann/util-linux:
  login: Use pid_t for child_pid
  login: move comment

12 months agoMerge branch 'lsfd--resolve-mqueue-nodev' of https://github.com/masatake/util-linux
Karel Zak [Mon, 25 Sep 2023 10:22:54 +0000 (12:22 +0200)] 
Merge branch 'lsfd--resolve-mqueue-nodev' of https://github.com/masatake/util-linux

* 'lsfd--resolve-mqueue-nodev' of https://github.com/masatake/util-linux:
  lsfd: collect the device number for mqueue fs in the initialization stage
  tests: (lsfd) show the entry for mqueue in /proc/self/mountinfo

12 months agolib/timeutils: (parse_timestamp_reference) report errors on overflow
Thomas Weißschuh [Sun, 24 Sep 2023 21:43:44 +0000 (23:43 +0200)] 
lib/timeutils: (parse_timestamp_reference) report errors on overflow

Instead of silently returning '0' on 'minus'-underflow and silently
wrapping on 'plus'-overflow return ERANGE.

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
12 months agolib/timeutils: print error if timestamp can't be parsed
Thomas Weißschuh [Sun, 24 Sep 2023 21:32:08 +0000 (23:32 +0200)] 
lib/timeutils: print error if timestamp can't be parsed

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
12 months agolib/timeutils: test epoch timestamp
Thomas Weißschuh [Sun, 24 Sep 2023 21:14:34 +0000 (23:14 +0200)] 
lib/timeutils: test epoch timestamp

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
12 months agoci: cache openwrt sdk
Thomas Weißschuh [Fri, 22 Sep 2023 20:03:34 +0000 (22:03 +0200)] 
ci: cache openwrt sdk

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
12 months agoci: also use GCC 13 for sanitizer builds
Thomas Weißschuh [Fri, 22 Sep 2023 18:38:13 +0000 (20:38 +0200)] 
ci: also use GCC 13 for sanitizer builds

Now that -Werror is not used anymore with -fsanitize the false-postives
are not a problem anymore and we get the better runtime checks of newer
sanitizers.

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
12 months agoci: don't combine -Werror and -fsanitize
Thomas Weißschuh [Fri, 22 Sep 2023 09:19:24 +0000 (11:19 +0200)] 
ci: don't combine -Werror and -fsanitize

As explained in [0]:

    Note that sanitizers tend to increase the rate of false positive
    warnings, most notably those around -Wmaybe-uninitialized. We recommend
    against combining -Werror and [the use of] sanitizers.

[0] https://gcc.gnu.org/onlinedocs/gcc-13.2.0/gcc/Instrumentation-Options.html#index-fsanitize_003dundefined

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
12 months agolibsmartcols: handle nameless tables in export format
Thomas Weißschuh [Fri, 22 Sep 2023 09:20:36 +0000 (11:20 +0200)] 
libsmartcols: handle nameless tables in export format

fputs(NULL) is not allowed.

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
12 months agoldattach: don't call exit() from signal handler
Thomas Weißschuh [Fri, 22 Sep 2023 18:21:38 +0000 (20:21 +0200)] 
ldattach: don't call exit() from signal handler

Instead use _exit().

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
12 months agolslogins: fix realloc() loop allocation size
Thomas Weißschuh [Fri, 22 Sep 2023 18:08:22 +0000 (20:08 +0200)] 
lslogins: fix realloc() loop allocation size

If stat() fails the realloc loop would always try to allocate zero
bytes.

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
12 months agomore: avoid out-of-bound access
Thomas Weißschuh [Fri, 22 Sep 2023 17:53:24 +0000 (19:53 +0200)] 
more: avoid out-of-bound access

The realloc() needs to happen before that memory is used.

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
12 months agolibfdisk: handle allocation failure in fdisk_new_partition
Thomas Weißschuh [Fri, 22 Sep 2023 17:35:01 +0000 (19:35 +0200)] 
libfdisk: handle allocation failure in fdisk_new_partition

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
12 months agolib/env: fix function name remote_entry -> remove_entry
Thomas Weißschuh [Fri, 22 Sep 2023 17:34:03 +0000 (19:34 +0200)] 
lib/env: fix function name remote_entry -> remove_entry

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
12 months agolibmount: gracefully handle NULL path in mnt_resolve_target()
Thomas Weißschuh [Fri, 22 Sep 2023 09:30:57 +0000 (11:30 +0200)] 
libmount: gracefully handle NULL path in mnt_resolve_target()

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
12 months agolibblkid: avoid memory leak of cachefile path
Thomas Weißschuh [Fri, 22 Sep 2023 09:20:04 +0000 (11:20 +0200)] 
libblkid: avoid memory leak of cachefile path

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
12 months agolib/env: avoid underflow of read_all_alloc() return value
Thomas Weißschuh [Fri, 22 Sep 2023 09:19:37 +0000 (11:19 +0200)] 
lib/env: avoid underflow of read_all_alloc() return value

read_all_alloc() returns a negative error on failure.
When casting this to an unsigned type the failure check "< 1"
will not work.

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
12 months agotreewide: use (x)reallocarray() when applicable
Thomas Weißschuh [Fri, 22 Sep 2023 09:56:42 +0000 (11:56 +0200)] 
treewide: use (x)reallocarray() when applicable

reallocarray() prevents overflow of the multiplication.
It also avoids issues with operator precedence like in libmount/src/context.c:

    pids = realloc(cxt->children, sizeof(pid_t) * cxt->nchildren + 1);

This only allocated one additional byte, and not enough space for
another child.

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
12 months agologin: prevent undefined ioctl and tcsetattr calls
Tobias Stoeckmann [Thu, 21 Sep 2023 18:25:55 +0000 (20:25 +0200)] 
login: prevent undefined ioctl and tcsetattr calls

Do not call tcsetattr if tcgetattr fails, because the content of
tt and ttt is undefined in that case.

Also do not just warn if ioctl fails, but also avoid calling it again
after tty has been re-opened.

I've solved this by setting struct variables to values which cannot be
valid at this point. If they do have these exact values, then the
calls will be prevented.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
12 months agologin: use correct terminal fd during setup
Tobias Stoeckmann [Thu, 21 Sep 2023 18:15:46 +0000 (20:15 +0200)] 
login: use correct terminal fd during setup

The function get_terminal_name iterates through standard file
descriptors until it finds a terminal. This means that it's not
guaranteed that STDIN_FILENO (i.e. 0) is actually a terminal.

Do not modify permissions on possible files. Instead, retrieve
the file descriptor which was used by get_terminal_name as well.

Proof of Concept (as root):

1. Create a temporary file with a mode different than TTYPERM.
```
install -m 700 /dev/null /tmp/test
ls -l /tmp/test
-rwx------ 1 root root 0 Sep 21 20:15 /tmp/test
```

2. Run login within a terminal with adjusted stdin.
```
login < /tmp/test
host login:
            Hangup
```

3. Check permissions of input file.
```
ls -l /tmp/test
-rw------- 1 root root 0 Sep 21 20:15 /tmp/test
```

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
12 months agoci: build with clang 17
Thomas Weißschuh [Wed, 20 Sep 2023 21:31:04 +0000 (23:31 +0200)] 
ci: build with clang 17

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
12 months agologin: Use pid_t for child_pid
Tobias Stoeckmann [Tue, 19 Sep 2023 18:45:40 +0000 (20:45 +0200)] 
login: Use pid_t for child_pid

Since child_pid keeps track of a PID, it should be of type pid_t
and not of type int.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>