sbase/libutil
FRIGN 3c33abc520 Implement mallocarray()
A function used only in the OpenBSD-Kernel as of now, but it surely
provides a helpful interface when you just don't want to make sure
the incoming pointer to erealloc() is really NULL so it behaves
like malloc, making it a bit more safer.

Talking about *allocarray(): It's definitely a major step in code-
hardening. Especially as a system administrator, you should be
able to trust your core tools without having to worry about segfaults
like this, which can easily lead to privilege escalation.

How do the GNU coreutils handle this?
$ strings -n 4611686018427387903
strings: invalid minimum string length -1
$ strings -n 4611686018427387904
strings: invalid minimum string length 0

They silently overflow...

In comparison, sbase:

$ strings -n 4611686018427387903
mallocarray: out of memory
$ strings -n 4611686018427387904
mallocarray: out of memory

The first out of memory is actually a true OOM returned by malloc,
whereas the second one is a detected overflow, which is not marked
in a special way.
Now tell me which diagnostic error-messages are easier to understand.
2015-03-10 22:19:19 +01:00
..
agetcwd.c Fix off-by-one in apathmax() as the path is relative to "/" 2015-03-06 23:50:39 +00:00
apathmax.c Fix off-by-one in apathmax() as the path is relative to "/" 2015-03-06 23:50:39 +00:00
concat.c Switch concat() to use fread() and fwrite() 2015-02-09 15:24:03 +00:00
cp.c Fix off-by-one in apathmax() as the path is relative to "/" 2015-03-06 23:50:39 +00:00
crypt.c Make already audited tools argv-centric instead of argc-centric 2015-03-02 14:19:26 +01:00
ealloc.c add estrndup 2015-02-11 01:17:21 +00:00
enmasse.c Fix off-by-one in apathmax() as the path is relative to "/" 2015-03-06 23:50:39 +00:00
eprintf.c Rename util/ to libutil/ 2014-11-17 16:48:34 +00:00
eregcomp.c Rename util/ to libutil/ 2014-11-17 16:48:34 +00:00
estrtod.c Rename util/ to libutil/ 2014-11-17 16:48:34 +00:00
fnck.c Refactor enmasse() and recurse() to reflect depth 2015-03-02 22:50:38 +01:00
getlines.c Make getlines() less verbose 2015-02-12 14:34:07 +00:00
human.c Rename util/ to libutil/ 2014-11-17 16:48:34 +00:00
mallocarray.c Implement mallocarray() 2015-03-10 22:19:19 +01:00
md5.c Rename util/ to libutil/ 2014-11-17 16:48:34 +00:00
mode.c Rename util/ to libutil/ 2014-11-17 16:48:34 +00:00
putword.c Rename util/ to libutil/ 2014-11-17 16:48:34 +00:00
reallocarray.c Implement mallocarray() 2015-03-10 22:19:19 +01:00
recurse.c Use path[len] instead of *(path + len) 2015-03-03 00:31:27 +01:00
rm.c Refactor enmasse() and recurse() to reflect depth 2015-03-02 22:50:38 +01:00
sha1.c Rename util/ to libutil/ 2014-11-17 16:48:34 +00:00
sha256.c Rename util/ to libutil/ 2014-11-17 16:48:34 +00:00
sha512.c Rename util/ to libutil/ 2014-11-17 16:48:34 +00:00
strcasestr.c Argh - include strings.h 2014-11-21 00:03:30 +00:00
strlcat.c Rename util/ to libutil/ 2014-11-17 16:48:34 +00:00
strlcpy.c Rename util/ to libutil/ 2014-11-17 16:48:34 +00:00
strsep.c Import strsep() from musl libc 2015-01-25 17:48:11 +00:00
strtonum.c Use strtonum and libutf in test(1), refactor code and manpage 2015-02-09 22:21:23 +01:00
unescape.c Add \e, \", \' and hex-escapes (\xH[H]) to unescape() 2015-02-14 22:55:37 +01:00