diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index e975f45..56ba3bc 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -167,6 +167,7 @@ Common traps to avoid: | `xargs` | `-r` (no-op if empty, GNU only) | Guard with a prior `[ -n "..." ]` check, or accept the harmless empty invocation | | `readlink` | `-f` (canonicalize, GNU only) | Use only in Linux-specific code paths, or reimplement with `cd`/`pwd` | | `dd` | `iflag=`, `oflag=` (GNU only) | Use only in Linux-specific code paths (e.g. `/dev/cpu/*/msr`) | +| `base64` | `-w N` (set line-wrap width, GNU only; BusyBox doesn't support it) | Pipe through `tr -d '\n'` to remove newlines instead of `-w0` | When a tool genuinely has no portable equivalent, restrict the non-portable call to a platform-specific code path (i.e. inside a BSD-only or Linux-only branch) and document why. diff --git a/src/libs/300_kernel_extract.sh b/src/libs/300_kernel_extract.sh index bfeef9a..3b29f3f 100644 --- a/src/libs/300_kernel_extract.sh +++ b/src/libs/300_kernel_extract.sh @@ -88,7 +88,9 @@ try_decompress() { fi pos=${pos%%:*} # shellcheck disable=SC2086 - tail -c+$pos "$6" 2>/dev/null | $3 $4 >"$g_kerneltmp" 2>/dev/null + # wrap in subshell so that if $3 segfaults (e.g. old BusyBox unlzma on random data), + # the "Segmentation fault" message printed by the shell goes to /dev/null + (tail -c+$pos "$6" 2>/dev/null | $3 $4 >"$g_kerneltmp" 2>/dev/null) 2>/dev/null ret=$? if [ ! -s "$g_kerneltmp" ]; then # don't rely on $ret, sometimes it's != 0 but worked diff --git a/src/main.sh b/src/main.sh index 3522c61..2b405c5 100644 --- a/src/main.sh +++ b/src/main.sh @@ -35,7 +35,7 @@ if [ -n "$g_mockme" ] && [ "$opt_mock" = 1 ]; then # not a useless use of cat: gzipping cpuinfo directly doesn't work well # shellcheck disable=SC2002 if command -v "base64" >/dev/null 2>&1; then - g_mock_cpuinfo="$(cat /proc/cpuinfo | gzip -c | base64 -w0)" + g_mock_cpuinfo="$(cat /proc/cpuinfo | gzip -c | base64 | tr -d '\n')" elif command -v "uuencode" >/dev/null 2>&1; then g_mock_cpuinfo="$(cat /proc/cpuinfo | gzip -c | uuencode -m - | grep -Fv 'begin-base64' | grep -Fxv -- '====' | tr -d "\n")" fi