Commit Graph

3552 Commits

Author SHA1 Message Date
Leah Rowe
bf9c4a67f8 util/spkmodem-recv: handle fread errors
also handle EOF condition and exit cleanly.

don't use dirty feof.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-11 23:30:22 +00:00
Leah Rowe
9195ff97b7 util/spkmodem-recv: fix getopt prototype
i use -pedantic and std=c90

also add the define

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-11 23:25:50 +00:00
Leah Rowe
62c0cc68c5 removed some unnecessary things
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-11 23:14:51 +00:00
Leah Rowe
361dbef41c another fix
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-11 23:13:33 +00:00
Leah Rowe
7af3015a89 tiny fix
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-11 23:12:27 +00:00
Leah Rowe
6962404ce5 util/spkmodem-recv: portability and code cleanup
borrowing recent improvements from nvmutil

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-11 22:39:16 +00:00
Leah Rowe
977c83873e util/nvmutil: re-use do_rw() from prw()
using a special leah-only technique

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-10 18:20:47 +00:00
Leah Rowe
5f8fe4fdc3 util/nvmutil: add missing sanitization tests
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-10 17:17:39 +00:00
Leah Rowe
48f65abb01 util/nvmutil: properly use rc in rw_File_exact
subtract and add iteratively

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-10 16:57:46 +00:00
Leah Rowe
9eb3895f4e util/nvmutil: tidy up gbe_cat_buf()
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-10 16:52:38 +00:00
Leah Rowe
69cf4fe6ed util/nvmutil: split up rw_file_exact()
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-10 16:43:47 +00:00
Leah Rowe
454af12153 util/nvmutil: update some comments
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-10 16:25:43 +00:00
Leah Rowe
1403bdf1cc util/nvmutil: re-add EINTR loop check on rw
accidentally removed it during re-factor

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-10 16:17:33 +00:00
Leah Rowe
f0240df229 util/nvmutil: rename set_err for code clarity
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-10 16:14:43 +00:00
Leah Rowe
c41483916a util/nvmutil: skip errno check in main
skip it if there is a valid checksum, to mitigate
erroneous errno state upon exit from run_cmd(),
because we can assume by this point that we
are in fact ready to write at this point.

the check at the end still exists, which will catch
any error set by write, and any error set before
that. this fixes a weird warning on cmd_dump.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-10 16:06:13 +00:00
Leah Rowe
13c759bf3a util/nvmutil: don't reset errno in rw_file_exact
reset it in callers instead.

this means that the main function is more generalised.

we know by the time we exit that there is no error.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-10 16:02:57 +00:00
Leah Rowe
82dbeb9736 util/nvmutil: reset errno in gbe_cat
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-10 16:00:16 +00:00
Leah Rowe
9ba84d1117 util/nvmutil: reset errno in gbe_cat_buf
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-10 15:58:57 +00:00
Leah Rowe
ca37bef34f util/nvmutil: fix bad loop in command sanitizer
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-10 15:55:05 +00:00
Leah Rowe
9691e7e7db util/nvmutil: use set_err where appropriate
in the new file i/o functions, my own setting
of errno should be done with set_err. this
avoids clobbering what the real libc set.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-10 15:50:45 +00:00
Leah Rowe
59eac512eb util/nvmutil: properly set errno everywhere
i set it to ecanceled before. now i set it more
appropriately, for each type of error.

where a real syscall was called, or my file i/o
functions are used, err() is called with errno
itself as input, to avoid clobbering real errno.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-10 15:46:30 +00:00
Leah Rowe
3174806b3f util/nvmutil: fix /dev/random fallback
i forgot to set urandom_fd

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-10 15:38:30 +00:00
Leah Rowe
318c0eb95b Revert "util/nvmutil: fix check in command sanitizer"
This reverts commit b28076557b.

nope. the check was already correct before.
2026-03-10 15:36:43 +00:00
Leah Rowe
9b6b89250d util/nvmutil: don't use bad pointer cast in prw
in practise it's ok, but some compilers might complain.

