Commit Graph

1837 Commits

Author SHA1 Message Date
Michael Forney
fa0e5d6378 libutil/unescape: NULL terminate unescaped string
In commit 30fd43d7f3, unescape was
simplified significantly, but the new version failed to NULL terminate
the resulting string.

This causes bad behavior in various utilities, for example tr:

Broken:

  $ echo b2 | tr '\142' '\143'
  c3

Fixed:

  $ echo b2 | tr '\142' '\143'
  c2

This bug breaks libtool's usage of tr, causing gcc to fail to build with
sbase.
2017-03-24 10:40:32 +01:00
Michael Forney
72b49a065b test: Use complete prototypes in func field of struct test
Function declarators with empty parentheses is an obsolescent feature in
C99, and it is not clear to me that the standard allows assigning
assigning a function pointer declared in this way to a function declared
in prototype-format.

In any case, using a union for the functions is just as simple and
enforces that we pass the correct types to the functions.
2017-03-24 10:39:19 +01:00
Mattias Andrée
30fd43d7f3 libutil/unescape.c: simplify and add \E
Signed-off-by: Mattias Andrée <maandree@kth.se>
2017-02-06 15:47:01 -08:00
Mattias Andrée
9a903c63de libutil/unescape.c: only print argv0 once on error
Signed-off-by: Mattias Andrée <maandree@kth.se>
2017-02-06 14:13:40 -08:00
Mattias Andrée
2c424c078a cp.1: source and dest are not optional
Signed-off-by: Mattias Andrée <maandree@kth.se>
2017-01-31 10:32:30 -08:00
Mattias Andrée
d301322cf2 getconf: fail if any other flag than -v is used
Signed-off-by: Mattias Andrée <maandree@kth.se>
2017-01-31 10:27:59 -08:00
Roberto E. Vargas Caballero
9ab1478f1e ed: fix commit 2ccc1e8
The patch was wrong because the prototype of
strcpy is different to the prototype of strlcpy
2017-01-10 11:30:34 +01:00
Roberto E. Vargas Caballero
b95c8ed79e ed: Don't use strlcpy()
All the buffers related to files have FILENAME_MAX size, so it is impossible
to have any buffer overrun.
2017-01-10 08:49:17 +01:00
Roberto E. Vargas Caballero
78bfd8978e Revert "ed: remove double free in join()"
This reverts commit 30da327fbd.
The double free is needed to avoid memory leaks when signals are caught
2017-01-10 08:41:35 +01:00
Thomas Mannay
89f5f84316 ed: Treat addresses of 0 as 1 for insert
From 6665eaa1d2c25a95b44a4f4fb3d24a3bd5c1180f Mon Sep 17 00:00:00 2001
From: Thomas Mannay <audiobarrier@openmailbox.org>
Date: Thu, 3 Nov 2016 15:16:32 +0000
Subject: [PATCH] Treat addresses of 0 as 1 for insert
2017-01-02 20:57:00 +01:00
Quentin Rameau
441f73a518 ls: print filenames on the fly rather than in a buffer 2016-12-28 12:23:03 -08:00
Robert Karl
60da4fb049 paste: fix warning on indentation in parallel()
_Bug_
Got the following error after cloning and running make:

paste.c: In function ‘parallel’:
paste.c:70:4: warning: this ‘else’ clause does not guard... [-Wmisleading-indentation]
    else
    ^~~~
paste.c:72:5: note: ...this statement, but the latter is misleadingly indented as if it is guarded by the ‘else’
     last++;
     ^~~~
This patch preserves the same functionality and just adjusts indentation to squelch the warning.

_Test plan_
Used the following 'script' to convince myself output looked correct for inputs
where the latter arguments to paste had fewer lines.

	make && printf "1\n2\n" > two.txt && printf "" > zero.txt && ./paste -d, two.txt zero.txt
2016-12-27 15:02:15 +01:00
Michael Forney
2481042651 cp: Also preserve atime/mtime for symlinks
Laslo: Fixed style a bit and added comment
2016-12-27 14:50:58 +01:00
Michael Forney
e03a57df92 cp: Check result of utimensat
POSIX says that if duplicating the modification/access times fails, then
an error should be written to stderr.
2016-12-27 14:46:11 +01:00
Michael Forney
a8a9b3bae9 xinstall: Check result of fchmod 2016-12-27 14:37:20 +01:00
Michael Forney
5e4e6aeb3e od: Fix buffer overflow if -N flag is larger than BUFSIZ
Previously, if max was specified, od will call read with that size,
potentially overflowing buf with data read from the file.
2016-12-27 14:32:04 +01:00
Laslo Hunhold
9e594a986e Add a TODO-note about crypt.c 2016-12-27 14:30:51 +01:00
Michael Forney
52e49329e5 crypt: Add some missing error checks for cryptsum
Previously, if a file failed to read in a checksum list, it would be
reported as not matched rather than a read failure.

