Commit Graph

1839 Commits

Author SHA1 Message Date
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
Evan Gates
e3f497e1f6 subtract 'a' from indices for marks
Given:

static int marks['z' - 'a'];
marks[c];

In this case c is the character read and index is out of bounds. We
need marks[c - 'a']

While playing around with optimization settings gcc caught caught this.

Also fix one check for c, change from isalpha to islower.

-emg

From 2cc36818283e9068576c1042690c016a81b709a3 Mon Sep 17 00:00:00 2001
From: Evan Gates <evan.gates@gmail.com>
Date: Fri, 15 Jul 2016 09:52:39 -0700
Subject: [PATCH] fix marks indexing
2016-08-03 15:35:36 +01:00
Michael Forney
3c12b287ec touch: Avoid unnecessary call to stat
Now, we first try a utimensat. If it succeeds, we are done, if not (and no -c
flag), create the file, then set the times with futimens.
2016-07-09 10:17:16 +01:00
Michael Forney
2e5f1281ed touch: Use special UTIME_NOW and UTIME_OMIT values
This allows users to touch files they have write access to, but aren't the
owner.

Also, remove utime.h include (not necessary since
4132561c17), and make sure to check the return
value of localtime (potentially preventing a NULL pointer derefence).
2016-07-09 10:17:16 +01:00
Michael Forney
36a0a6cd92 touch: Remove useless variable
The only possible return values of stat are 0 or -1, so it doesn't make sense to
store the return value in a variable to make sure it is not positive.
2016-07-09 10:17:16 +01:00
Michael Forney
0941c9ab2c touch: Respect caller's umask
Currently, if the caller has a umask of 002 or 000, the file gets created as 644
anyway.

Also, add O_WRONLY to the open call, since POSIX says that "Applications shall
specify exactly one of the first five values (file access modes) below in the
value of oflag".
2016-07-09 10:17:16 +01:00
Michael Forney
a211649cfd ln: Only fail if same inode without -f flag 2016-07-09 10:17:16 +01:00
Michael Forney
083d1451ac install: Handle -c flag as a no-op
This is required in order for autoconf's AC_PROG_INSTALL to use the sbase
install. Otherwise it will fall back to the slow and sucky install-sh script
from automake.
2016-07-09 10:17:16 +01:00
Michael Forney
49e1854600 od: Don't advance past end of type string
Currently, if you specify -t x, then s is advanced once in the switch statement
to determine the length, and then once again in the for loop, resulting in a
read past the end of the argument.

Also, use sizeof(int) when no length is specified, as specified by POSIX.
2016-07-09 10:17:16 +01:00
Michael Forney
5ae2793da6 od: Add some missing type flags 2016-07-09 10:17:16 +01:00
Michael Forney
8ca79a2993 linecmp: Handle NUL bytes properly
Test case:

if [ "$(printf 'a\na\0b' | ./sort -u)" = "$(printf 'a\na\0b')" ] ; then
	echo pass
else
	echo fail
fi
2016-07-09 10:09:50 +01:00
Michael Forney
a944b682a6 sort: Fix line comparison when col buffer contains data from longer line
I'm not sure if there are other implications of this or not, but
the issue is that columns() uses len to store the allocated buffer
size, but linecmp() compares up to len bytes. If those trailing
bytes do not match, the line is considered not matching, even though
the relevant parts of the buffer do match.

To resolve this, also keep track of column capacity. Additionally,
since there is no reason to keep the existing data when resizing,
just use free and emalloc rather than erealloc.

The simplest case I could reduce it to is this:

if [ "$(printf '%s\n' a a xxb xxc | ./sort -u)" = "$(printf '%s\n' a xxb xxc)" ] ; then
	echo pass
else
	echo fail
fi
2016-07-09 10:09:50 +01:00
Michael Forney
d827fcace2 ls: Simplify some logic
- After first iteration, set first to 0 instead of !first.
- If Hflag || Lflag, then mkent used stat instead of lstat, so the
  entity cannot be a symlink.
- Print path prefix along with directory name.
- In the 'if (Rflag)' block, just use 1 instead of Rflag.
2016-07-09 10:09:50 +01:00
Michael Forney
ea03da0bda ls: Don't show directory name with single directory operand
This fixes the issue b107489bf2 tried
to fix, but doesn't break -R (which
bb83eade39 tried to fix).
2016-07-09 10:09:50 +01:00
Michael Forney
e8e9b97baf Revert "ls: only display directory headers when more than one directory is specified"
This reverts commit b107489bf2.
2016-07-09 10:09:50 +01:00
Michael Forney
b91b9e79ec Revert "Fix showing directories when -R flag is set in ls(1)"
This reverts commit bb83eade39.

This commit causes the loop through dents at the end of main to
continue past the end of the dents array, causing a crash when
called with multiple directory arguments.
2016-07-09 10:09:50 +01:00
pranomostro
229d7cc89a printf: support escaping '%' with '%%'. See printf(1p) EXAMPLES section. 2016-06-27 11:21:47 +01:00
sin
11d8e91042 tee: Make sure we continue on error 2016-06-23 19:38:05 +01:00
Michael Forney
0ba879cdba grep: Fix -v output and exit status
Previously, it printed lines that didn't match some pattern. Instead,
it should print lines that don't match *any* pattern.

Test case:

out=$(echo foo | ./grep -v -e foo -e bar)
if [ "$?" = 1 ] && [ -z "$out" ] ; then
	echo pass
else
	echo fail
