Commit Graph

13388 Commits

Author SHA1 Message Date
Sami Kerola ff09a5129a
sulogin: fix variable / function shadowing [cppcheck]
[login-utils/sulogin.c:398] -> [login-utils/sulogin.c:171]: (style) Local
variable set shadows outer function
[login-utils/sulogin.c:398] -> [login-utils/sulogin.c:830]: (style) Local
variable set shadows outer function

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2019-05-18 22:41:58 +01:00
Sami Kerola 6dd7b74b3b
lscpu: remove redundant condition check [cppcheck]
[sys-utils/lscpu.c:1783] -> [sys-utils/lscpu.c:1785]: (warning) Either the
condition 'desc' is redundant or there is possible null pointer dereference: desc.
[sys-utils/lscpu.c:1840] -> [sys-utils/lscpu.c:1842]: (warning) Either the
condition 'desc' is redundant or there is possible null pointer dereference: desc.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2019-05-18 22:26:09 +01:00
Sami Kerola cbcedf6ba8
libmount: avoid possible null pointer dereference [cppcheck]
[libmount/src/monitor.c:797]: (warning) Possible null pointer dereference: me

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2019-05-18 22:17:10 +01:00
Sami Kerola 4f807791ee
lib/mangle: fix possible null pointer dereference [cppcheck]
Fix effects code that is used when testing util-linux, so quite low impact.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2019-05-18 22:09:25 +01:00
Sami Kerola 84f46d1f67
sfdisk: remove unnecessary size check [cppcheck]
Following warning is false positive.  Size of the buffer is defined using
BUFSIZ, and so the strncpy() will never overwrite the last byte that is
initialized to zero in get_user_reply().

[disk-utils/sfdisk.c:137] -> [disk-utils/sfdisk.c:136]: (warning) Either the
condition 'bufsz!=0' is redundant or strncpy() argument nr 3 can have
invalid value.  The value is -1 but the valid values are '0:'.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2019-05-18 22:07:20 +01:00
Karel Zak 4ac2ab97d1 Merge branch 'lscpu-output-fix' of https://github.com/kerolasa/util-linux
* 'lscpu-output-fix' of https://github.com/kerolasa/util-linux:
  lscpu: move trailing null after removing characters from a string
