Commit Graph

14589 Commits

Author SHA1 Message Date
Karel Zak 195025c29e mkswap: check for holes and unwanted extentd in file
Let's make mkswap(8) more user-friend and report possible swapon
issues already when user initialize a swap file. The extents check
produces warnings, no exit with error.

  # dd if=/dev/zero of=img count=100 bs=1MiB
  # chmod 0600 img

  # fallocate --dig-hole --offset 64520192 --length 1MiB img
  # fallocate --dig-hole --offset 84520960 --length 1MiB img

  # ./mkswap img
  mkswap: extents check failed:
    - hole detected at offset 64520192 (size 1048576 bytes)
    - hole detected at offset 84520960 (size 1048576 bytes)
  file img can be rejected by kernel on swap activation.

  Setting up swapspace version 1, size = 100 MiB (104853504 bytes)
  no label, UUID=92091112-26b5-47aa-a02a-592e52528319

It checks for holes in the file, and for unknown, inline, shared and
deallocated extents.

Addresses: https://github.com/karelzak/util-linux/issues/1120
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-09-09 11:10:51 +02:00
yangzz-97 933f095feb libfdisk: reset context FD on error
When the query disk fails, reset cxt->dev_fd.

Addresses: https://github.com/karelzak/util-linux/pull/1137
Addresses: https://github.com/karelzak/util-linux/issues/1131
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-09-07 12:09:36 +02:00
Karel Zak f29a2cfbe1 libsmartcols: don't print empty output on empty table in JSON
old version:
 $ findmnt --json --type foo
 $

new version:
 $ findmnt --json --type foo
 {
    "filesystems": [
    ]
 }

Addresses: https://github.com/karelzak/util-linux/issues/1136
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-09-07 11:52:13 +02:00
Karel Zak f9de18f54a Merge branch 'cramfs-test-fix' of https://github.com/masami256/util-linux
* 'cramfs-test-fix' of https://github.com/masami256/util-linux:
  tests: mkfs-endianness test use iflag=fullblock to fill block completely with string
2020-09-03 10:57:13 +02:00
Masami Ichikawa 7b54f05d6b tests: mkfs-endianness test use iflag=fullblock to fill block completely with string
When run mkfs-endianness test on lowend machine, sometimes dd didn't
fill block with string then test failed.
So, it's nice to add iflag=fullblock option to fill a block with
string read from stdin.

Tested on Raspberry Pi 3 B+(using 1core to simulate lowend environment)
 with iflag=fullblock option didn't get test failure.

Without iflag=fullblock option.
$ sudo sh -c 'for i in $(seq 1 500); do taskset -c 0 ./ts/cramfs/mkfs-endianness ;  done' | grep FAILED | wc -l
49

With iflag=fullblock option.
$ sudo sh -c 'for i in $(seq 1 500); do taskset -c 0 ./ts/cramfs/mkfs-endianness ;  done' | grep FAILED | wc -l
0

Signed-off-by: Masami Ichikawa <masami256@gmail.com>
2020-09-03 10:41:18 +09:00
Sami Kerola f4987e082b libmount: do not use pointer as an integer value
Fix couple "initialization of ‘long int’ from ‘void *’ makes integer from
pointer without a cast" warnings.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-09-02 12:06:18 +02:00
Karel Zak 6932a11035 lsblk: fix -T optional argument
Addresses: https://github.com/karelzak/util-linux/issues/1132
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-09-02 11:10:18 +02:00
Karel Zak 42fa381b9d pg: fix wcstombs() use
The size (3rd) argument should be ignored if the 1st *dest is NULL, but it seems gcc & glibc headers
are more pedantic now:

ext-utils/pg.c:456:13: error: argument 1 is null but the corresponding size argument 3 value is 2048 [-Werror=nonnull]

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-09-01 11:54:07 +02:00
Karel Zak 57898c3a7e libmount: remove read-mountinfo workaround
This workaround has been introduced by
e4925f591c

And originally requested by https://github.com/systemd/systemd/issues/10872

It seems we do not need it anymore as the problem should be fixed in kernel since 5.8
(kernel commit 9f6c61f96f2d97cbb5f7fa85607bc398f843ff0f).

