Commit Graph

80 Commits

Author SHA1 Message Date
Rosen Penev ad296391f9
[clang-tidy] fix wrong *cmp usage
Found with bugprone-suspicious-string-compare

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-04-20 13:21:00 -07:00
Rosen Penev 042f62dfc5
[clang-tidy] do not use else after return
Found with readability-else-after-return

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-04-20 13:20:59 -07:00
Rosen Penev bd89499e07
[clang-tidy] do not return in void functions
Found with readability-redundant-control-flow

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-04-19 14:03:21 -07:00
Karel Zak 2c308875a7 misc: consolidate version printing and close_stdout()
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-04-16 15:14:13 +02:00
Ruediger Meier f45f3ec34a misc: consolidate macro style USAGE_HELP_OPTIONS
changed in include/c.h and applied via sed:

  sed -i 's/fprintf.*\(USAGE_MAN_TAIL.*\)/printf(\1/' $(git ls-files -- "*.c")
  sed -i 's/print_usage_help_options\(.*\);/printf(USAGE_HELP_OPTIONS\1);/' $(git ls-files -- "*.c")

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-29 16:54:33 +02:00
Ruediger Meier b1a294c448 misc: introduce print_usage_help_options()
Consolidate --help and --version descriptions. We are
now able to align them to the other options.

We changed include/c.h. The rest of this patch was
generated by sed, plus manually setting the right
alignment numbers. We do not change anything but
white spaces in the --help output.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-27 12:26:19 +02:00
Ruediger Meier 6e1eda6f22 misc: never use usage(stderr)
Here we fix all cases where we have usage(FILE*)
functions.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-26 14:38:24 +02:00
Ruediger Meier 0b2b32e8a7 misc: fix more strutils related exit codes
Found by grep:

grep -l "\bEXIT_\|exit *( *[0-9][0-9] *)\|strutils\.h" $(grep -L \
    strutils_set_exitcode  $(git grep -l "_EX_\|FINDFS_\|BLKID_EXIT\|EX_USAGE" -- "*.c"))

