Skip to contentSkip to conversation

scripts/run-scan-build: update

PATCH In review Christian Göttsche 2 participants 8 messages Jul 14, 2021 – Jul 22, 2021 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/6 scripts/run-scan-build: update

- use multiple jobs
- define _FORTIFY_SOURCE=2 to enable checks on standard string handling functions due to macro/intrinsic overloads or function attributes
- allow to override clang and scan-build binaries, i.e. for using versioned ones
- set PYTHON_SETUP_ARGS accordingly on Debian
- enable common warning -Wextra
- print build result

---
 scripts/run-scan-build | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)
scripts/run-scan-build +18 -4
index ae5aa48b..ef07fefc 100755
@@ -1,6 +1,10 @@
 #!/bin/sh
 # Run clang's static analyzer (scan-build) and record its output in output-scan-build/
 
+# Allow overriding binariy names, like clang-12
+export CC=${CC:-clang}
+SCAN_BUILD=${SCAN_BUILD:-scan-build}
+
 # Ensure the current directory is where this script is
 cd "$(dirname -- "$0")" || exit $?
 
@@ -20,14 +24,24 @@ export PATH="$DESTDIR/usr/sbin:$DESTDIR/usr/bin:$DESTDIR/sbin:$DESTDIR/bin:$PATH
 export PYTHONPATH="$DESTDIR$(${PYTHON:-python3} -c "from distutils.sysconfig import *;print(get_python_lib(prefix='/usr'))")"
 export RUBYLIB="$DESTDIR/$(${RUBY:-ruby} -e 'puts RbConfig::CONFIG["vendorlibdir"]'):$DESTDIR/$(${RUBY:-ruby} -e 'puts RbConfig::CONFIG["vendorarchdir"]')"
 
+if [ -f /etc/debian_version ]; then
+    export PYTHON_SETUP_ARGS='--install-layout=deb'
+fi
+
 # Build and analyze
-make -C .. CC=clang clean distclean -j"$(nproc)"
-scan-build -analyze-headers -o "$OUTPUTDIR" make -C .. \
-    CC=clang \
+make -C .. clean distclean -j"$(nproc)"
+$SCAN_BUILD -analyze-headers -o "$OUTPUTDIR" make -C .. \
     DESTDIR="$DESTDIR" \
-    CFLAGS="-O2 -Wall -D__CHECKER__ -I$DESTDIR/usr/include" \
+    CFLAGS="-O2 -Wall -Wextra -D_FORTIFY_SOURCE=2 -D__CHECKER__ -I$DESTDIR/usr/include" \
+    -j"$(nproc)" \
     install install-pywrap install-rubywrap all test
 
+if [ $? -eq 0 ]; then
+    echo "++ Build succeeded"
+else
+    echo "++ Build failed"
+fi
+
 # Reduce the verbosity in order to keep the message from scan-build saying
 # "scan-build: Run 'scan-view /.../output-scan-build/2018-...' to examine bug reports.
 set +x
Signature · 1 line
2.32.0
#1 lore raw

PATCH 2/6 secilc: fix memory leaks in secilc

When specifying -o or -f more than once, the previous allocations leak.

Found by scan-build.

---
 secilc/secilc.c | 2 ++
 1 file changed, 2 insertions(+)
secilc/secilc.c +2 -0
index 1c4f1ca0..80d3583d 100644
@@ -199,9 +199,11 @@ int main(int argc, char *argv[])
 				qualified_names = 1;
 				break;
 			case 'o':
+				free(output);
 				output = strdup(optarg);
 				break;
 			case 'f':
+				free(filecontexts);
 				filecontexts = strdup(optarg);
 				break;
 			case 'G':
Signature · 1 line
2.32.0
#2 lore raw

PATCH 3/6 secilc: fix memory leaks in secilc2conf

In reply to Christian Göttsche

When specifying -o more than once, the previous allocation leaks.

Found by scan-build.

---
 secilc/secil2conf.c | 1 +
 1 file changed, 1 insertion(+)
secilc/secil2conf.c +1 -0
index d4103777..c49522e5 100644
@@ -111,6 +111,7 @@ int main(int argc, char *argv[])
 				qualified_names = 1;
 				break;
 			case 'o':
