Commit Graph

14615 Commits

Author SHA1 Message Date
Mauricio Faria de Oliveira 477239ce0d rename: fix regression for symlink with non-existing target
Since commit 5454df9c31 ("rename: check source file access early")
rename fails early for symlinks with non-existing target (regression),
because access() dereferences the link.

From access(2):

  "access() checks whether the calling process can access the file pathname.
   If pathname is a symbolic link, it is dereferenced."

Thus replace access() with faccessat() and lstat() as fallback,
(as in do_symlink()), that is equivalent for symlink and files.

From fsaccess(2) and stat(2):

  "The faccessat() system call operates in exactly the same way as access(),
   except for the differences described here.
   [...]
   If pathname is relative and dirfd is the special value AT_FDCWD, then pathname
   is interpreted relative to the current working directory of the calling process
   (like access()).
   [...]
   AT_SYMLINK_NOFOLLOW
     If pathname is a symbolic link, do not dereference it:
     instead return information about the link itself."

  "lstat() is identical to stat(), except that if pathname is a symbolic link, then
   it returns information about  the  link  itself, not the file that it refers to."

Testing
-------

  1) symlink with existing target
  2) symlink with non-existing target
  3) non-existing symlink
  4) existing file
  5) non-existing file

Before:

  $ touch file-found
  $ ln -s file-found symlink-1
  $ ./rename sym symbolic- symlink-1	# XPASS.
  $ echo $?
  0

  $ ln -s file-not-found symlink-2
  $ ./rename sym symbolic- symlink-2	# FAIL! REGRESSION.
  rename: symlink-2: not accessible: No such file or directory
  $ echo $?
  1

  $ ./rename sym symbolic- symlink-3	# XFAIL.
  rename: symlink-3: not accessible: No such file or directory
  $ echo $?
  1

  $ touch file-found
  $ ./rename found existing file-found	# XPASS.
  $ echo $?
  0

  $ ./rename found existing file-not-found # XFAIL.
  rename: file-not-found: not accessible: No such file or directory
  $ echo $?
  1

After:

  $ touch file-found
  $ ln -s file-found symlink-1
  $ ./rename sym symbolic- symlink-1	# XPASS.
  $ echo $?
  0

  $ ln -s file-not-found symlink-2
  $ ./rename sym symbolic- symlink-2	# PASS! REGRESSION FIXED.
  $ echo $?
  0

  $ ./rename sym symbolic- symlink-3	# XFAIL.
  rename: symlink-3: not accessible: No such file or directory
  $ echo $?
  1

  $ touch file-found
  $ ./rename found existing file-found	# XPASS.
  $ echo $?
  0

  $ ./rename found existing file-not-found # XFAIL.
  rename: file-not-found: not accessible: No such file or directory
  $ echo $?
  1

