summaryrefslogtreecommitdiff
path: root/util/libreboot-utils/lib
AgeCommit message (Collapse)Author
19 hourslbutils/file: don't use undefined USE_OPENATLeah Rowe
clang -Weverything told me to Signed-off-by: Leah Rowe <leah@libreboot.org>
20 hourslbutils/file: don't loop EINTR on close()Leah Rowe
state is undefined after EINTR. just abort universally. Signed-off-by: Leah Rowe <leah@libreboot.org>
20 hourslbutils/file: fix implicit conversion on openat2Leah Rowe
as dictated by clang -Weverything Signed-off-by: Leah Rowe <leah@libreboot.org>
20 hourslbutils/file: fix overflow checkLeah Rowe
clang -Weverything: lib/file.c:165:49: warning: implicit conversion changes signedness: 'ssize_t' (aka 'long') to 'size_t' (aka 'unsigned long') [-Wsign-conversion] 165 | if (if_err(rval >= 0 && (size_t)rval > (nrw - rc), EOVERFLOW)) Signed-off-by: Leah Rowe <leah@libreboot.org>
21 hourslbutils: remove more unused macrosLeah Rowe
detected via clang -Weverything Signed-off-by: Leah Rowe <leah@libreboot.org>
21 hourslbutils/file: remove unused macroLeah Rowe
not needed here (detected with clang -Weverything) Signed-off-by: Leah Rowe <leah@libreboot.org>
21 hourslbutils/file: rename rw_file_exactLeah Rowe
call it rw_exact, so that it's closer to the name rw. it matches naming more closely; the alternative was to call rw rw_file but read/write can handle more than just files! Signed-off-by: Leah Rowe <leah@libreboot.org>
21 hourslibreboot-utils/file: never retry file rw on zeroLeah Rowe
even with a timer, it's possible that on a buggy system, we may keep writing even though the outcome is zero. if a system comes back with zero bytes written, that is a fatal bug and we should stop. Signed-off-by: Leah Rowe <leah@libreboot.org>
23 hourslbutils/rand: close fd on urandom errorLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
23 hourslbutils: remove rw on_eintr functions. just use rwLeah Rowe
rw is enough. i unified everything there. next commit will remove rw_type and instead run positional i/o depending on whether the offset is zero. i'm simplifying the API a lot. Signed-off-by: Leah Rowe <leah@libreboot.org>
25 hourslbutils: support using arc4random on linuxLeah Rowe
-DUSE_ARC4=1 use that Signed-off-by: Leah Rowe <leah@libreboot.org>
25 hourslbutils: don't set USE_OPENAT and USE_URANDOMLeah Rowe
these can be set explicitly in the compiler flags, e.g. make CC="cc -DUSE_OPENAT=1 -DUSE_URANDOM=1" these options, if set to 1, will cause you to use the code as if it were running on non-linux systems such as openbsd. of course, some differences will still exist, but this is useful for portability testing when compiling on linux. Signed-off-by: Leah Rowe <leah@libreboot.org>
26 hourslbutils: only use GNU SOURCE for syscallLeah Rowe
and remove manual prototypes; fchmod, realpath and so on rely on the _XOPEN_SOURCE macro. the POSIX macro wasn't needed: _XOPEN_SOURCE is sufficient. Signed-off-by: Leah Rowe <leah@libreboot.org>
27 hourslibreboot-utils: don't use the GNU SOURCE macroLeah Rowe
use the POSIX one declare prototypes where necessary. Signed-off-by: Leah Rowe <leah@libreboot.org>
28 hourslibreboot-utils: fix ALL compiler warningsLeah Rowe
i wasn't using strict mode enough in make: make strict now it compiles cleanly. mostly removing unused variables, fixing implicit conversions, etc. Signed-off-by: Leah Rowe <leah@libreboot.org>
31 hourslibreboot-utils: loop fcntl on eintrLeah Rowe
but i can't write a generic function for this, because fcntl is a variadic function, so wrapping cannot be done cleanly. Signed-off-by: Leah Rowe <leah@libreboot.org>
32 hourssafer macroLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
44 hourslibreboot-utils: stricter errno handlingLeah Rowe
where possible, try not to clobber sys errno. override it only when relatively safe. also: when a syscall succeeds, it may set errno. this is rare, but permitted (nothing specified against it in specs, and the specs say that errno is undefined on success). i'm not libc, but i'm wrapping around it, so i need to be careful in how i handle the errno value. also: i removed the requirement for directories to be executable, in mkhtemp.c, because this isn't required and will only break certain setups. in world_writeable and sticky, i made the checks stricter: the faccessat check was being skipped on some paths, so i've closed that loophole now. i also generally cleaned up some code, as part of the errno handling refactoring, where it made sense to do so, plus a few other bits of code cleanup. Signed-off-by: Leah Rowe <leah@libreboot.org>
47 hourslbutils/rand: add missing error handleLeah Rowe
accidentally removed in previous refactor Signed-off-by: Leah Rowe <leah@libreboot.org>
2 dayslbutils/file: only support real pread/pwriteLeah Rowe
the portable version was written for fun, but it's bloat, and makes the code hard to read. every unix since about 2005 has these functions. Signed-off-by: Leah Rowe <leah@libreboot.org>
2 dayslbutils/file: don't alllow EAGAIN/EWOULDBLOCKLeah Rowe
a non-blocking file descriptor could be used while errno is set to these. this would create an infinite loop. it's better that we only allow EINTR. Signed-off-by: Leah Rowe <leah@libreboot.org>
2 dayslbutils/file: remove ETXTBSY from exemption on ioLeah Rowe
obsolete. ripe for abuse. do not permit this error. Signed-off-by: Leah Rowe <leah@libreboot.org>
2 dayslbutils/file: don't reset errno on successful ioLeah Rowe
some io syscalls may set errno on success. this patch honours that. we try to preserve caller errno, but it is important for debugging not to clobber it. if fs_err_retry errs, then we don't reset errno. if fs_err is successful but errno wasn't set, we restore caller errno. this is done by setting errno to zero in callers, which also restore caller errno. Signed-off-by: Leah Rowe <leah@libreboot.org>
2 dayslibreboot-utils: unified EINTR loop handlingLeah Rowe
absolutely unified. Signed-off-by: Leah Rowe <leah@libreboot.org>
2 daysTODOLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
2 dayslibreboot-utils: unified max path lengthsLeah Rowe
just use PATH_MAX like a normal person with additional safety Signed-off-by: Leah Rowe <leah@libreboot.org>
3 dayslibreboot-utils: more flexible string usageLeah Rowe
i previously used error status and set return values indirectly. i still do that, but where possible, i also now return the real value. this is because these string functions can no longer return with error status; on error, they all abort. this forces the program maintainer to keep their code reliable, and removes the need to check the error status after using syscalls, because these libc wrappers mitigate that and make use of libc for you, including errors. this is part of a general effort to promote safe use of the C programming language, especially in libreboot! Signed-off-by: Leah Rowe <leah@libreboot.org>
3 dayslbutils: strict string functions - abort on errLeah Rowe
on the conditions where these functions encounter an unexpected error, we currently return -1 this means that the caller must check. which means the caller won't check. nobody does. i often forget. force the caller (me) to be correct, instead. the current calling convention is that the real return value is stored in a pointer, provided inside the function signature, on a given string function, and the function's return value is merely an indicator. this calling convention is retained for now; the next patch will change it, such that the real value is also the function's return value. this is more flexible. Signed-off-by: Leah Rowe <leah@libreboot.org>
3 dayslibreboot-utils: optimised string functionsLeah Rowe
operate per word, not per byte this is also done on sdup, which uses a slightly inefficient method: the new string allocation is that of the maximum size, rather than what we need. for example, if you wanted a 20 character string (21 including null), you would still allocate 4096 bytes if that was the maximum length. it's a bit naughty, and i have half a mind to keep sdup on the old implementation, but i'll leave it be for now. Signed-off-by: Leah Rowe <leah@libreboot.org>
4 dayslibreboot-utils: safe memcmpLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
4 dayslbutils hexdump: reduce width on smaller integersLeah Rowe
showing the size for 64-bit high integers seems silly Signed-off-by: Leah Rowe <leah@libreboot.org>
4 dayslibreboot-utils/lib: loop eintr on [p]read/[p]writeLeah Rowe
i forgot to do this! with this, I/O should be bullet proof now. i already loop this on other I/O commands. Signed-off-by: Leah Rowe <leah@libreboot.org>
4 daysmkhtemp: rename variable for clarityLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
4 dayshexdump performance test, part 1Leah Rowe
spoiler alert: it's slow as molasses part 2 will be presented at a later date (yes, please don't fill 8GB of memory with random data and hexdump it) Signed-off-by: Leah Rowe <leah@libreboot.org>
4 daysmkhtemp: generalised string concatenationLeah Rowe
scatn in strings.c was buggy, so i replaced it; it concatenates any number of things. Signed-off-by: Leah Rowe <leah@libreboot.org>
4 dayslbutils: simplify getprogname usageLeah Rowe
the functions no longer return errors, so i don't need to handle them. furthermore, the handling in state.c is redundant, so i've removed that too. Signed-off-by: Leah Rowe <leah@libreboot.org>
4 dayslibreboot-utils: simplify random tmpdir namegenLeah Rowe
generalise it in rand.c because this logic will be useful for other programs in the future. Signed-off-by: Leah Rowe <leah@libreboot.org>
4 dayslbutils: rename mkrbuf to rmallocLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
4 dayslibreboot-utils: simplify lbgetprognameLeah Rowe
make it more reliable; it can't segfault now, under any circumstance. not even once. the problem arised when lbsetname was not called in a program, before calling the function: lbgetprogname. a segfault would occur, due to it being NULL. not every os/libc has getprogname, so i have my own implementation. Signed-off-by: Leah Rowe <leah@libreboot.org>
4 daysutil/nvmutil: better hexdumpLeah Rowe
this is a more generic one that i implemented for "lottery.c" (which is really just a tester of my rset function in lib/rand.c) i could probably actually write a full hexdump program in libreboot-utils to be honest. Signed-off-by: Leah Rowe <leah@libreboot.org>
4 dayscleanupLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
5 daysTODOLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
5 daysTODOLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
5 daysmkhtemp: use O_NOFOLLOW in same_dirLeah Rowe
we have a policy: symlinks do not exist. Signed-off-by: Leah Rowe <leah@libreboot.org>
5 daysTODOLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
5 dayslbutils env_tmpdir: use static strings for fallbackLeah Rowe
i currently return pointers to these, without copying. they can fade because of this. make them static, since that is what they should be anyway. Signed-off-by: Leah Rowe <leah@libreboot.org>
5 dayslbutils: unify xopen and open_on_eintrLeah Rowe
use open_on_eintr for gbe files Signed-off-by: Leah Rowe <leah@libreboot.org>
5 dayslibreboot-utils: unified errno handling on returnsLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
5 dayslibreboot-utils: much stricter open() handlingLeah Rowe
abort on error, and do EINTR looping Signed-off-by: Leah Rowe <leah@libreboot.org>
5 dayslbutils/file ffree_and_set_null: err if nullLeah Rowe
free can take a null, that's fine, but my pointer to the pointer being freed should not be null. that is a bug. Signed-off-by: Leah Rowe <leah@libreboot.org>