Note that the libmount solution is very expensive as it repeats read()
many times (until we get consistent result) if kernel is busy with
mount table modification. This behaviour makes events management in
systemd (or other places) pretty difficult as read mountinfo takes
time on busy systems.

Addresses: https://github.com/systemd/systemd/pull/16537
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-09-01 10:15:14 +02:00
Karel Zak a3a0cc42af Merge branch 'master' of https://github.com/itsthem/util-linux
* 'master' of https://github.com/itsthem/util-linux:
  her -> their
  her -> their
  him -> them
  him -> them
  his -> their
  he -> they
  he -> they
  he -> they
2020-09-01 09:45:32 +02:00
Rosen Penev fdac67ae14
hwclock: fix SYS_settimeofday fallback
turns out this is subtly broken. musl 1.2.x for 64-bit architectures defines __NR_settimeofday but not
for 32-bit ones. For 32-bit, it defines a _time32 variant.
2020-08-29 21:55:58 -07:00
leeceeksdee 0c4bf7913c
her -> their 2020-08-28 19:19:23 +02:00
leeceeksdee c9c7de7932
her -> their 2020-08-28 19:18:33 +02:00
leeceeksdee 087203733d
him -> them 2020-08-28 19:17:00 +02:00
leeceeksdee 3a03903011
him -> them 2020-08-28 19:16:33 +02:00
leeceeksdee 40d249fca0
his -> their 2020-08-28 19:15:34 +02:00
leeceeksdee d15a6c22cf
he -> they 2020-08-28 19:12:44 +02:00
leeceeksdee c2fcf2f797
he -> they 2020-08-28 19:11:45 +02:00
leeceeksdee 3ba9018b85
he -> they 2020-08-28 19:11:02 +02:00
Michael Kerrisk (man-pages) 76054e1527 Manual pages: blockdev.8, sfdisk.8: typo fixes
Fix a couple of typos that I introduced.

Signed-off-by: Michael Kerrisk (man-pages) <mtk.manpages@gmail.com>
2020-08-28 09:15:25 +02:00
Soumendra Ganguly 75ccd75a2f script: cleanup --echo
Permanently turn off current stdin ECHO when it is a terminal and enable setting slave ECHO instead.
Fix other minor typos, update documentation.

[kzak@redhat.com: - remove irrelevant changes
                  - keep --echo argument unchanged]

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-08-27 12:56:46 +02:00
Karel Zak d3f21dca1e bash-completion: add column --table-columns-limit
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-08-25 14:23:28 +02:00
Karel Zak ea160a2bef column: add --table-columns-limit
$ echo -e 'AAA:BBB:CCC:DDD\n' | ./column -t -s ':'
AAA  BBB  CCC  DDD

$ echo -e 'AAA:BBB:CCC:DDD\n' | ./column -t -s ':' -l 2
AAA  BBB:CCC:DDD

$ echo -e 'AAA:BBB:CCC:DDD\n' | ./column -t -s ':' -l 3
AAA  BBB  CCC:DDD

Addresses: https://github.com/karelzak/util-linux/issues/1124
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-08-25 14:15:36 +02:00
Karel Zak 816c5754f2 Merge branch 'fix-sfdisk-json' of https://github.com/adriaandegroot/util-linux
* 'fix-sfdisk-json' of https://github.com/adriaandegroot/util-linux:
  Generate valid JSON if partition table is empty
2020-08-25 11:29:16 +02:00
Karel Zak f1f48270c9 mount, umount: restore environ[] after suid drop
The commands mount and umount sanitize environment variables as it
works with suid permissions by default. Since v2.36 it's possible
that the commands drop the permissions and continue as regular user.
It seems we also need to restore the original environ to keep things
consistent for users (e.g. HOME=).

The implementation is pretty simple -- it keeps in memory removed
variables and use it after switch to non-suid mode.

Addresses: https://github.com/karelzak/util-linux/issues/880
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-08-25 10:48:29 +02:00
Karel Zak e113093ce9 lib/env: add function to save and restore unwanted variables
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-08-25 10:43:07 +02:00
Adriaan de Groot bc743b355c
Generate valid JSON if partition table is empty
When the partition table is present **but** empty, the existing code would output fields followed by a `,` , on the assumption that the list of partitions would follow. But if the list of partitions is empty, it is skipped, leading to output like this:

