`--json` implies `--dump`, thus `--json --dump` must be
allowed. `--list-free` is incompatible with `--dump`, and thus also
with `--json`. Currently `--json --dump` is prohibited, even though
`--list-free` is not specified at all.
Karel Zak [Wed, 21 Oct 2020 09:08:11 +0000 (11:08 +0200)]
Merge branch 'ul-refactor' of https://github.com/kerolasa/util-linux
* 'ul-refactor' of https://github.com/kerolasa/util-linux:
ul: flip comparisons to lesser to greater order
ul: use size_t to measure memory allocation size
ul: improve function and variable names
ul: rename enumerated mode symbols
ul: remove function like putwp preprocessor define
ul: free most allocations ncurses did during setupterm()
ul: replace global runtime variables with a control structure
ul: add a term capabilities tracking structure
ul: remove function prototypes
ul: tidy up coding style
ul: add basic tests
Karel Zak [Wed, 21 Oct 2020 08:19:26 +0000 (10:19 +0200)]
cal: do not use putp(), directly use stdio functions
It seems our putp() based output is not portable as some ncurses
implementations strictly follow POSIX where putp() accepts only
terminfo capability strings and nothing else.
We already use standard stdio.h functions to output terminfo strings
(e.g. for colors). It seems we can do the same for cal(1) to
highlight the current day.
Note that mix putp() and fputs() is bad idea due to different
buffering ways in some cases (see cal.c git log for more details).
This patch also reduces complexity of the code as we can directly
output to stdout without snprintf to string.
Addresses: https://github.com/karelzak/util-linux/pull/1167 Signed-off-by: Karel Zak <kzak@redhat.com>
Sami Kerola [Fri, 16 Oct 2020 21:26:15 +0000 (22:26 +0100)]
ul: use size_t to measure memory allocation size
The size_t is the type libc memory allocation functions use. The size_t
also provides allocation range that is enough not to a simple tool like this
to perform paranoia size checks. Just let the realloc(3) fail if there is
not enough memory available to handle the requested line size. That is a
lot more straightforward.
Sami Kerola [Wed, 14 Oct 2020 21:51:37 +0000 (22:51 +0100)]
ul: rename enumerated mode symbols
First two are are ISO/IEC 2022 graphic character sets G0 (normal) and G1
(alternative), that one has to Switch In (SI) and Switch Out (SO). The rest
are about how ul(1) is interacting with various text emphasis.
Reference: https://tldp.org/HOWTO/Keyboard-and-Console-HOWTO-6.html Signed-off-by: Sami Kerola <kerolasa@iki.fi>
There's a couple of places which use varients on "0x%u" in format strings;
that's almost always wrong - you either want 0x%x or just %u. In libmount's
case it's flags, so I'm assuming the intention really is hex. In the ja.po
case it's %u in the original msgid.
Signed-off-by: Dr. David Alan Gilbert <dave@treblig.org>
Sami Kerola [Sun, 9 Aug 2020 11:59:38 +0000 (12:59 +0100)]
fsck, libblkid: fix printf format string issue [coverity scan]
According to coverirty a printf format string contains an unrecognized
format specifier (CWE-628). Lets avoid glibc extension "%m" that is same
as "%s", strerror(errno).
CID: 360699
CID: 360718 Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Dusty Mabe [Tue, 13 Oct 2020 15:26:16 +0000 (11:26 -0400)]
fstrim: remove fstab condition from fstrim.timer
In 9995da0 we added support to fstrim to be able to fall back to
`/proc/self/mountinfo` if `/etc/fstab` didn't exist, but we forgot
to remove the `/etc/fstab` condition from the timer. Let's remove
that condition from the timer so we can go back to periodically
running `fstrim.service`.
Karel Zak [Tue, 13 Oct 2020 08:31:42 +0000 (10:31 +0200)]
losetup: avoid infinite busy loop
issue report:
if i run the heavy duty test from #16859 a couple of times I can get
the loopback layer in the kernel into a state where there's a loopback
block device allocated, that you can open, but where both LOOP_CLR_FD
and _SET_FD fail with EBUSY. and /dev/loop-control still returns it as
the next free one... weird state util-linux losetup when called to
allocate a new device then freezes
This commit:
* restrict number of attempts to 16
* use 200000ms sleep between attempts
* add note about non-atomic loop device setup to the man page
Reported-by: Lennart Poettering <lennart@poettering.net> Signed-off-by: Karel Zak <kzak@redhat.com>
Karel Zak [Tue, 6 Oct 2020 11:26:36 +0000 (13:26 +0200)]
build-sys: exclude GPL from libcommon
The library is not distributed and almost all code in this ar(1)
archive is Public Domain or LGPL ... but let's avoid any doubts and do
not mix non-GPL and GPL code there.
Addresses: https://github.com/karelzak/util-linux/issues/1157 Signed-off-by: Karel Zak <kzak@redhat.com>
Karel Zak [Tue, 6 Oct 2020 11:15:29 +0000 (13:15 +0200)]
lib/procutils: use Public Domain for this file
It's was originally GPL, but all the current code in the file is from
me and I don't think it makes sense to use GPL here anymore. We need
to use lib/ files in LGPL as well as in GPL binaries, etc. Let's makes
things (build-system) less complicated.
Karel Zak [Thu, 1 Oct 2020 12:04:21 +0000 (14:04 +0200)]
login: use mem2strcpy() rather than rely on printf()
The strings from utmp does not have to be terminated. It's seems
better to explicitly terminate it than rely on "%.*s" printf()
functionality -- printf() man page assumes that "If a precision is
given, no null byte need be present", but static analyzers are pretty
unhappy with it.
Karel Zak [Wed, 30 Sep 2020 11:47:35 +0000 (13:47 +0200)]
col: enable deallocation on exit also for __SANITIZE_ADDRESS__
The macro FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION does not have to
enabled in all cases (e.g. default travis-ci, local tests, ...). It
seems more robust also check for __SANITIZE_ADDRESS__ too.
Addresses: https://github.com/karelzak/util-linux/pull/1115 Signed-off-by: Karel Zak <kzak@redhat.com>
Karel Zak [Wed, 30 Sep 2020 11:11:01 +0000 (13:11 +0200)]
libblkid: (gpt) accept tiny devices
GPT prober reads 2 first sectors. There is no overhead as we already
read begin of the device for another filesystems (like FAT) and we
have these sectors already in memory.
Addresses: https://github.com/karelzak/util-linux/issues/1147 Signed-off-by: Karel Zak <kzak@redhat.com>
Karel Zak [Wed, 30 Sep 2020 10:38:59 +0000 (12:38 +0200)]
libfdisk: (gpt) reduce number of entries to fit small device
The default is 128 partitions (entries in partitions array). The size
of the entry is 128 bytes, it means 32 sectors (512-byte) for the
array. The default is too large for tiny devices and it seems better to
dynamically reduce the number to fix the device size.
The reduction is reported to user.
Example:
$ dd if=/dev/zero of=8-sectors.img count=8 bs=512
$ fdisk 8-sectors.img
...
Command (m for help): g
Created a new GPT disklabel (GUID: 3DB3EECE-BCCA-6C46-95FA-7E23783BB3B2).
The maximal number of partitions is 8 (default is 128).
Command (m for help): x
Expert command (m for help): p
Disk 8-sectors.img: 4 KiB, 4096 bytes, 8 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 3DB3EECE-BCCA-6C46-95FA-7E23783BB3B2
First LBA: 4
Last LBA: 4
Alternative LBA: 7
Partition entries LBA: 2
Allocated partition entries: 8
In this case, sectors:
0 - PMBR
1 - GPT header
2-3 - GPT array of partitions (8 entries, 128 bytes each)
4 - partition data
5-6 - backup GPT array of partitions
7 - backup GPT header
The smallest image is 6 sectors with 4 entries in array of partitions.
Note that Linux kernel has no problem to accept 4K image with 1
512-bytes GPT partition.
# losetup -P -f 4K.img
# lsblk /dev/loop0
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
loop0 7:0 0 4K 0 loop
└─loop0p1 259:5 0 512B 0 part
... but we need to fix libblkid, it ignores so small devices to probe for GPT :)
Addresses: https://github.com/karelzak/util-linux/issues/1147 Signed-off-by: Karel Zak <kzak@redhat.com>
Karel Zak [Wed, 30 Sep 2020 09:44:03 +0000 (11:44 +0200)]
libfdisk: (gpt) make sure device is large enough
The current code creates GPT header and partitions arrays (with 128
entries ...) although there is no space for all the stuff. This patch
forces fdisk_create_disklabel() to return -ENOSPC if the last and first
usable LBA calculation is out of device size.
Addresses: https://github.com/karelzak/util-linux/issues/1147 Signed-off-by: Karel Zak <kzak@redhat.com>
Karel Zak [Tue, 29 Sep 2020 11:41:00 +0000 (13:41 +0200)]
Merge branch 'col-refactor' of https://github.com/kerolasa/util-linux
* 'col-refactor' of https://github.com/kerolasa/util-linux:
col: replace LINE and CHAR typedefs with structs
col: free memory before exit [LeakSanitizer]
col: tidy up sources a little bit
col: add defaults to switch case clauses
col: flip all comparisions to numerical order
col: use size_t when dealing with numbers that buffer sizes
col: add structure to hold line variables
col: add update_cur_line() function
col: add handle_not_graphic() function
col: initialize variables when they are declared
col: move option handling to separate function
col: move global variables to a control structure
col: use inline function rather than function like define
col: use typedef and enum to clarify struct
col: remove function prototypes
col: add more tests
ARM SBBR (Sever Base Boot Requirements) require SMBIOS tables, and
SMBIOS Type 4 describes the CPU manufacturer and model name (among other
details). If SMBIOS Type 4 is present, use it to extract these strings.
Example output (before and after the patch) on an HP m400, Lenovo HR330A,
and HPE Apollo 70:
[root@hpe-apollo-70 ~]# /usr/bin/lscpu | grep -i -e vendor -e model -e stepping
Vendor ID: Cavium
Model: 1
Model name: ThunderX2 99xx
Stepping: 0x1
[root@hpe-apollo-70 ~]# ./lscpu | grep -i -e vendor -e model -e stepping
Vendor ID: Cavium Inc.
Model: 1
Model name: Cavium ThunderX2(R) CPU CN9980 v2.1 @ 2.20GHz
Stepping: 0x1
[kzak@redhat.com: - move dmi_header to lscpu.h
- make arm_cpu_smbios() more robust for failed
open() and read()
- use original arm_cpu_decode() also on failed
arm_cpu_smbios()]
Signed-off-by: Jeffrey Bastian <jbastian@redhat.com> Signed-off-by: Karel Zak <kzak@redhat.com>
Karel Zak [Fri, 25 Sep 2020 15:23:18 +0000 (17:23 +0200)]
libmount: improve mnt_split_optstr() performance
This function is used by fstab (etc.) parser to split VFS, FS and
userspace options to separate lists. Unfortunately, the current
implementation reallocates the final string always when append a new
option to the string.
The new implementation pre-allocate memory for the final string
according to source string length (1/2 of the original string). This
dramatically reduces realloc() calls.
For example oss-fuzz (./test_mount_fuzz) uses 800K input string, old
version needs 28s to parse the string, new version 500ms.
Addresses: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=23861 Signed-off-by: Karel Zak <kzak@redhat.com>