fi
2016-05-14 12:58:38 +01:00
Michael Forney
e6b3af07cf grep: Fix exit status with -F when last line doesn't match
Test case:

if printf '%s\n' foo bar | ./grep -F foo >/dev/null ; then
	echo pass
else
	echo fail
fi
2016-05-14 12:58:38 +01:00
Michael Forney
8636c956d9 grep: Reverse some if-else logic
This way, people don't have to do double negatives in their head.
2016-05-14 12:58:38 +01:00
FRIGN
c7ea20a9cb Update Kurt H. Maier's E-Mail address 2016-04-29 12:16:51 +01:00
FRIGN
afc944d9b8 Remove locale-cancer from grep(1)
What in the actual fuck? Check the ml history on why we won't use
locale() functions in this context.
2016-04-29 12:16:51 +01:00
Mattias Andrée
727f795e94 grep: fix UTF-8 support
Signed-off-by: Mattias Andrée <maandree@kth.se>
2016-04-20 22:57:40 +01:00
Mattias Andrée
7250fb6968 printenv: exit status is 2 on failure
This provides a reliable and portable way to
test whether an environment variable is defined.

(Of course, if you are using glibc you may get
false positives if you include a = in the query.)

Signed-off-by: Mattias Andrée <maandree@kth.se>
2016-04-20 22:57:40 +01:00
Mattias Andrée
dfc94e0221 ls: fix segfault when timestamp is out of range for struct tm
Signed-off-by: Mattias Andrée <maandree@kth.se>
2016-04-20 22:57:40 +01:00
Mattias Andrée
33c5c71e01 Update test.1:
Document -ef, -ot, and -nt.
-k was already documented somewhy it seems...

Signed-off-by: Mattias Andrée <maandree@kth.se>
2016-04-20 22:57:40 +01:00
Hiltjo Posthuma
8d96afd4fb touch: make invalid date an error and fix uninitialised value
reproduce: touch -t 12345678 mytralala

would only give a warning and use uninitialised time values. The proper
way is to treat it as an error. Clear the "struct tm" and kill some lines
just in case.
2016-04-15 19:53:01 +01:00
sin
d89cd48118 test: Sort includes 2016-03-26 19:07:45 +00:00
sin
4093341657 test: Remove unused variable 2016-03-26 08:18:47 +00:00
Mattias Andrée
35a114acd5 test: add support for big integers
Signed-off-by: Mattias Andrée <maandree@kth.se>
2016-03-26 08:18:47 +00:00
Mattias Andrée
1ea414e300 test: add -k, -ef, -ot, and -nt
Signed-off-by: Mattias Andrée <maandree@kth.se>
2016-03-26 08:18:47 +00:00
Mattias Andrée
44a6d65832 *sum: support - when using -c
Signed-off-by: Mattias Andrée <maandree@kth.se>
2016-03-26 08:18:47 +00:00
Michael Forney
75611997f9 sort: Fix -c option
In eb9bda8787, a bug was introduced in the
handling of -1 return values from getline. Since the type of the len
field in struct line is unsigned, the break condition was never true.
This caused sort -c to never succeed.
2016-03-13 11:08:36 +00:00
Eivind Uggedal
d4f7ecd334 uniq: always store previous line length
A bug was introduced in the NUL support refactor leading to
the length of the previous line only being saved if the
previous line was shorter than the current line. If triggered
this lead to copying too much data into the previous line buffer.

Behavior before:

	printf '1234\na\n' | ./uniq
	1234
	a
	4

Behavior after:

	printf '1234\na\n' | ./uniq
	1234
	a
2016-03-11 15:38:36 +00:00
FRIGN
515525997c Fix linecmp() to return correct values 2016-03-11 15:38:36 +00:00
FRIGN
0b87cd4c61 Properly use delimlen instead of len in paste(1) 2016-03-10 13:39:49 +00:00
FRIGN
7fd88bdc6f xargs(1) already supports NUL characters 2016-03-10 08:48:09 +00:00
FRIGN
5b7df455f8 Change paste(1) a bit to prepare libutf changes 2016-03-10 08:48:09 +00:00
FRIGN
e537186ba4 Support NUL containing lines in uniq(1) 2016-03-10 08:48:09 +00:00
FRIGN
b58884312c Support NUL containing lines in nl(1) and reuse the line-buffer(!) 2016-03-10 08:48:09 +00:00
FRIGN
c25996924b Support NUL containing lines in join(1)
while also simplyfing the line-field-parser.
2016-03-10 08:48:09 +00:00
FRIGN
d7741c7725 Support NUL containing lines in fold(1) and reuse the line-buffer(!) 2016-03-10 08:48:09 +00:00
FRIGN
dc5190eab1 logger(1) is NUL compliant
because we can't call the syslog-syscall without becoming unportable.
The syslog() libc-function does not accept a length though, so we're
fucked. Anyway, let's carry on.
2016-03-10 08:48:09 +00:00
FRIGN
00b579566a Use the UTF8_POINT macro in cols(1)
No need for libutf any more
2016-03-10 08:48:09 +00:00
FRIGN
cc3aefa488 Support NUL containing lines in cut(1) 2016-03-10 08:48:09 +00:00
FRIGN
5ad71a466b Error out when giving an empty delimiter to sort(1) 2016-03-10 08:48:09 +00:00
FRIGN
3debc5e064 Add linecmp() 2016-03-10 08:48:09 +00:00
FRIGN
698a14b1da Indent README headings properly 2016-03-10 08:48:09 +00:00