Also, if reading from stdin failed, previously a bogus checksum would be
printed anyway.
2016-12-27 14:02:32 +01:00
Mattias Andrée
609169d600 install: ignore -s
The -s flag previously called strip(1) on the installed file.
This patch changes install(1)'s behaviour to ignore -s.

Many makefiles use the -s flag, so it has to be recognised for
compatibility, however it does not have to do anything because
symbols do not negatively affect the functionallity of binaries.

Ignoring -s have the added benefit that the user do not need
to edit makefiles if they want the symbols that are useful for
debugging. If the user wants to strip away symbols, it can be
done manually or automatically by the package manager.

Laslo: Update the man-date and remove -s from usage()

Signed-off-by: Mattias Andrée <maandree@kth.se>
2016-12-27 13:56:27 +01:00
Michael Forney
b7fb3a58e7 xinstall: Fix broken memmove with -t
memmove moves a number of bytes, not pointers, so if you passed a number
of arguments that is larger than the pointer byte size, you could
end up crashing or skipping the install of a file and installing another
twice.

Also, argv was never decreased to match the moved arguments, so the -t
parameter was added in the NULL argv slot.
2016-12-27 13:48:59 +01:00
Michael Forney
87f40834a3 parsemode: No need to return after eprintf
Also, since parsemode exits on failure, don't bother checking return
value in xinstall (this would never trigger anyway because mode_t can be
unsigned).
2016-12-27 13:33:35 +01:00
parazyd
aded902891 remove install.1 on make uninstall
Just a minor fix since xinstall.1 is installed as install.1.
2016-12-27 13:30:08 +01:00
Evan Gates
123f784ccc printf: handle \0 in %b arguments
The %b case was using fputs after unescape to print the argument, which
meant that it could not handle nul bytes. Instead, store the length
returned from unescape and use fwrite to properly handle them.
2016-12-27 13:25:38 +01:00
Evan Gates
d6154bd87f Makefile: sort file lists 2016-12-27 13:16:53 +01:00
Evan Gates
4b5a948cee targets must be prerequisites to .PHONY not commands 2016-12-27 13:15:10 +01:00
Laslo Hunhold
e2f886c7e2 ed: Use strlcpy() instead of strcpy() and other minor things
Based on contribution by Ali H. Fardan, thanks!
2016-12-27 13:07:02 +01:00
Thomas Mannay
370e0ae675 ed: add manpage
Laslo: Fix some things pointed out by mandoc -Tlint:
	1) replace empty lines with .Pp, we want to start a new
	   paragraph
	2) Add a comma before the second item in SEE ALSO
	3) Place SEE ALSO before STANDARDS, as is the convention
	4) Update the man-date
2016-12-27 12:53:30 +01:00
Thomas Mannay
30da327fbd ed: remove double free in join() 2016-12-27 12:50:25 +01:00
Thomas Mannay
2304df908c ed: place newly joined lines correctly 2016-12-27 12:50:20 +01:00
Thomas Mannay
696520714b ed: giving j only one address does nothing 2016-12-27 12:50:09 +01:00
Thomas Mannay
61e06396bd ed: remove infinite loops in join() and getindex() 2016-12-27 12:50:03 +01:00
Evan Gates
d2bd40a589 find: remove VLAs
Laslo: Use ereallocarray and fix the style a bit
2016-12-27 12:46:06 +01:00
Evan Gates
0b27c0c9a0 find: estrdup before basename
"The basename() function may modify the string pointed to by path..."
Thanks POSIX

Laslo: Changed the style a bit
2016-12-27 12:37:57 +01:00
Wolfgang Corcoran-Mathe
b7c73e2392 ed: Fix backslash expressions in RHS
By stripping backslashes this code caused a number of bugs.
'\<digit>' expressions caused literal <digit>s to be subbed-in,
'\&' was treated identically to '&', and other escaped characters
added garbage to the string.
2016-12-27 12:29:52 +01:00
Wolfgang Corcoran-Mathe
f5baf2630a ed: Don't match against line 0 in search()
regexec(3) happily matches /^$/ against the text of line
zero (the null string), causing an error.