```
{
  "partitiontable": {
      "label":"gpt",
      "id":"1F9E80D9-DD78-024F-94A3-B61EC82B18C8",
      "device":"/dev/sdb",
      "unit":"sectors",
      "firstlba":2048,
      "lastlba":30949342,
      "sectorsize":512,
  }
}
```

Note the `512,` on the *sectorsize* line.

This is invalid JSON for some parsers, which choke on it.

Avoid this, by checking when outputting the last separator: if there's no table, or there is a table but it is empty, then just put a newline, otherwise use the old path of comma-newline and assume there's going to be a list of partitions after.
2020-08-24 23:30:35 +02:00
nl6720 80a54e2b3e
libfdisk: add systemd-homed user's home GPT partition type
See https://systemd.io/HOME_DIRECTORY/ .
Additionally update the URL of the Boot Loader Specification.

Signed-off-by: nl6720 <nl6720@gmail.com>
2020-08-22 15:40:06 +03:00
Karel Zak 72f783d0ea libmount: fix tab parser for badly terminated lines
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-08-17 16:33:59 +02:00
Evgeny Vereshchagin d7720587f5 tests: cover the code parsing comments
It seems to be failing with
```
AddressSanitizer:DEADLYSIGNAL
=================================================================
==13==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x00000055f428 bp 0x7ffc3743a170 sp 0x7ffc3743a080 T0)
==13==The signal is caused by a WRITE memory access.
==13==Hint: address points to the zero page.
SCARINESS: 10 (null-deref)
    #0 0x55f428 in mnt_table_parse_next /src/util-linux/libmount/src/tab_parse.c:587:6
    #1 0x55c200 in __table_parse_stream /src/util-linux/libmount/src/tab_parse.c:737:8
    #2 0x55be38 in mnt_table_parse_stream /src/util-linux/libmount/src/tab_parse.c:809:8
    #3 0x5511ff in LLVMFuzzerTestOneInput /src/util-linux/libmount/src/fuzz.c:21:16
    #4 0x458a31 in fuzzer::Fuzzer::ExecuteCallback(unsigned char const*, unsigned long) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerLoop.cpp:558:15
    #5 0x458175 in fuzzer::Fuzzer::RunOne(unsigned char const*, unsigned long, bool, fuzzer::InputInfo*, bool*) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerLoop.cpp:470:3
    #6 0x45a117 in fuzzer::Fuzzer::ReadAndExecuteSeedCorpora(std::__Fuzzer::vector<fuzzer::SizedFile, fuzzer::fuzzer_allocator<fuzzer::SizedFile> >&) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerLoop.cpp:770:7
    #7 0x45a319 in fuzzer::Fuzzer::Loop(std::__Fuzzer::vector<fuzzer::SizedFile, fuzzer::fuzzer_allocator<fuzzer::SizedFile> >&) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerLoop.cpp:799:3
    #8 0x44a055 in fuzzer::FuzzerDriver(int*, char***, int (*)(unsigned char const*, unsigned long)) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerDriver.cpp:846:6
    #9 0x471bf2 in main /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerMain.cpp:19:10
    #10 0x7fe3bd93b83f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2083f)
    #11 0x41f208 in _start (/out/test_mount_fuzz+0x41f208)

DEDUP_TOKEN: mnt_table_parse_next--__table_parse_stream--mnt_table_parse_stream
```
2020-08-13 05:21:26 +00:00
Karel Zak 93bf606312 Merge branch 'patch-1' of https://github.com/8vasu/util-linux
* 'patch-1' of https://github.com/8vasu/util-linux:
  Update pty-session.c
  More minor typos
  Fix minor typo
2020-08-14 11:18:59 +02:00
Karel Zak 91a3e37489 Merge branch 'fdisk-fuzzer-follow-up' of https://github.com/evverx/util-linux
* 'fdisk-fuzzer-follow-up' of https://github.com/evverx/util-linux:
  tests: add testcases that triggered various crashes