The Command shows also some false positives (fstrim.c,
context_mount.c, ...)

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-22 22:40:21 +02:00
Karel Zak 82c7ab9cb8 fsck.minix: add hint for scanners [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-17 11:38:54 +02:00
Sami Kerola 51b4b39870 fsck.minix: fix crash
disk-utils/fsck.minix.c:421:30: runtime error: index 513 out of bounds for
type 'unsigned short [512]'

Addresses: https://github.com/karelzak/util-linux/issues/373
Reported-by: Hanno Bock <hanno@gentoo.org>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-05-16 14:54:41 +02:00
Karel Zak 677ec86cef Use --help suggestion on invalid option
The current default is to print all usage() output. This is overkill
in many case.

Addresses: https://github.com/karelzak/util-linux/issues/338
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-12-19 13:13:34 +01:00
Sami Kerola 74ce680a3e
misc: simplify if clauses [oclint]
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-07-21 21:14:33 +01:00
Karel Zak 65c74885df fsck.minix: fix endless loop and out of stack
It seems there is no elegant way how to recovery if a directory i_zone
(and i_size) is out of reality. Let's require human interaction to
avoid endless loop when executed with --auto, etc.

Addresses: https://github.com/karelzak/util-linux/issues/228
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-06-01 14:55:15 +02:00
Sebastian Rasmussen 9e93004171 misc: Fix various typos
Fix various typos in error messages, warnings, debug strings,
comments and names of static functions.

Signed-off-by: Sebastian Rasmussen <sebras@gmail.com>
2016-05-31 23:40:21 +02:00
Tobias Stoeckmann 8f35b3a998 fsck.minix: Verify more fields in super-block.
The field s_ninodes in super-block is used for memory allocation and
division without verifications. The memory allocation increments the
unchecked value by 1, making it vulnerable to an integer overflow
on 32 bit systems with minix 3 file systems. I did not find a (good)
way to exploit this by crafting a malicious file system, so I consider
it as a reliability issue. If it's 0, a division by zero occurs when
"-v" has been used. A filesystem without any inodes is definitely
wrong, because it means that there's not even the root inode, which is
accessed unchecked later on.

The field s_firstdatazone has to be checked against s_(n)zones. If it
is larger than the highest allowed index, the file system is definitely
corrupted -- hard to say which value is wrong though, therefore I
decided to simply call die(). A maliciously created file system could
do more harm in this way: single bits inside the memory area could be
flipped because range checks would fail. Hard to consider it as a
security issue though, because these addresses are not arbitrarily
accessible without very careful crafting (if at all possible).

[kzak@redhat.com: - fix compiler warning (cast get_nzones()) [-Wsign-compare]]

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-05-31 13:18:06 +02:00
Ruediger Meier fdbd7bb940 misc: again fixing many printf format strings
This is again a huge patch regarding printf format strings to
fix compiler warnings seen on clang/OSX.

I'm trying to follow these rules strictly:

 #type      #format   #cast
 uintmax_t   %ju      -
 intmax_t    %jd      -
 uint64_t    PRIu64   -
 int64_t     PRId64   -
 size_t      %zu      -
 ssize_t     %zd      -
 ino_t       %ju      (uintmax_t)
 off_t       %jd      (intmax_t)

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-03-07 23:16:04 +01:00
Ruediger Meier fcb1242601 fsck.minix: fix v3 version offset
Our test-suite discoverd it on big endian systems, but it was also
broken on little endian for inode numbers > 0xffff.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-03-03 09:24:06 +01:00
Ruediger Meier f3e0213aa4 include: remove unused mntent.h
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-02-18 16:54:23 +01:00
Sami Kerola 624e147ba2 misc: fix shadow declarations
sys-utils/zramctl.c: In function 'get_mm_stat':
sys-utils/zramctl.c:276:58: warning: declaration of 'inbytes' shadows a global declaration [-Wshadow]
 static char *get_mm_stat(struct zram *z, size_t idx, int inbytes)
sys-utils/zramctl.c:119:39: note: shadowed declaration is here
 static unsigned int raw, no_headings, inbytes;

libmount/src/tab.c: In function 'mnt_table_get_fs_root':
libmount/src/tab.c:1221:22: warning: declaration of 'fs' shadows a parameter [-Wshadow]
    struct libmnt_fs *fs = mnt_table_find_mountpoint(tb,
libmount/src/tab.c:1197:24: note: shadowed declaration is here
      struct libmnt_fs *fs,

disk-utils/fsck.minix.c: In function 'main':
disk-utils/fsck.minix.c:1364:17: warning: declaration of 'i' shadows a previous local [-Wshadow]
   unsigned long i, free;
disk-utils/fsck.minix.c:1250:6: note: shadowed declaration is here
  int i;

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-08-24 10:55:37 +02:00
Karel Zak 1e9d849b8d fsck.minix: be more paranoid with block buffers [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-08-04 11:15:53 +02:00
Sami Kerola 158b8d6918 fsck.minix: introduce long options to the command
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-07-30 11:39:17 +02:00
Sami Kerola 86a9f3dad5 fsck.minix: add minix v3 support
Relates-to: a2657ae3ff
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-07-30 11:39:16 +02:00
Sami Kerola e1df9d4cd6 fsck.minix: rename device file descriptor variable
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-07-30 11:39:16 +02:00
Sami Kerola cd2a6f1cfd rpmatch: use symbolic value when evaluation return codes
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-02-24 12:42:06 +01:00
Sami Kerola 730ae9c899 fsck.minix: fix segmentation fault
Return from check_file() and check_file2() functions when maximum name
depth is reached.  The use unsafe strncpy() is also removed just to be on
safe side.

Addresses: https://bugs.debian.org/773892
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-01-07 10:14:13 +01:00
Benno Schulenberg 451dbcfae1 textual: add a docstring to most of the utilities
This adds a concise description of a tool to its usage text.

A first form of this patch was proposed by Steven Honeyman
(see http://www.spinics.net/lists/util-linux-ng/msg09994.html).

Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2015-01-06 11:27:38 +01:00
Sami Kerola 564dd4af5d fsck.minix: check writing to a file descriptor was successful
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-04-26 13:26:07 +02:00
Sami Kerola 3acc206d39 various: fix variable and function declarations [smatch scan]
disk-utils/fsck.minix.c:511:9: warning: mixing declarations and code
fdisks/sfdisk.c:982:5: warning: mixing declarations and code
fdisks/sfdisk.c:1254:5: warning: mixing declarations and code
fdisks/sfdisk.c:1564:5: warning: mixing declarations and code
lib/mbsalign.c:279:7: warning: mixing declarations and code
libblkid/src/devname.c:378:17: warning: mixing declarations and code
libfdisk/src/alignment.c:219:9: warning: mixing declarations and code
term-utils/wall.c:111:9: warning: mixing declarations and code
text-utils/col.c:418:19: warning: non-ANSI function declaration of function 'flush_blanks'
text-utils/col.c:553:12: warning: non-ANSI function declaration of function 'alloc_line'
text-utils/rev.c:105:9: warning: mixing declarations and code
text-utils/tailf.c:245:9: warning: mixing declarations and code

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-04-09 12:17:20 +02:00
William Pitcock 51924a4ef0 add missing rpmatch.h everywhere it needs to be
Signed-off-by: William Pitcock <nenolod@dereferenced.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-02-20 13:04:02 +01:00
Benno Schulenberg b50945d4ac textual: spell and encode the name of Arkadiusz Miśkiewicz correctly
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2013-02-06 11:15:02 +01:00
Benno Schulenberg 0c6625a15d textual: standardize the reporting of program name plus package version
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2013-01-30 15:24:00 +01:00
Karel Zak 248b8101a0 mkfs.minix: fsck:minix: fix compiler warnings
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-12-20 20:01:35 +01:00
Sami Kerola 65ca6f8382 minix: replace magic constants with macro names
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-12-19 11:38:56 +01:00
Sami Kerola a180dc6c54 minix: use off_t, size_t, etc appropriate types
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-12-19 11:38:53 +01:00
Sami Kerola 289dcc9023 translation: unify file open error messages
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-07-16 18:18:22 +02:00
Petr Uzel e12c9866b5 include: rename writeall.h to all-io.h
Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
2012-05-15 11:32:27 +02:00
Petr Uzel 28d4cdcb9d fsck.minix.c: fix compiler warnings [-Wunused-result]
fsck.minix.c: In function ‘ask’:
fsck.minix.c:263:7: error: ignoring return value of ‘fgets’, declared with attribute warn_unused_result [-Werror=unused-result]

Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
2012-04-27 12:30:46 +02:00
Sami Kerola 45ca68ece7 disk-utils: verify writing to streams was successful
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-04-04 20:04:39 +02:00
Sami Kerola 2a11944f16 fsck.minix: fix printf format warning
fsck.minix.c:1302:3: warning: ISO C does not support the '%m' gnu_printf format [-Wformat]

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-03-30 16:48:12 +02:00
Sami Kerola a2bfda30ba fsck.minix: clean up coding style
$ indent -linux -psl -blf disk-utils/fsck.minix.c

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-03-30 16:48:12 +02:00
Sami Kerola 78ecf61b0e fsck.minix: align with howto-usage-function.txt
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-03-30 16:48:12 +02:00
Sami Kerola d4a573bc7b fsck.minix: use rpmatch() for yes/no question
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-03-30 16:48:12 +02:00
Sami Kerola 891327c091 fsck.minix: use symbolic exit codes
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-03-30 16:48:12 +02:00
Francesco Cosoleto f8209a0f66 fsck.minix: fix zone_map memory allocation failure check
Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
2011-11-10 12:58:31 +01:00
Francesco Cosoleto d73af2ac4b fsck.minix: remove unnecessary memset calls
The program aborts without using this unintialized allocated memory,
setting to zero doesn't look needed.

memset calls with sizeof() of pointer as argument (reported by clang).

[kzak@redhat.com: - replace malloc with calloc for {zone,inode}_count
                    to make code more robust]

Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-11-09 10:03:07 +01:00
Petr Uzel 960cf5737e misc: use %m in format string instead of %s and strerror(errno)
Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
2011-09-27 15:46:07 +02:00
Karel Zak 832410da7b mkfs.minix: fix write_all() usage
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-08-17 00:29:39 +02:00
Karel Zak ab1c86fc53 fsck.minix: fix compiler warnings [-Wsign-compare]
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-08-01 14:38:42 +02:00
Karel Zak 06c0375ce3 fsck.minix: fix "array subscript is above array bounds"
fsck.minix.c: In function ‘map_block2’:
fsck.minix.c:486:9: warning: array subscript is above array bounds [-Warray-bounds]

The 'blknr' has to be bigger than 7 + 256 + (256 * 256) for i_zone[9].

Signed-off-by: Karel Zak <kzak@redhat.com>
2011-07-21 13:00:40 +02:00
Karel Zak 0dca7bd54a minix: remove unnecessary initializations
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-07-21 12:41:25 +02:00