Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

fault-injection: enhance failcmd to exit on non-hex address input

The failcmd.sh script in the fault-injection toolkit does not currently
validate whether the provided address is in hexadecimal format. This can
lead to silent failures if the address is sourced from places like
`/proc/kallsyms`, which omits the '0x' prefix, potentially causing users
to operate under incorrect assumptions.

Introduce a new function, `exit_if_not_hex`, which checks the format of
the provided address and exits with an error message if the address is not
a valid hexadecimal number.

This enhancement prevents users from running the command with improperly
formatted addresses, thus improving the robustness and usability of the
failcmd tool.

Link: https://lkml.kernel.org/r/20240729084512.3349928-1-leitao@debian.org
Signed-off-by: Breno Leitao <leitao@debian.org>
Reviewed-by: Akinobu Mita <akinobu.mita@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Breno Leitao and committed by
Andrew Morton
11ee88a0 588661fd

+12
+12
tools/testing/fault-injection/failcmd.sh
··· 64 64 EOF 65 65 } 66 66 67 + exit_if_not_hex() { 68 + local value="$1" 69 + if ! [[ $value =~ ^0x[0-9a-fA-F]+$ ]]; then 70 + echo "Error: The provided value '$value' is not a valid hexadecimal number." >&2 71 + exit 1 72 + fi 73 + } 74 + 67 75 if [ $UID != 0 ]; then 68 76 echo must be run as root >&2 69 77 exit 1 ··· 168 160 shift 2 169 161 ;; 170 162 --require-start) 163 + exit_if_not_hex "$2" 171 164 echo $2 > $FAULTATTR/require-start 172 165 shift 2 173 166 ;; 174 167 --require-end) 168 + exit_if_not_hex "$2" 175 169 echo $2 > $FAULTATTR/require-end 176 170 shift 2 177 171 ;; 178 172 --reject-start) 173 + exit_if_not_hex "$2" 179 174 echo $2 > $FAULTATTR/reject-start 180 175 shift 2 181 176 ;; 182 177 --reject-end) 178 + exit_if_not_hex "$2" 183 179 echo $2 > $FAULTATTR/reject-end 184 180 shift 2 185 181 ;;