all this change costs is a bit of branching inside a
loop, but compilers will sort that out.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-10 15:33:50 +00:00
Leah Rowe
b28076557b util/nvmutil: fix check in command sanitizer
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-10 15:30:10 +00:00
Leah Rowe
0b4e298cb1 util/nvmutil: use EINVAL in command sanitizen
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-10 15:29:23 +00:00
Leah Rowe
4819dcbc75 util/nvmutil: don't use xopen() for urandom
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-10 15:27:24 +00:00
Leah Rowe
9427285dce util/nvmutil: conservative use of errno
only use errno itself as the value

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-10 15:19:09 +00:00
Leah Rowe
1f953359cb util/nvmutil: re-try /dev/[u]random on EAGAIN
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-10 15:12:12 +00:00
Leah Rowe
b291bbf2e5 util/nvmutil: Make rw_file_exact an ssize_t
Use its return value. Don't exit from the function,
but actually treat it like a real syscall.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-10 15:03:16 +00:00
Leah Rowe
4bc7ba1e4b util/nvmutil: use O_NONBLOCK on /dev/[u]random
on some systems, it is otherwise blocking, but blocking
can be disabled, making access more reliable.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-10 14:25:43 +00:00
Leah Rowe
c953228bb0 util/nvmutil: fix possible overflow: gbe_x_offset
preventative fix, since the values are currently
quite tiny. this new check is the same, but goes
the other way to eliminate overflow.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-10 14:18:19 +00:00
Leah Rowe
883860d687 util/nvmutil: reset rw_file_exact errno on EINTR
this is essentially what it already did, but it
wasn't explicitly stated. now it's clearer.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-10 14:12:45 +00:00
Leah Rowe
6eefd80efe util/nvmutil: comment prw()
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-10 14:07:35 +00:00
Leah Rowe
06cb129530 util/nvmutil: better SSIZE_MAX define
the old one assumes that ssize_t is signed size_t,
which let's face it, is always true in practise,
but not actually guaranteed!

so now i'm using one that's even more pedantic.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-10 13:42:43 +00:00
Leah Rowe
79106c5b3d util/nvmutil: define EXIT_FAILURE/SUCCESS
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-10 13:34:40 +00:00
Leah Rowe
adfe865afc util/nvmutil: more sensible errno init
just use errno itself as input to err

if unset, it's set to ECANCELED anyway

i really should rewrite the error handling
to not use errno at some point. it's a bit
unreliable, on some unix systems.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-10 13:32:29 +00:00
Leah Rowe
4202ded96c util/nvmutil: proper errno status on prw()
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-10 13:21:34 +00:00
Leah Rowe
ee751c27ed util/nvmutil: reset errno if EINTR on lseek
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-10 12:32:42 +00:00
Leah Rowe
bbe6de44e8 util/nvmutil: stricter errno on prw()
we want the first error to be the one shown,
when returning negative

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-10 11:25:27 +00:00
Leah Rowe
5603fa51d2 util/nvmutil: fix printf c89/c90 specifiers
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-10 11:15:43 +00:00
Leah Rowe
7431046ea6 util/nvmutil: reset part_valid
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-10 11:08:42 +00:00
Leah Rowe
632c85ce1c util/nvmutil: restore errno if lseek resets it
if it resets it on success, that is!

theoretically possible. we must preserve errno.

normally i'm a bit more casual about it, but this
function is replicating libc, so i must be strict

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-10 11:06:31 +00:00
Leah Rowe
8d156bcf35 util/nvmutil: fix another printf specifier
ditto to last commit

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-10 11:02:39 +00:00
Leah Rowe
fa859d80d5 util/nvmutil: fix bad print specifier (c90)
size_t may be unsigned long long, but lu
is for unsigned long. the integer is small
enough that we don't need to worry, so let's
just cast it accordingly (inside err)

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-10 10:58:41 +00:00
Leah Rowe
6778a4ed98 util/nvmutil: only inc num_invalid on bad checksum
this fixes a regression that i introduced

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-10 10:56:56 +00:00
Leah Rowe
e3e02fa657 util/nvmutil: restore errno on failed offset restore
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-10 10:53:11 +00:00
Leah Rowe
6408570fa1 util/nvmutil: don't leave part_valid untouched
always set it. the current logic only sets it if
valid, but invalid doesn't, relying on global
initialisation. this check sets it explicitly.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-10 10:48:16 +00:00
Leah Rowe
090a702b74 util/nvmutil: remove unused st variable
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-10 10:44:27 +00:00
Leah Rowe
cbd7ad13a3 util/nvmutil: check whether a file is a file
and not, say, a socket or a directory, or
a character device, or something else.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-10 10:35:51 +00:00