From c12965f8e4205cc28d9f468891cd20330b28c53c Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Sat, 23 Aug 2025 15:35:47 +0100 Subject: lib.sh: safer pad_one_byte function instead of copying to a temp file and then concatenating with padding back to the main file, we concatenate and create the temp file, then move the temp file back to the main file. this is because cat can be quite error prone, more so than mv, so this will reduce the chance of corrupt files being left behind depending on the context (of course, the latter is often avoided due to xbmk's design, which emphasises use of temporary files first). this matches the same design used in the function unpad_one_byte, which creates the deconcatenated output in a temporary file first, moving it back. Signed-off-by: Leah Rowe --- include/lib.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/lib.sh b/include/lib.sh index 7215106c..f64a6a35 100644 --- a/include/lib.sh +++ b/include/lib.sh @@ -98,9 +98,8 @@ findpath() pad_one_byte() { paddedfile="`mktemp`" || err "mktemp pad_one_byte" - x_ cp "$1" "$paddedfile" - x_ cat "$paddedfile" config/data/coreboot/0 > "$1" || err "!pad $1"; : - x_ rm "$paddedfile" + x_ cat "$1" config/data/coreboot/0 > "$paddedfile" || err "!pad $1"; : + x_ mv "$paddedfile" "$1" } unpad_one_byte() -- cgit v1.2.1