2020-08-14 11:16:12 +02:00
Karel Zak 1f50296c0f libfdisk: (script) fix possible partno overflow
Addresses: https://oss-fuzz.com/testcase-detail/5740890480705536
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-08-14 11:13:50 +02:00
Soumendra Ganguly 5679c7bbdb
Update pty-session.c 2020-08-13 12:58:22 -05:00
Karel Zak 678d03cc8a libfdisk: (script) fix possible memory leaks
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-08-13 13:48:28 +02:00
Soumendra Ganguly c556dc5943
More minor typos 2020-08-13 06:01:57 -05:00
Karel Zak d8f35960ae libfdisk: another parse_line_nameval() cleanup 2020-08-13 10:13:01 +02:00
Karel Zak 9f03ad60e5 libfdisk: make fdisk_partname() more robust 2020-08-13 10:12:01 +02:00
Soumendra Ganguly 86139a7041
Fix minor typo
terminall -> terminal
2020-08-13 02:44:28 -05:00
Karel Zak 3b87a9af49 libfdisk: fix typo from 255f5f4c77
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-08-12 19:48:47 +02:00
Karel Zak 4bdb681571 libfdisk: (script) make sure buffer is initialized
Just to make static analyzers happy.

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-08-12 19:39:34 +02:00
Karel Zak 8bbc11f12f libfdisk: (script) don't use sector size if not specified
This is probably bad script API use, but better be safe than sorry.

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-08-12 15:59:38 +02:00
Karel Zak 255f5f4c77 libfdisk: (script) make sure label is specified
and unref type if already specified (unlikely, but be paranoid)

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-08-12 15:52:53 +02:00
Evgeny Vereshchagin 519ad7a136 tests: add testcases that triggered various crashes
to make it easier to catch regressions going forward.

It's a follow-up to 678d03cc8a, 9f03ad60e5
and 4bdb681571

Signed-off-by: Evgeny Vereshchagin <evvers@ya.ru>
2020-08-12 00:21:45 +00:00
Evgeny Vereshchagin 6c13bfcfed travis: stop building fuzz targets on macOS
Looks like `-fsanitize=fuzzer` isn't supported there:

https://travis-ci.org/github/karelzak/util-linux/jobs/716894984
```
clang: error: unsupported option '-fsanitize=fuzzer' for target 'x86_64-apple-darwin17.7.0'
```
2020-08-11 00:21:27 +00:00
Evgeny Vereshchagin b62ec52e8f tests: add a fuzz target calling fdisk_script_read_file
It has already found a couple of issues mentioned in
https://github.com/karelzak/util-linux/issues/1023#issuecomment-671910621
2020-08-10 23:30:50 +00:00
Karel Zak 943f4dbdfe Merge branch 'scriptreplay_noebadf' of https://github.com/8vasu/util-linux 2020-08-11 11:58:30 +02:00
Karel Zak 69e4fbfbfd hwclock: add fallback if SYS_settimeofday does not exist
It seems Musl-C removes SYS_settimeofday macro at all.

Addresses: 9c6139a720 (commitcomment-41290951)
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-08-11 11:02:31 +02:00
Karel Zak c87cce57d8 Merge branch 'fuzz' of https://github.com/evverx/util-linux
* 'fuzz' of https://github.com/evverx/util-linux:
  tests: pack testcases into zip archives
  tests: integrate test_last_fuzz into the testsuite
  tests: add a fuzzer for process_wtmp_file
  docs: mention OSS-Fuzz and CIFuzz and how to build fuzz targets locally
  tools: make it possible to set all the fuzzing flags with config-gen
  build-system: make "make distcheck" work
  travis: set CXX correctly
  travis: turn on --enable-fuzzing-engine
  build-sys: add support for --enable-fuzzing-engine
  tests: integrate test_mount_fuzz into the testsuite
  tests: take exit codes into account
  tests: add a fuzzer for mnt_table_parse_stream
2020-08-10 14:40:44 +02:00
Karel Zak dc4816142c tests: add sfdisk test for 4fe7f9b614
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-08-10 12:00:17 +02:00