Commit graph

49 commits

Author SHA1 Message Date
Karel Zak
2ac1bc84d7 text-utils: use proper paths to term.h
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-30 17:15:37 +02:00
Sami Kerola
2ba641e5f3 misc: add static keyword to where needed [smatch scan]
text-utils/rev.c:68:9: warning: symbol 'buf' was not declared. Should it be
static?

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-20 12:58:49 +01:00
Sami Kerola
8791804065 misc: do not use plain 0 as NULL [smatch scan]
text-utils/tailf.c:69:21: warning: Using plain integer as NULL pointer

Since many 'struct option' has used zero as NULL make them more readable in
same go by reindenting, and using named argument requirements.

Reference: https://lwn.net/Articles/93577/
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-20 12:58:49 +01: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
Tobias Stoeckmann
f20b214edc ul: Fix buffer overflow
The text-utility ul can run into a buffer overflow on very long lines.
See this proof of concept how to reproduce the issue:

$ dd if=/dev/zero bs=1M count=10 | tr '\000' '\041' > poc.txt
$ echo -ne '\xe\x5f\x8\x5f\x61\x2\xf\x5f\x8\x5f' | dd of=poc.txt conv=notrunc
$ ul -i poc.txt > /dev/null # output would take ages
Segmentation fault
$ _

The problem manifests by using alloca with "maxcol", which can be as
large as INT_MAX, based on the input line.

A very long line (> 8 MB) with modes must be supplied to ul, as seen in
my proof of concept byte sequence above.

It is rather easy to fix this issue: allocate space on the heap instead.
maxcol could overflow here, but in that case no system will have enough
space to handle the request, properly ending ul through an err() call.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2016-09-29 11:49:08 +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
Ruediger Meier
b0b24b11f8 lib: rename strmode() and setmode()
On BSD they are part of the standard C library.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-02-18 12:53:48 +01:00
Sami Kerola
97d8f180b6 ul: remove unexplained TERM=lpr override
The FIXME item has been in place since 2011-04-30, and the code has never
made sense, so remove it.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-01-07 21:57:53 +00: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
d07b223788 ul: fix filter() indentation
Content of the while() loop missed one indentation step.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-10-20 14:07:20 +02:00
Sami Kerola
f627750083 textual: use version printing macro everywhere
Only mount, umount, and blkid remains not using the macro because they
are print also library references.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-10-01 12:33:23 +02:00
Sami Kerola
67519cdd8f ul: use string printing function
Use of for loop and printing a string character by character is slower
than to print whole string with single function.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-07-09 14:25:55 +02:00
Sami Kerola
aa971f7d58 ul: use correct types
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-07-09 14:25:36 +02:00
Sami Kerola
99361a9c0e ul: enhance command performance
Avoid reseting, time after time, the memory which was not used.  Effect
of the change is below in before and after timings.

$ time ./ul </etc/services >/dev/null
real    0m0.320s
user    0m0.307s
sys     0m0.010s

$ time ./ul </etc/services >/dev/null
real    0m0.068s
user    0m0.050s
sys     0m0.017s

