~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/scripts/test_fortify.sh

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 #!/bin/sh
  2 # SPDX-License-Identifier: GPL-2.0-only
  3 set -e
  4 
  5 # Argument 1: Source file to build.
  6 IN="$1"
  7 shift
  8 # Extract just the filename for error messages below.
  9 FILE="${IN##*/}"
 10 # Extract the function name for error messages below.
 11 FUNC="${FILE#*-}"
 12 FUNC="${FUNC%%-*}"
 13 FUNC="${FUNC%%.*}"
 14 # Extract the symbol to test for in build/symbol test below.
 15 WANT="__${FILE%%-*}"
 16 
 17 # Argument 2: Where to write the build log.
 18 OUT="$1"
 19 shift
 20 TMP="${OUT}.tmp"
 21 
 22 # Argument 3: Path to "nm" tool.
 23 NM="$1"
 24 shift
 25 
 26 # Remaining arguments are: $(CC) $(c_flags)
 27 
 28 # Clean up temporary file at exit.
 29 __cleanup() {
 30         rm -f "$TMP"
 31 }
 32 trap __cleanup EXIT
 33 
 34 # Function names in warnings are wrapped in backticks under UTF-8 locales.
 35 # Run the commands with LANG=C so that grep output will not change.
 36 export LANG=C
 37 
 38 status=
 39 # Attempt to build a source that is expected to fail with a specific warning.
 40 if "$@" -Werror -c "$IN" -o "$OUT".o 2> "$TMP" ; then
 41         # If the build succeeds, either the test has failed or the
 42         # warning may only happen at link time (Clang). In that case,
 43         # make sure the expected symbol is unresolved in the symbol list.
 44         # If so, FORTIFY is working for this case.
 45         if ! $NM -A "$OUT".o | grep -m1 "\bU ${WANT}$" >>"$TMP" ; then
 46                 status="warning: unsafe ${FUNC}() usage lacked '$WANT' symbol in $IN"
 47         fi
 48 else
 49         # If the build failed, check for the warning in the stderr.
 50         # GCC:
 51         # ./include/linux/fortify-string.h:316:25: error: call to '__write_overflow_field' declared with attribute warning: detected write beyond size of field (1st parameter); maybe use struct_group()? [-Werror=attribute-warning]
 52         # Clang 14:
 53         # ./include/linux/fortify-string.h:316:4: error: call to __write_overflow_field declared with 'warning' attribute: detected write beyond size of field (1st parameter); maybe use struct_group()? [-Werror,-Wattribute-warning]
 54         if ! grep -Eq -m1 "error: call to .?\b${WANT}\b.?" "$TMP" ; then
 55                 status="warning: unsafe ${FUNC}() usage lacked '$WANT' warning in $IN"
 56         fi
 57 fi
 58 
 59 if [ -n "$status" ]; then
 60         # Report on failure results, including compilation warnings.
 61         echo "$status" | tee "$OUT" >&2
 62 else
 63         # Report on good results, and save any compilation output to log.
 64         echo "ok: unsafe ${FUNC}() usage correctly detected with '$WANT' in $IN" >"$OUT"
 65 fi
 66 cat "$TMP" >>"$OUT"

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php