And to test/simulate faccessat()'s EINVAL for AT_SYMLINK_NOFOLLOW
for Mac OS X, per commit 826538bf64 ("rename: skip faccessat()
failure if AT_SYMLINK_NOFOLLOW is not a valid flag"), forced 'if'
to evaluate to false so that lstat() is taken.

It still fails early; the error messages are slightly different
('not accessible' vs. 'stat of ... failed') but still tell same
'No such file or directory'; exit code is the same as well.

  $ ./rename sym symbolic- symlink-3	# XFAIL. DIFF MSG/SAME RC.
  rename: stat of symlink-3 failed: No such file or directory
  $ echo $?
  1

  $ ./rename found existing file-not-found # XFAIL. DIFF MSG/SAME RC.
  rename: stat of file-not-found failed: No such file or directory
  $ echo $?
  1

Tested on commit 2b41c409e ("Merge branch 'blkd-err' of ...")

Signed-off-by: Mauricio Faria de Oliveira <mfo@canonical.com>
2020-07-07 16:19:15 -03:00
Luca Boccassi 488fd4c3df cryptsetup: add option to use via dlopen in libmount
Enabling libcrypsetup in libmount had several unintended side
effects.
First of all, it increases the Debian minimal image size by
~2.5% (5.6MB worth of new libraries).
Then, due to libcryptsetup linkage to OpenSSL and libjson-c,
it causes incompatibilities with external programs linking
against both libmount and a private, static, old version of
OpenSSL, or external programs linking against libjansson or
json-glib, which have one symbol in common with libjson-c.

If ./configure is ran with --with-crypsetup=dlopen,
instead of linking to libcrypsetup, use dlopen to resolve
the symbols at runtime only when the verity feature is
used, thus avoiding clashes and keeping images size down.

Fixes #1081

Signed-off-by: Luca Boccassi <luca.boccassi@microsoft.com>
2020-07-07 16:43:55 +01:00
Karel Zak 2b41c409e7 Merge branch 'blkd-err' of https://github.com/evverx/util-linux
* 'blkd-err' of https://github.com/evverx/util-linux:
  tests: turn off detect_leaks on s390x, use more asan options
  tests: skip "blkid/dm-err" when `mknod` doesn't work
2020-07-07 14:24:41 +02:00
Evgeny Vereshchagin 1b9f2ff333 tests: turn off detect_leaks on s390x, use more asan options
Signed-off-by: Evgeny Vereshchagin <evvers@ya.ru>
2020-07-03 13:26:08 +00:00
Evgeny Vereshchagin d3c9e21fe7 tests: skip "blkid/dm-err" when `mknod` doesn't work
Signed-off-by: Evgeny Vereshchagin <evvers@ya.ru>
2020-07-03 11:44:23 +00:00
Karel Zak 7586e9d1aa cal: use size_t to calculate width [lgtm scan]
We use size_t for width. This patch makes it consistent for
years_width too.

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-07-03 13:17:51 +02:00
Karel Zak 2e5819df6c unshare: (man) add note about signals on --fork
Addresses: https://github.com/karelzak/util-linux/pull/1087
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-07-03 13:03:58 +02:00
Karel Zak 9120e39f92 Merge branch 'unshare-signals' of https://github.com/DaanDeMeyer/util-linux 2020-07-03 12:56:54 +02:00
Karel Zak d118738095 libfdisk: (gpt) fix compiler warning [-Wmaybe-uninitialized]
Make sure that variables used in  gpt_calculate_* are always initialized.

Addresses: https://github.com/karelzak/util-linux/issues/1091
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-07-03 12:30:59 +02:00
Karel Zak bc270ae1a8 Merge branch 'werror' of https://github.com/evverx/util-linux 2020-07-03 11:34:12 +02:00
Karel Zak 32e1bc0d72 Merge branch 'travis-arch' of https://github.com/evverx/util-linux
* 'travis-arch' of https://github.com/evverx/util-linux:
  travis: build util-linux on arm64, ppc64le and s390x
2020-07-03 11:32:36 +02:00
Evgeny Vereshchagin b9b65bffc3 travis: turn on CIFuzz
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-07-03 11:19:14 +02:00
Evgeny Vereshchagin 6af515811b tests: ignore the python libmount tests when they're run under UBSan
ts_init_py meddles with LD_LIBRARY_PATH causing those tests to fail with
```
+Traceback (most recent call last):
+  File "/home/travis/build/karelzak/util-linux/libmount/python/test_mount_tab.py", line 8, in <module>
+    import pylibmount as mnt
+ImportError: /home/travis/build/karelzak/util-linux/.libs/libblkid.so.1: undefined symbol: __ubsan_handle_negate_overflow
}}}-diff
```
2020-07-03 11:18:54 +02:00
Evgeny Vereshchagin 5cda653a7b travis: install llvm-* to get llvm-symbolizer
Backtraces like
```
misc-utils/cal.c:295:4: runtime error: signed integer overflow: 2147483647 + 5 cannot be represented in type 'int'
==1405==WARNING: invalid path to external symbolizer!
==1405==WARNING: Failed to use and restart external symbolizer!
    #0 0x4c4c09  (/home/travis/build/karelzak/util-linux/cal+0x4c4c09)
    #1 0x7f4363046b96  (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
    #2 0x41bab9  (/home/travis/build/karelzak/util-linux/cal+0x41bab9)
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior misc-utils/cal.c:295:4 in
```
aren't very helpful

It's follow-up to https://github.com/karelzak/util-linux/pull/1075
2020-07-03 11:18:54 +02:00
Evgeny Vereshchagin 5b9df9c40d travis: turn on UBsan on Travis CI to see how it goes
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-07-03 11:18:32 +02:00
Evgeny Vereshchagin e6a4d8cc06 build-sys: add --enable-ubsan to make it possible to build util-linux with UBSan
mostly to prepare for https://github.com/karelzak/util-linux/pull/1068
but it's useful even without fuzzing.

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-07-03 11:17:53 +02:00
Daan De Meyer 3ba6736f3a unshare --fork: Ignore SIGINT and SIGTERM in parent 2020-07-02 16:35:21 +02:00
Evgeny Vereshchagin bf04d98b93 skip hwclock/systohc on Travis CI on Ubuntu Precise
It's flaky there.

Closes https://github.com/karelzak/util-linux/issues/1082
2020-07-02 11:52:46 +00:00
Evgeny Vereshchagin 38c5db359d travis: turn off -Werror on precise and osx
I'm not sure anyone is particularly interested in what the compilers
have to say there.
2020-07-02 10:51:04 +00:00
Evgeny Vereshchagin ad6aef0ea8 revert a680b2abe7
It's not clear what that commit was supposed to fix. Looks like
772420322d should have helped there.
2020-07-02 10:23:47 +00:00
Evgeny Vereshchagin 7b81644f10 travis: turn on -Werror 2020-07-02 09:49:12 +00:00
Evgeny Vereshchagin c7eb1925ee travis: build util-linux on arm64, ppc64le and s390x 2020-07-02 08:08:41 +00:00
Karel Zak a732e4a1d3 libblkid: remove blkid_llseek()
Let's use libc lseek() everywhere like we use in another tools. It's
year 2020 ...

Addresses: https://github.com/karelzak/util-linux/issues/1083
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-07-01 15:47:20 +02:00
Karel Zak 63c80c4cf7 build-sys: add --enable-werror
Add new ./configure option to make all compiler warnings into errors.

Addresses: https://github.com/karelzak/util-linux/issues/1083
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-07-01 15:23:10 +02:00
Karel Zak 077650ff0d docs: remove drone.io, add lgtm.com
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-07-01 09:33:27 +02:00
Karel Zak 313a738832 build-sys: add -Waddress-of-packed-member
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-07-01 09:32:58 +02:00
Karel Zak 96f114455e Merge branch 'bionic' of https://github.com/evverx/util-linux
* 'bionic' of https://github.com/evverx/util-linux:
  travis: make it easier to switch to the next clang/gcc
  travis: switch to clang-10
  travis: switch to gcc-10
  travis: ignore memory leaks in checkusage
  travis: install all the "official" build dependencies
  travis: switch to Bionic
2020-07-01 09:28:23 +02:00
Evgeny Vereshchagin e0967c5b39 travis: make it easier to switch to the next clang/gcc
by just changing the compiler option in .travis.yml

In https://travis-ci.org/github/karelzak/util-linux/builds/703664282 I switched
to gcc-9/clang-9 by simply applying the following patch:
```
diff --git a/.travis.yml b/.travis.yml
index ec1284717..12a247d91 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -7,8 +7,8 @@ git:
   depth: 1500

 compiler:
-  - gcc-10
-  - clang-10
+  - gcc-9
+  - clang-9

 env:
   - MAKE_CHECK="nonroot"
```
2020-06-30 18:11:30 +00:00
Evgeny Vereshchagin d98d498727 travis: switch to clang-10
to prepare the infrastructure for https://github.com/karelzak/util-linux/pull/1068
2020-06-29 14:54:26 +00:00
Evgeny Vereshchagin f99c2464e7 travis: switch to gcc-10
to get around an ASan bug mentioned in https://github.com/karelzak/util-linux/issues/1076
2020-06-29 14:28:42 +00:00
Evgeny Vereshchagin c297ed7533 travis: ignore memory leaks in checkusage
Closes https://github.com/karelzak/util-linux/issues/1077
2020-06-29 12:36:48 +00:00
Karel Zak f9a4f93584 Merge branch 'ufiformat-reference' of https://github.com/wojtekka/util-linux
* 'ufiformat-reference' of https://github.com/wojtekka/util-linux:
  disk-utils: Add reference to ufiformat(8)
2020-06-29 12:49:20 +02:00
Damien Goutte-Gattat 49848aa53a chfn: Make readline prompt for each field on a separate line
When readline is called to get user input, it is called without
a prompt argument. As a result, if the user does not enter anything
for a given field, then the next field is displayed on the same
line, yielding the following output:

  $ chfn
  Changing finger information for user.
  Password:
  Name []: Office []: Office Phone []: Home Phone []:

instead of the expected:

  $ chfn
  Changing finger information for user.
  Password:
  Full Name []:
  Room Number []:
  Work Phone []:
  Home Phone []:

This patch restores the expected behavior by feeding readline with
a character to display as "prompt".

[kzak@redhat.com: - do the same change in chsh
                  - use ' ' rather than '\n' for non-readline code]

Signed-off-by: Damien Goutte-Gattat <dgouttegattat@incenp.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-06-29 11:57:26 +02:00
Evgeny Vereshchagin 852db9d87d travis: install all the "official" build dependencies 2020-06-28 20:14:40 +02:00
Evgeny Vereshchagin 55092472e0 travis: switch to Bionic
To judge from fc412fe4ce, back in 2016 it was the latest version
of Ubuntu available on Travis CI. Now build tools there are too old
for testing purposes.

Other than that, Ubuntu Trusty hasn't been supported at https://apt.llvm.org/
since August 2019, which makes it kind of hard at this point to bring the latest clang
along with ASan, UBsan, Msan and libFuzzer to Travis CI.
2020-06-28 19:59:27 +02:00
Wojtek Kaniewski 98aa9c815a disk-utils: Add reference to ufiformat(8)
fdformat(8) doesn't handle USB floppy disk drives. As legacy floppy
disk drives have become a scarce resource it would be nice to point
those poor souls trying to format their floppy disks to a utility that
doesn't throw "Invalid argument" at them.

Signed-off-by: Wojtek Kaniewski <wojtekka@toxygen.net>
2020-06-27 21:15:10 +02:00
Karel Zak fe0d12d4f8 libmount: (parser) fix memory leak on error before end-of-file
Let's simplify the loop where we add FS to the table. The optimization
for recoverable errors is a fragile overkill. The new code always
allocates and unrefs FS for each loop.

Addresses: https://github.com/karelzak/util-linux/pull/1068
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-06-26 12:59:32 +02:00
Karel Zak d454da17da docs: mark some branches as github-only
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-06-24 16:38:28 +02:00
Mark Hindley 3e93958117 tests: Fix mountpoint test failure in build chroots.
The test assumed that / was a mountpoint. This is not always the case, for
example in pbuilder/cowbuilder chroots. So use / if findmnt verifies it is a
mountpoint, otherwise use the first mountpoint found. Skip the test if no
mountpoints are found.

Signed-off-by: Mark Hindley <mark@hindley.org.uk>
2020-06-24 15:44:44 +02:00
Bjarni Ingi Gislason 67fcb85739 sys-utils: mount.8: split a long line into two
Split two long lines, adding '\e' at the end of the first part,
as otherwise the last part of them disappears at the right margin in
the printed output (pdf).

Signed-off-by: Bjarni Ingi Gislason <bjarniig@rhi.hi.is>
2020-06-24 15:42:43 +02:00
Karel Zak c1fa7067e2 Merge branch 'bug422' of https://github.com/kerolasa/util-linux 2020-06-24 15:40:02 +02:00
Karel Zak 965334990e Merge branch 'some/small/fixes' of https://github.com/lnslbrty/util-linux
* 'some/small/fixes' of https://github.com/lnslbrty/util-linux:
  login: fixed invalid sizeof usage
  libfdisk, unshare: fix gcc-4.9.4 warnings
2020-06-24 15:32:54 +02:00
Alexey Gladkov 9fd01b10d0 setarch: add arm and aarch64 architectures to transition rules
Since aarch64 kernel can be configured with compat 32-bit support
enabled, extend translation rules in a way similar to x86/x86_64.

Suggested-by: "Dmitry V. Levin" <ldv@altlinux.org>
Signed-off-by: Alexey Gladkov <gladkov.alexey@gmail.com>
2020-06-24 15:05:53 +02:00
Alexey Gladkov 7f48cfb0e4 setarch: make verify_arch_domain extendable
When other compatible architectures are introduced, they will also have
to be added to the verifier.

Signed-off-by: Alexey Gladkov <gladkov.alexey@gmail.com>
2020-06-24 15:05:53 +02:00
Sami Kerola d8bfcb4cc5
col: fix output when first line does not have newline character
Commit I made while back and has been part of util-linux v2.30 to v2.35 made
col(1) not to output anything when first line did not have newline character.

    printf "gone from output" | col

This commit fixes the issue.  Admittedly the col source code is unnecessarily
hard to work with.  It could be a good idea to refactor the col(1) as low
priority task, Assuming refactoring is done the first commit to get that done
should add tests that exhaust all possible input handling including all command
line option directives.

Addresses: https://github.com/karelzak/util-linux/issues/422
Fixes: b6b5272b03
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-06-20 22:17:30 +01:00
Toni Uhlig fdadefe599
login: fixed invalid sizeof usage
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
2020-06-19 20:37:44 +02:00
Toni Uhlig 9eba847689
libfdisk, unshare: fix gcc-4.9.4 warnings
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
2020-06-19 20:37:33 +02:00
Karel Zak 883d1d6564 build-sys: fix blkdiscard blkid.h use
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-06-19 19:04:10 +02:00
Karel Zak 51355bea70 lib/sysfs: fix prefix use in sysfs_devname_is_hidden()
Addresses: https://github.com/karelzak/util-linux/issues/1062
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-06-19 10:06:25 +02:00
Rupesh Girase 4bee67e2d1 Manual pages: losetup.8: Fix "--direct-io" defaults
"--direct-io" option is "off" by default while configuring
loop device but it's mentioned "on" in man page.

Signed-off-by: Rupesh Girase <rgirase@redhat.com>
2020-06-19 10:03:00 +02:00