[kzak@redhat.com: - add "else" and use maxcol]

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-07-01 14:02:57 +02:00
Karel Zak
a2343e0312 ul: cleanup usage() and man page
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-04-05 12:43:51 +02: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
Sami Kerola
7285104410 ul: fix shadow declaration
text-utils/ul.c:641:25: warning: declaration of 'col' shadows a global declaration [-Wshadow]
text-utils/ul.c:126:5: warning: shadowed declaration is here [-Wshadow]

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-07-26 13:51:20 +02: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
Bernhard Voelker
455fe9a075 Fix typos found by misspellings
The tool misspellings (https://github.com/lyda/misspell-check)
detected several typos. Command used:

  $ git ls-files | grep -v ^po/ | misspellings -f -

* isosize: Fix typo in usage string.
* configure.ac: Fix typo in help string of --enable-most-builds option.
* fdisk: Fix typo in man page.
* libblkid, blkid, mount: Likewise.
* Fix various typos in docs and in source code comments.

Signed-off-by: Bernhard Voelker <mail@bernhard-voelker.de>
2012-04-23 13:16:35 +02:00
Sami Kerola
b87cbe8486 text-utils: verify writing to streams was successful
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-04-04 19:45:41 +02:00
Benno Schulenberg
262aee0b45 ul: remove superfluous return as usage() does not return
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2011-08-15 15:49:42 +02:00
Benno Schulenberg
293fbd7f04 ul: make usage() say that more than one input file is allowed
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2011-08-15 15:49:38 +02:00
Benno Schulenberg
055da7c5e4 ul: in usage() not overwriting but overriding is meant
Also always use lowercase.

Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2011-08-15 15:49:36 +02:00
Sami Kerola
0200c80155 ul.c: warn user when command chooses term type
Happens usually when user specifies garbage as -t argument.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-05-17 15:58:05 +02:00
Sami Kerola
a4949aaa54 ul.c: escape handling refactored
Separate function for escape handling to make switch statement
more readable.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-05-17 15:58:05 +02:00
Sami Kerola
78b0fdd3d7 ul.c: close files and free memory after usage
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-05-17 15:58:05 +02:00
Sami Kerola
565239b034 ul.c: code style and comment fixes
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-05-17 15:58:05 +02:00
Sami Kerola
2afa872ffc ul.c: fix compier warnings
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-05-17 15:56:30 +02:00
Sami Kerola
cc319747b5 ul.c: magic constant removal
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-05-17 15:56:30 +02:00
Sami Kerola
a3b761801c ul.c: use long options
This commit introduces help & version options.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-05-17 15:56:30 +02:00
Sami Kerola
cdbe31fc6a ul.c: convert definition to function
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-05-17 15:56:22 +02:00
Fabian Groffen
eb76ca98b0 build-sys: provide alternatives for err, errx, warn and warnx
Solaris lacks err, errx, warn and warnx.  This also means the err.h header
doesn't exist.  Removed err.h include from all files, and included err.h from
c.h instead if it exists, otherwise alternatives are provided.

Signed-off-by: Fabian Groffen <grobian@gentoo.org>
2011-02-14 17:45:24 +01:00
Davidlohr Bueso
f0961db21f ul: use xalloc for memory allocation
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2010-11-01 15:17:10 +01:00
Karel Zak
5d757a9fde remove free() from atexit() callbacks
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-10-29 13:29:28 +02:00
Marek Polacek
50644ff4de use _exit() instead of exit() in sighandlers
Signed-off-by: Marek Polacek <mmpolacek@gmail.com>
2010-10-29 13:26:25 +02:00
Karel Zak
59f8c787e7 ul: use atexit() to deallocate buffer, print errors by err()
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-09-17 10:35:35 +02:00
Davidlohr Bueso
4727b16944 ul: fix memory leak.
The 'obuf' variable is not being freed after usage and this includes
when SIGINTs occur, hence add some basic signal handling.

[kzak@redhat.com - remove if-before-free ]

Signed-off-by: Davidlohr Bueso <dave@gnu.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-09-17 10:02:36 +02:00
Daniel Mierswa
c0f19ccff7 replace bcopy,bzero,index and rindex
Those 4 functions are marked as LEGACY in POSIX.1-2001 and removed in
POSIX.1-2008.

Replaced with memmove,memset,strchr and strrchr.

Signed-off-by: Daniel Mierswa <impulze@impulze.org>
2009-08-17 11:15:59 +02:00
Karel Zak
06b04b23cd build-sys: fix ifdef ENABLE_WIDECHAR usage
There has been unexpected mix of HAVE_WIDECHAR and ENABLE_WIDECHAR macros. The
ENABLE_WIDECHAR is old version and has to be replaced everywhere otherwise we
will see bugs with multibyte stuff.

Signed-off-by: Karel Zak <kzak@redhat.com>
2007-01-30 13:49:50 +01:00
Karel Zak
ffc4374869 Imported from util-linux-2.11o tarball. 2006-12-07 00:25:53 +01:00
Karel Zak
c07ebfa1e0 Imported from util-linux-2.11b tarball. 2006-12-07 00:25:46 +01:00
Karel Zak
66ee8158b6 Imported from util-linux-2.10s tarball. 2006-12-07 00:25:44 +01:00
Karel Zak
22853e4a82 Imported from util-linux-2.10m tarball. 2006-12-07 00:25:43 +01:00
Karel Zak
eb63b9b8f4 Imported from util-linux-2.10f tarball. 2006-12-07 00:25:41 +01:00
Karel Zak
7eda085c41 Imported from util-linux-2.9v tarball. 2006-12-07 00:25:39 +01:00
Karel Zak
5c36a0eb7c Imported from util-linux-2.9i tarball. 2006-12-07 00:25:37 +01:00
Karel Zak
2b6fc908bc Imported from util-linux-2.8 tarball. 2006-12-07 00:25:35 +01:00
Karel Zak
fd6b7a7ffc Imported from util-linux-2.7.1 tarball. 2006-12-07 00:25:34 +01:00
Karel Zak
6dbe3af945 Imported from util-linux-2.2 tarball. 2006-12-07 00:25:32 +01:00