+				free(output);
 				output = strdup(optarg);
 				break;
 			case 'h':
Signature · 1 line
2.32.0
#3 lore raw

PATCH 4/6 policycoreutils: free memory on lstat failure in sestatus

In reply to Christian Göttsche

In case lstat(3) fails the memory is not free'd at the end of the for loop, due to the control flow change by continue.

Found by scan-build.

---
 policycoreutils/sestatus/sestatus.c | 1 +
 1 file changed, 1 insertion(+)
policycoreutils/sestatus/sestatus.c +1 -0
index b37f0353..ceee0d52 100644
@@ -461,6 +461,7 @@ int main(int argc, char **argv)
 				    ("%s (could not check link status (%s)!)\n",
 				     context, strerror(errno));
 				freecon(context);
+				free(fc[i]);
 				continue;
 			}
 			if (S_ISLNK(m.st_mode)) {
Signature · 1 line
2.32.0
#4 lore raw

PATCH 5/6 policycoreutils: free memory of allocated context in run_init

In reply to Christian Göttsche

Found by scan-build.

---
 policycoreutils/run_init/run_init.c | 5 +++++
 1 file changed, 5 insertions(+)
policycoreutils/run_init/run_init.c +5 -0
index 1c5eb68e..545490a2 100644
@@ -406,14 +406,19 @@ int main(int argc, char *argv[])
 
 	if (chdir("/")) {
 		perror("chdir");
+		free(new_context);
 		exit(-1);
 	}
 
 	if (setexeccon(new_context) < 0) {
 		fprintf(stderr, _("Could not set exec context to %s.\n"),
 			new_context);
+		free(new_context);
 		exit(-1);
 	}
+
+	free(new_context);
+
 	if (access("/usr/sbin/open_init_pty", X_OK) != 0) {
 		if (execvp(argv[1], argv + 1)) {
 			perror("execvp");
Signature · 1 line
2.32.0
#5 lore raw

PATCH 6/6 policycoreutils: free memory of allocated context in newrole

In reply to Christian Göttsche

Found by scan-build.

---
 policycoreutils/newrole/newrole.c | 1 +
 1 file changed, 1 insertion(+)
policycoreutils/newrole/newrole.c +1 -0
index 0264531a..7c1f062f 100644
@@ -1239,6 +1239,7 @@ int main(int argc, char *argv[])
 		free(pw.pw_dir);
 		free(pw.pw_shell);
 		free(shell_argv0);
+		free(new_context);
 		return exit_code;
 	}
 
Signature · 1 line
2.32.0
Acked-by on v1 1/6
#6 lore raw
In reply to Christian Göttsche
Quoted 11 lines · Christian Göttsche

- use multiple jobs
- define _FORTIFY_SOURCE=2 to enable checks on standard string handling functions due to macro/intrinsic overloads or function attributes
- allow to override clang and scan-build binaries, i.e. for using versioned ones
- set PYTHON_SETUP_ARGS accordingly on Debian
- enable common warning -Wextra
- print build result

For all six patches:

Quoted 51 lines
---
 scripts/run-scan-build | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)
scripts/run-scan-build +18 -5
index ae5aa48b..ef07fefc 100755
@@ -1,6 +1,10 @@
 #!/bin/sh
 # Run clang's static analyzer (scan-build) and record its output in output-scan-build/
 
+# Allow overriding binariy names, like clang-12
+export CC=${CC:-clang}
+SCAN_BUILD=${SCAN_BUILD:-scan-build}
+
 # Ensure the current directory is where this script is
 cd "$(dirname -- "$0")" || exit $?
 
@@ -20,14 +24,24 @@ export PATH="$DESTDIR/usr/sbin:$DESTDIR/usr/bin:$DESTDIR/sbin:$DESTDIR/bin:$PATH
 export PYTHONPATH="$DESTDIR$(${PYTHON:-python3} -c "from distutils.sysconfig import *;print(get_python_lib(prefix='/usr'))")"
 export RUBYLIB="$DESTDIR/$(${RUBY:-ruby} -e 'puts RbConfig::CONFIG["vendorlibdir"]'):$DESTDIR/$(${RUBY:-ruby} -e 'puts RbConfig::CONFIG["vendorarchdir"]')"
 
+if [ -f /etc/debian_version ]; then
+    export PYTHON_SETUP_ARGS='--install-layout=deb'
+fi
+
 # Build and analyze
-make -C .. CC=clang clean distclean -j"$(nproc)"
-scan-build -analyze-headers -o "$OUTPUTDIR" make -C .. \
-    CC=clang \
+make -C .. clean distclean -j"$(nproc)"
+$SCAN_BUILD -analyze-headers -o "$OUTPUTDIR" make -C .. \
     DESTDIR="$DESTDIR" \
-    CFLAGS="-O2 -Wall -D__CHECKER__ -I$DESTDIR/usr/include" \
+    CFLAGS="-O2 -Wall -Wextra -D_FORTIFY_SOURCE=2 -D__CHECKER__ -I$DESTDIR/usr/include" \
+    -j"$(nproc)" \
     install install-pywrap install-rubywrap all test
 
+if [ $? -eq 0 ]; then
+    echo "++ Build succeeded"
+else
+    echo "++ Build failed"
+fi
+
 # Reduce the verbosity in order to keep the message from scan-build saying
 # "scan-build: Run 'scan-view /.../output-scan-build/2018-...' to examine bug reports.
 set +x
--

2.32.0

#7 lore raw
Quoted 13 lines · James Carter
Quoted 10 lines · Christian Göttsche

- use multiple jobs
- define _FORTIFY_SOURCE=2 to enable checks on standard string handling functions due to macro/intrinsic overloads or function attributes
- allow to override clang and scan-build binaries, i.e. for using versioned ones
- set PYTHON_SETUP_ARGS accordingly on Debian
- enable common warning -Wextra
- print build result

Quoted 5 lines
Quoted 1 line

For all six patches:

This series has been merged.

Thanks,
Jim

Quoted 51 lines
Quoted 51 lines
---
 scripts/run-scan-build | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)