Also update email address for Wolfgang Corcoran-Mathe
2016-12-27 12:28:36 +01:00
Mattias Andrée
28129a87c4 Add rev(1)
Signed-off-by: Mattias Andrée <maandree@kth.se>
2016-12-27 11:35:27 +01:00
Laslo Hunhold
fb11173926 tr: Fix multiple ranges with different lengths (Michael Forney)
See his description below. Thanks Michael!

---
A bug was introduced in bc4c293fe5 causing the
range length for the next set to be used instead of the first one. This causes
issues when choosing the replacement rune when the ranges are of different
lengths.

Current behavior:

$ echo 1234 | tr 'a-f1-4' '1-6a-d'
56ab

Correct behavior:

$ echo 1234 | tr 'a-f1-4' '1-6a-d'
abcd

This also fixes range expressions in the form [a-z], which get encoded as four
ranges '[', 'a'..'z', ']', causing all a-z characters to get mapped to ']'. This
form is occasionally used in shell scripts, including the syscalltbl.sh script
used to build linux.
---
2016-11-18 12:45:59 +01:00
Evan Gates
d24ef864cb ls: respect -q when printing directory names with -R
break out the non printable character to ? code into a makeprint()
function so it can be used both in output() and lsdir()
2016-10-06 10:21:12 +02:00
Evan Gates
071dcc4d6b ls: fix ls -lq to respect -q flag 2016-10-06 10:21:12 +02:00
Laslo Hunhold
b5ebd49dd3 tr: Provide a fallthrough case for single-arg -s
Previously, this would not work properly and not be let through the
sanity check.

This is a dirty hack until the next iteration where I'll clean up the
data structures and make this saner.
2016-10-06 02:00:25 +02:00
Laslo Hunhold
c154ef7a03 tr(1): Properly handle the -dc case for character classes
I actually did that properly in the set-case but forgot to add the same
logic to the character classes. Now it should work fine.
2016-10-06 00:16:30 +02:00
Laslo Hunhold
096c504d82 tr(1): Properly jump to output when inside set complement 2016-10-05 21:54:51 +02:00
Laslo Hunhold
456f3c4211 tr.1: Make note of some changes in the utility 2016-10-05 21:42:24 +02:00
FRIGN
bc4c293fe5 Revamp tr(1) set parsing and handling
If you look at GNU coreutils, they do not support the mappings

	$ echo "1234abc" | tr "[:alnum:]" "[:upper:]"

	$ echo "ABCabc" | tr -c "[:upper:]" "[l*]"

to only give a few examples. This commit broadens the scope of tr(1)
as far as humanly possible to map between classes and non-classes,
making tr a usable tool and actually fulfilling user expectations.
Posix really is of no help here as it still kind of assumes the
fixed ASCII table instead of complex Unicode code points or even
Grapheme clusters.
2016-10-05 21:18:24 +02:00
FRIGN
9de401a495 Fix tr(1) squeezing
Okay, it took me a while and another look at the Posix spec to see that
I have been dealing with squeezing in a way too complicated way.
What just needed to be done is before doing the final write to deploy
the squeeze-check. We actually do not need this atomically complicated
squeeze check in every single edge-case. Now it should work properly.
2016-10-05 19:31:50 +02:00
FRIGN
fac091b7cc getconf.sh: Be more explicit we are using a heredoc here 2016-10-05 18:48:10 +02:00
Evan Gates
de28c8bfa7 use only one getconf header
this simplifies the getconf.sh script and handling parallel make
2016-10-05 18:48:10 +02:00
Mattias Andrée
96ccf5172d find: check whether readdir failed, and properly check timestamps
Signed-off-by: Mattias Andrée <maandree@kth.se>
2016-10-05 18:48:10 +02:00
Mattias Andrée
e8a3a3ec37 test: -erwx test against effetive uid/gid, not real
Signed-off-by: Mattias Andrée <maandree@kth.se>
2016-10-05 18:48:10 +02:00
Mattias Andrée
da04e4cc2a pathchk: fixes and cleanup
Signed-off-by: Mattias Andrée <maandree@kth.se>
2016-10-05 18:48:10 +02:00