2019-05-16 13:31:30 +02:00
Sami Kerola b94acada9e
lscpu: move trailing null after removing characters from a string
From the test input string ':' characters are removed:

    cat x86_64-epyc_7451/sys/devices/system/cpu/vulnerabilities/spectre_v2
    Mitigation: Full AMD retpoline, IBPB: conditional, STIBP: disabled, RSB filling

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2019-05-16 11:45:47 +01:00
Karel Zak e2a0f26341 libsmartcols: (groups) improve scols_table_group_lines() args check [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-15 17:46:31 +02:00
Karel Zak cb400752a4 libmount: fix memory leak on error [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-15 17:25:04 +02:00
Karel Zak f11eedf527 libfdisk: avoid memory leak [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-15 17:12:38 +02:00
Karel Zak 845fd622ed libfdisk: avoid division by zero [clang scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-15 17:10:38 +02:00
Karel Zak 1d161441c2 libfdisk: remove unused code [clang scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-15 16:59:52 +02:00
Karel Zak 7f3a98229b libfdisk: properly check return code of add_to_partitions_array() [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-15 16:49:26 +02:00
Karel Zak 5b3b21128c libblkid: make partitions reference counting more robust [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-15 16:28:31 +02:00
Karel Zak 488b3a69df libblkid: don't ignore blkid_probe_set_magic() errors [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-15 16:24:51 +02:00
Karel Zak 709beed937 libblkid: fix possible uninitialized value use [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-15 16:15:15 +02:00
Karel Zak 6d92f7d7bf lib/strutils: keep static analyzer happy [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-15 16:09:16 +02:00
Karel Zak 91bf581742 lib/path: fix resource leak [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-15 16:01:32 +02:00
Karel Zak 8083862536 lib/path: fix possible NULL dereferencing [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-15 15:57:09 +02:00
Karel Zak 8e28151329 lib/path: fix ul_path_get_dirfd() usage [coverity scan]
ul_path_get_dirfd() returns negative number on error...

Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-15 15:52:54 +02:00
Karel Zak 2c417af196 lib/path: consolidate ul_path_mkpath() usage
* always use errno from ul_path_mkpath()
* keep code simple and short as possible

Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-15 15:47:29 +02:00
Karel Zak b24650294d lib/path: fix possible NULL pointer dereferencing [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-15 15:36:49 +02:00
Austin English 4b4a780539 column: fix "maybe be" duplication
Signed-off-by: Austin English <austinenglish@gmail.com>
2019-05-15 13:49:20 +02:00
Austin English 4669934b18 rtcwake: fix "maybe be" duplication
Signed-off-by: Austin English <austinenglish@gmail.com>
2019-05-15 13:49:13 +02:00
Austin English 381db76d01 mount: fix "maybe be" duplication
Signed-off-by: Austin English <austinenglish@gmail.com>
2019-05-15 13:49:04 +02:00
Austin English fd5f21ca45 lsblk: fix "maybe be" duplication
Signed-off-by: Austin English <austinenglish@gmail.com>
2019-05-15 13:48:54 +02:00
Austin English 9d71482941 libmount: fix "maybe be" duplication
Signed-off-by: Austin English <austinenglish@gmail.com>
2019-05-15 13:48:47 +02:00
Austin English 5cee62edc4 lib/colors: fix "maybe be" duplication
Signed-off-by: Austin English <austinenglish@gmail.com>
2019-05-15 13:48:34 +02:00
Karel Zak 3011b381e3 losetup: keep static analyzer happy [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-14 16:43:40 +02:00
Karel Zak dcf6f5b3d9 lib/colors: keep static analyzer happy [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-14 16:37:35 +02:00
Karel Zak 0ed52c662e lib/canonicalize: verify DM paths [coverity scan]
Now the code only checks that /sys/.../dm/name exists, but never
verify the device node in /dev (because path prefix is never NULL).

The prefix is used to redirect hardcoded paths to /sys dumps (e.g.
lsblk regression tests, etc.)

This bug has been introduced in v2.33. Fortunately, it's probably no
big issue as /dev is always in sync with /sys (thanks to udevd).

Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-14 15:47:02 +02:00
Karel Zak fbd2d01e23 build-sys: add PKG_INSTALLDIR fallback
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-14 15:25:07 +02:00
Karel Zak 89770db4ef fdisk: initialize buffers for get_user_reply() [coverity scan]
It's probably unnecessary, but better be safe than sorry.

Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-14 15:00:01 +02:00
Karel Zak 99f95a1ea9 build-sys: add --with-pkgconfigdir
It seems we need a way how to override the default pkg-config install directory.

default:
	$ ./configure
	$ grep 'pkgconfigdir ='  Makefile
	pkgconfigdir = ${usrlib_execdir}/pkgconfig

user-defined:
	$ ./configure --with-pkgconfigdir=/usr/share/pkgconfig
	$ grep 'pkgconfigdir ='  Makefile
	$ pkgconfigdir = /usr/share/pkgconfig

Addresses: https://github.com/karelzak/util-linux/issues/793
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-14 13:50:59 +02:00
Nikolay Borisov 99878f5dc4 libblkid: Set BLKID_BID_FL_VERIFIED in case revalidation is not needed
If blkid_verify deems that device revalidation is not needed since BLKID_PROBE_MIN
seconds haven't elapsed since the last revalidation of the device it returns
a blkid_dev. However, if this device has been read from the cache file on disk then
it wont' have BLKID_BID_FL_VERIFIED bit set. This in turn could lead to a later
call to blkid_dev_get free this device in case its part of a multi device
configuration. This is particularly relevant to btrfs raid configurations.

Namely this  was exhibited by btrfs-progs which use blkid for device enumeration.
In case of a multi-device filesystem (i.e raid10) running xfstest btrfs/011
would fail sporadically since cached devices read from cache were not revalidated
due to being recently validated (according to timestamp in the cache file) at
the same time their in-memory blkid_dev structures didn't have BLKID_BID_FL_VERIFIED
set. This lead to their untimely removal from the cache from blkid_get_dev.

Fix this by setting the BLKID_BID_FL_VERIFIED when returning from blkid_verify
with a valid device irrespective of whether full revalidation was performed or
the device is deemed valid due to being recently validated.

[kzak@redhat.com: - remove also check for BLKID_BID_FL_VERIFIED, the
                    function needs to check for elapsed time only]

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-14 13:35:58 +02:00
Nikolay Borisov 5de879b0f2 libblkid: Don't check BLKID_PROBE_INTERVAL in blkid_verify
That constant is set to 200 seconds and is already check in probe_all().
It essentially controls how often blkid_probe_all can do a full cache
revalidation. Since blkid_verify is called from within probe_all() iff at least
BLKID_PROBE_INTERVAL seconds have elapsed it makes no sense to check this value
in blkid_verify.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
2019-05-14 13:33:13 +02:00
Karel Zak 8c368dc6d3 lib/strutils: parse_size() fix frac digit calculation
Old code:

	./test_strutils --size 0.5MiB
		0.5MiB :               512000 :     500K :      500 KiB
	./test_strutils --size 0.50MiB
		0.50MiB :              5120000 :     4.9M :      4.9 MiB

New code:
	./test_strutils --size 0.5MiB
		0.5MiB :               524288 :     512K :      512 KiB
	./test_strutils --size 0.50MiB
	       0.50MiB :               524288 :     512K :      512 KiB

Note that the new implementation also does not use float points,
because we need to support PiB and so on... it seems good enough for
things like:

        ./test_strutils --size 7.13G
                7.13G :           7656104581 :     7.1G :      7.1 GiB
        ./test_strutils --size 7.16G
                7.16G :           7690675814 :     7.2G :      7.2 GiB

to avoid situation where cfdisk creates partition with completely
crazy numbers.

Addresses: https://github.com/karelzak/util-linux/issues/782
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-13 17:07:14 +02:00
Karel Zak 482e0a0754 lib/strutils: parse_size() fix frac with zeros
Fix 0.001G as well as accept 0.000G as valid number.

Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-13 16:15:58 +02:00
Karel Zak 5fcdf204b0 fstrim: affect only warnings by --quiet
We need the same return code from fstrim_filesystem() independently on
--quiet command line option.

Addresses: https://github.com/karelzak/util-linux/pull/791
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-09 13:59:54 +02:00
Karel Zak 0d71a25998 bash-completion: add fstrim --quiet
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-09 13:16:03 +02:00
Karel Zak ddd9ffb152 Merge branch 'fstrim-bug-789' of https://github.com/kerolasa/util-linux
* 'fstrim-bug-789' of https://github.com/kerolasa/util-linux:
  fstrim: add --quiet option to suppress error messages
2019-05-09 13:15:10 +02:00
Karel Zak cb055909c3 libmount: return errno on failed fstab stat()
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-09 10:09:34 +02:00
Sami Kerola 374baa6f64
fstrim: add --quiet option to suppress error messages
When fstrim interacts with NTFS it result can be error reporting bad file
descriptor.  That seems to be a bug in NTFS.  While waiting driver to get on
top of the issue and be commonly available lets add to fstrim option to make
it be more silent about errno 9 aka EBADF, Bad file descriptor.

Reported-by: https://github.com/moviuro
Proposed-by: Dave Reisner <dreisner@archlinux.org>
Reference: https://bugs.archlinux.org/task/62288
Addresses: https://github.com/karelzak/util-linux/issues/789
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2019-05-07 20:18:08 +01:00
Karel Zak 084365f1a1 build-sys: use __SANITIZE_ADDRESS__ rather than custom USE_CLOSE_ATEXIT
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-07 12:59:52 +02:00
Romain Izard eab90ef8d4 lib/loopdev.c: Retry LOOP_SET_STATUS64 on EAGAIN
A recent bugfix in the Linux kernel made it possible for the
LOOP_SET_STATUS64 ioctl to fail when called with a non-zero offset,
with an EAGAIN errno:

5db470e229e2 loop: drop caches if offset or block_size are changed

This fix changes a silent failure (where mount could sometimes access
the backing loop image through the cache without the specified offset)
to an explicit failure, and it has also been backported on stable
branches.

On a 5.0 kernel, other changes to the loop driver make it hard to get
generate the EAGAIN error, but this bugfix has also been backported to
stables branches, without these changes. At least with the 4.14 stable
branch, the EAGAIN error can be quickly generated with the following loop:

while mount -o loop,offset=239 disk point && umount point; do :; done

Retry the ioctl when it fails with EAGAIN, which means that mount or
losetup will eventually succeed when encountering this case.

[kzak@redhat.com: - use our local portable xusleep()]

Signed-off-by: Romain Izard <romain.izard.pro@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-07 12:36:00 +02:00
Karel Zak 47b6eccc97 libsmartcols: use scols_walk_* for calculations and printing
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-07 11:46:11 +02:00
Karel Zak 19c2e73116 libsmartcols: add generic function to walk on tree
Now we implement the same thing on more places. Let's add one set of
functions to walk the tree and use it everywhere.

Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-07 11:44:24 +02:00
Karel Zak f6f8a671a9 lsblk: fix heap-use-after-free
Addresses: https://github.com/karelzak/util-linux/issues/787
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-06 12:39:07 +02:00
Karel Zak 281a2f3212 libsmartcols: cell width calulation cleanup
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-03 17:27:17 +02:00
Karel Zak ea7fb72eb2 libsmartcols: (groups) use print functions tp calculate grpset
Now we have extra code to calculate grpset. It seems better to use
only one way how we wall the tree.

Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-03 17:12:18 +02:00