scripts/run-scan-build +18 -5
index ae5aa48b..ef07fefc 100755
@@ -1,6 +1,10 @@
 #!/bin/sh
 # Run clang's static analyzer (scan-build) and record its output in output-scan-build/
 
+# Allow overriding binariy names, like clang-12
+export CC=${CC:-clang}
+SCAN_BUILD=${SCAN_BUILD:-scan-build}
+
 # Ensure the current directory is where this script is
 cd "$(dirname -- "$0")" || exit $?
 
@@ -20,14 +24,24 @@ export PATH="$DESTDIR/usr/sbin:$DESTDIR/usr/bin:$DESTDIR/sbin:$DESTDIR/bin:$PATH
 export PYTHONPATH="$DESTDIR$(${PYTHON:-python3} -c "from distutils.sysconfig import *;print(get_python_lib(prefix='/usr'))")"
 export RUBYLIB="$DESTDIR/$(${RUBY:-ruby} -e 'puts RbConfig::CONFIG["vendorlibdir"]'):$DESTDIR/$(${RUBY:-ruby} -e 'puts RbConfig::CONFIG["vendorarchdir"]')"
 
+if [ -f /etc/debian_version ]; then
+    export PYTHON_SETUP_ARGS='--install-layout=deb'
+fi
+
 # Build and analyze
-make -C .. CC=clang clean distclean -j"$(nproc)"
-scan-build -analyze-headers -o "$OUTPUTDIR" make -C .. \
-    CC=clang \
+make -C .. clean distclean -j"$(nproc)"
+$SCAN_BUILD -analyze-headers -o "$OUTPUTDIR" make -C .. \
     DESTDIR="$DESTDIR" \
-    CFLAGS="-O2 -Wall -D__CHECKER__ -I$DESTDIR/usr/include" \
+    CFLAGS="-O2 -Wall -Wextra -D_FORTIFY_SOURCE=2 -D__CHECKER__ -I$DESTDIR/usr/include" \
+    -j"$(nproc)" \
     install install-pywrap install-rubywrap all test
 
+if [ $? -eq 0 ]; then
+    echo "++ Build succeeded"
+else
+    echo "++ Build failed"
+fi
+
 # Reduce the verbosity in order to keep the message from scan-build saying
 # "scan-build: Run 'scan-view /.../output-scan-build/2018-...' to examine bug reports.
 set +x
--

2.32.0