diff options
author | Pavlina Moravcova Varekova <pmoravco@redhat.com> | 2019-08-09 16:30:43 +0200 |
---|---|---|
committer | Panu Matilainen <pmatilai@redhat.com> | 2019-08-28 12:16:52 +0300 |
commit | de88c7586a809ecad4ec393910c998f35af284b8 (patch) | |
tree | 9f752473724eb373d50892980e8e34e7d3ca3ebc | |
parent | 57876b0a7af40ad67caa489a2c55f9c98fd0df31 (diff) | |
download | rpm-de88c7586a809ecad4ec393910c998f35af284b8.tar.gz |
Eliminate use of ambiguous logical operators in script conditionals
Prefer '[] && []' to '[ -a ]' and '[] || []' to '[ -o ]' in tests.
-a and -o to mean AND and OR in a [ .. ] test expression is not well
defined, and can cause incorrect results when arguments start with
dashes or contain !. Moreover binary -a and -o are inherently
ambiguous. test(1) man page recommends to use
'test EXPR1 && test EXPR2' or 'test EXPR1 || test EXPR2' instead.
It corrects warnings [SC2166] spotted by covscan.
(cherry picked from commit e9c13c6565cf4782d1f73255ee9144dd9bd2aca7)
-rwxr-xr-x | scripts/brp-compress | 2 | ||||
-rw-r--r-- | scripts/brp-java-gcjcompile | 4 | ||||
-rw-r--r-- | scripts/brp-python-bytecompile | 12 | ||||
-rwxr-xr-x | scripts/brp-python-hardlink | 2 | ||||
-rwxr-xr-x | scripts/brp-strip | 2 | ||||
-rwxr-xr-x | scripts/brp-strip-comment-note | 2 | ||||
-rw-r--r-- | scripts/brp-strip-shared | 2 | ||||
-rwxr-xr-x | scripts/brp-strip-static-archive | 2 | ||||
-rwxr-xr-x | scripts/check-buildroot | 2 | ||||
-rwxr-xr-x | scripts/check-rpaths | 2 | ||||
-rwxr-xr-x | scripts/find-debuginfo.sh | 6 | ||||
-rwxr-xr-x | scripts/find-lang.sh | 6 | ||||
-rw-r--r-- | scripts/gendiff | 2 | ||||
-rwxr-xr-x | scripts/rpm2cpio.sh | 2 | ||||
-rwxr-xr-x | scripts/rpmdb_loadcvt | 2 | ||||
-rwxr-xr-x | scripts/tgpg | 2 |
16 files changed, 26 insertions, 26 deletions
diff --git a/scripts/brp-compress b/scripts/brp-compress index e4307eff7..1a5692ff8 100755 --- a/scripts/brp-compress +++ b/scripts/brp-compress @@ -1,7 +1,7 @@ #!/bin/sh # If using normal root, avoid changing anything. -if [ -z "$RPM_BUILD_ROOT" -o "$RPM_BUILD_ROOT" = "/" ]; then +if [ -z "$RPM_BUILD_ROOT" ] || [ "$RPM_BUILD_ROOT" = "/" ]; then exit 0 fi diff --git a/scripts/brp-java-gcjcompile b/scripts/brp-java-gcjcompile index ec9b93a93..79612d19e 100644 --- a/scripts/brp-java-gcjcompile +++ b/scripts/brp-java-gcjcompile @@ -1,14 +1,14 @@ #!/bin/sh # If using normal root, avoid changing anything. -[ -z "$RPM_BUILD_ROOT" -o "$RPM_BUILD_ROOT" = "/" ] && exit 0 +[ -z "$RPM_BUILD_ROOT" ] || [ "$RPM_BUILD_ROOT" = "/" ] && exit 0 # If we are a noarch package, avoid changing anything. [ "$RPM_ARCH" = "noarch" ] && exit 0 # If we don't have the required executables, avoid changing anything. gcj=${1:-/usr/bin/gcj} -[ ! -x "$gcj" -o ! -x "$gcj-dbtool" ] && exit 0 +[ ! -x "$gcj" ] || [ ! -x "$gcj-dbtool" ] && exit 0 # Now get to work... libdir="/usr/lib" # XXX need to sed this in or something diff --git a/scripts/brp-python-bytecompile b/scripts/brp-python-bytecompile index c06bdfafe..d9c4832dc 100644 --- a/scripts/brp-python-bytecompile +++ b/scripts/brp-python-bytecompile @@ -3,7 +3,7 @@ errors_terminate=$2 extra=$3 # If using normal root, avoid changing anything. -if [ -z "$RPM_BUILD_ROOT" -o "$RPM_BUILD_ROOT" = "/" ]; then +if [ -z "$RPM_BUILD_ROOT" ] || [ "$RPM_BUILD_ROOT" = "/" ]; then exit 0 fi @@ -11,7 +11,7 @@ fi # number and hope it's enough, but somewhere, somebody's sure to run into it. depth=`(find "$RPM_BUILD_ROOT" -type f -name "*.py" -print0 ; echo /) | \ xargs -0 -n 1 dirname | sed 's,[^/],,g' | sort -u | tail -n 1 | wc -c` -if [ -z "$depth" -o "$depth" -le "1" ]; then +if [ -z "$depth" ] || [ "$depth" -le "1" ]; then exit 0 fi @@ -66,14 +66,14 @@ do # Generate normal (.pyc) byte-compiled files. python_bytecompile "" "$python_binary" "" "$python_libdir" "$depth" "$real_libdir" - if [ $? -ne 0 -a 0$errors_terminate -ne 0 ]; then + if [ $? -ne 0 ] && [ 0$errors_terminate -ne 0 ]; then # One or more of the files had a syntax error exit 1 fi # Generate optimized (.pyo) byte-compiled files. python_bytecompile "-O" "$python_binary" "" "$python_libdir" "$depth" "$real_libdir" - if [ $? -ne 0 -a 0$errors_terminate -ne 0 ]; then + if [ $? -ne 0 ] && [ 0$errors_terminate -ne 0 ]; then # One or more of the files had a syntax error exit 1 fi @@ -98,14 +98,14 @@ find "$RPM_BUILD_ROOT" -type f -name "*.py" | grep -Ev "/bin/|/sbin/|/usr/lib(64 # Generate normal (.pyc) byte-compiled files. python_bytecompile "" $default_python "/bin/|/sbin/|/usr/lib(64)?/python[0-9]\.[0-9]|/usr/share/doc" "$RPM_BUILD_ROOT" "$depth" "/" -if [ $? -ne 0 -a 0$errors_terminate -ne 0 ]; then +if [ $? -ne 0 ] && [ 0$errors_terminate -ne 0 ]; then # One or more of the files had a syntax error exit 1 fi # Generate optimized (.pyo) byte-compiled files. python_bytecompile "-O" $default_python "/bin/|/sbin/|/usr/lib(64)?/python[0-9]\.[0-9]|/usr/share/doc" "$RPM_BUILD_ROOT" "$depth" "/" -if [ $? -ne 0 -a 0$errors_terminate -ne 0 ]; then +if [ $? -ne 0 ] && [ 0$errors_terminate -ne 0 ]; then # One or more of the files had a syntax error exit 1 fi diff --git a/scripts/brp-python-hardlink b/scripts/brp-python-hardlink index 949c9c32d..5fd1b43bb 100755 --- a/scripts/brp-python-hardlink +++ b/scripts/brp-python-hardlink @@ -1,7 +1,7 @@ #!/bin/sh # If using normal root, avoid changing anything. -if [ -z "$RPM_BUILD_ROOT" -o "$RPM_BUILD_ROOT" = "/" ]; then +if [ -z "$RPM_BUILD_ROOT" ] || [ "$RPM_BUILD_ROOT" = "/" ]; then exit 0 fi diff --git a/scripts/brp-strip b/scripts/brp-strip index 5e645669c..a9d04d315 100755 --- a/scripts/brp-strip +++ b/scripts/brp-strip @@ -1,6 +1,6 @@ #!/bin/sh # If using normal root, avoid changing anything. -if [ -z "$RPM_BUILD_ROOT" -o "$RPM_BUILD_ROOT" = "/" ]; then +if [ -z "$RPM_BUILD_ROOT" ] || [ "$RPM_BUILD_ROOT" = "/" ]; then exit 0 fi diff --git a/scripts/brp-strip-comment-note b/scripts/brp-strip-comment-note index 833ac78e5..a90be7109 100755 --- a/scripts/brp-strip-comment-note +++ b/scripts/brp-strip-comment-note @@ -1,6 +1,6 @@ #!/bin/sh # If using normal root, avoid changing anything. -if [ -z "$RPM_BUILD_ROOT" -o "$RPM_BUILD_ROOT" = "/" ]; then +if [ -z "$RPM_BUILD_ROOT" ] || [ "$RPM_BUILD_ROOT" = "/" ]; then exit 0 fi diff --git a/scripts/brp-strip-shared b/scripts/brp-strip-shared index 51d10d5b3..94113a4b2 100644 --- a/scripts/brp-strip-shared +++ b/scripts/brp-strip-shared @@ -3,7 +3,7 @@ # Thu Apr 20 - Guilherme Manika <gwm@conectiva.com.br> # Created file -if [ -z "$RPM_BUILD_ROOT" -o "$RPM_BUILD_ROOT" = "/" ]; then +if [ -z "$RPM_BUILD_ROOT" ] || [ "$RPM_BUILD_ROOT" = "/" ]; then exit 0 fi diff --git a/scripts/brp-strip-static-archive b/scripts/brp-strip-static-archive index f7fb26b87..37ab511a9 100755 --- a/scripts/brp-strip-static-archive +++ b/scripts/brp-strip-static-archive @@ -1,6 +1,6 @@ #!/bin/sh -if [ -z "$RPM_BUILD_ROOT" -o "$RPM_BUILD_ROOT" = "/" ]; then +if [ -z "$RPM_BUILD_ROOT" ] || [ "$RPM_BUILD_ROOT" = "/" ]; then exit 0 fi diff --git a/scripts/check-buildroot b/scripts/check-buildroot index f91dc767b..d69867b45 100755 --- a/scripts/check-buildroot +++ b/scripts/check-buildroot @@ -18,7 +18,7 @@ test -z "$QA_SKIP_BUILD_ROOT" || exit 0 -if [ -z "$RPM_BUILD_ROOT" -o "$RPM_BUILD_ROOT" = "/" ]; then +if [ -z "$RPM_BUILD_ROOT" ] || [ "$RPM_BUILD_ROOT" = "/" ]; then exit 0 fi diff --git a/scripts/check-rpaths b/scripts/check-rpaths index b94630bb1..c3d860050 100755 --- a/scripts/check-rpaths +++ b/scripts/check-rpaths @@ -21,7 +21,7 @@ test -z "$QA_SKIP_RPATHS" || { exit 0 } -if [ -z "$RPM_BUILD_ROOT" -o "$RPM_BUILD_ROOT" = "/" ]; then +if [ -z "$RPM_BUILD_ROOT" ] || [ "$RPM_BUILD_ROOT" = "/" ]; then exit 0 fi diff --git a/scripts/find-debuginfo.sh b/scripts/find-debuginfo.sh index 295226023..7624b3f36 100755 --- a/scripts/find-debuginfo.sh +++ b/scripts/find-debuginfo.sh @@ -157,7 +157,7 @@ while [ $# -gt 0 ]; do include_gdb_index=true ;; -o) - if [ -z "${lists[$nout]}" -a -z "${ptns[$nout]}" ]; then + if [ -z "${lists[$nout]}" ] && [ -z "${ptns[$nout]}" ]; then out=$2 else outs[$nout]=$2 @@ -428,7 +428,7 @@ do_file() # strip -g implies we have full symtab, don't add mini symtab in that case. # It only makes sense to add a minisymtab for executables and shared # libraries. Other executable ELF files (like kernel modules) don't need it. - if [ "$include_minidebug" = "true" -a "$strip_g" = "false" ]; then + if [ "$include_minidebug" = "true" ] && [ "$strip_g" = "false" ]; then skip_mini=true if [ "$strip_glibs" = "false" ]; then case "$(file -bi "$f")" in @@ -587,7 +587,7 @@ if [ -s "$SOURCEFILE" ]; then xargs --no-run-if-empty -0 chmod 0755 fi -if [ -d "${RPM_BUILD_ROOT}/usr/lib" -o -d "${RPM_BUILD_ROOT}/usr/src" ]; then +if [ -d "${RPM_BUILD_ROOT}/usr/lib" ] || [ -d "${RPM_BUILD_ROOT}/usr/src" ]; then ((nout > 0)) || test ! -d "${RPM_BUILD_ROOT}/usr/lib" || (cd "${RPM_BUILD_ROOT}/usr/lib"; find debug -type d) | diff --git a/scripts/find-lang.sh b/scripts/find-lang.sh index fdca18ec4..1542a43fb 100755 --- a/scripts/find-lang.sh +++ b/scripts/find-lang.sh @@ -184,7 +184,7 @@ s:%lang(C) :: /^$/d' >> $MO_NAME KDE3_HTML=`kde-config --expandvars --install html 2>/dev/null` -if [ x"$KDE3_HTML" != x -a -d "$TOP_DIR$KDE3_HTML" ]; then +if [ x"$KDE3_HTML" != x ] && [ -d "$TOP_DIR$KDE3_HTML" ]; then find "$TOP_DIR$KDE3_HTML" -type d|sed ' s:'"$TOP_DIR"':: '"$NO_ALL_NAME$KDE"'s:\(.*/HTML/\)\([^/_]\+\)\(.*/'"$NAME"'/\):: @@ -197,7 +197,7 @@ s:%lang(C) :: fi KDE4_HTML=`kde4-config --expandvars --install html 2>/dev/null` -if [ x"$KDE4_HTML" != x -a -d "$TOP_DIR$KDE4_HTML" ]; then +if [ x"$KDE4_HTML" != x ] && [ -d "$TOP_DIR$KDE4_HTML" ]; then find "$TOP_DIR$KDE4_HTML" -type d|sed ' s:'"$TOP_DIR"':: '"$NO_ALL_NAME$KDE"'s:\(.*/HTML/\)\([^/_]\+\)\(.*/'"$NAME"'/\):: @@ -210,7 +210,7 @@ s:%lang(C) :: fi KF5_HTML=`kf5-config --expandvars --install html 2>/dev/null` -if [ x"$KF5_HTML" != x -a -d "$TOP_DIR$KF5_HTML" ]; then +if [ x"$KF5_HTML" != x ] && [ -d "$TOP_DIR$KF5_HTML" ]; then find "$TOP_DIR$KF5_HTML" -type d|sed ' s:'"$TOP_DIR"':: '"$NO_ALL_NAME$KDE"'s:\(.*/HTML/\)\([^/_]\+\)\(.*/'"$NAME"'/\):: diff --git a/scripts/gendiff b/scripts/gendiff index a8cd1209e..ae083dcd1 100644 --- a/scripts/gendiff +++ b/scripts/gendiff @@ -1,6 +1,6 @@ #!/bin/sh -[ -z "$1" -o -z "$2" ] && { +[ -z "$1" ] || [ -z "$2" ] && { # usage echo "usage: $0 <directory> <diff-extension>" 1>&2 exit 1 diff --git a/scripts/rpm2cpio.sh b/scripts/rpm2cpio.sh index a883562ac..4531271cc 100755 --- a/scripts/rpm2cpio.sh +++ b/scripts/rpm2cpio.sh @@ -6,7 +6,7 @@ fatal() { } pkg="$1" -[ -n "$pkg" -a -e "$pkg" ] || +[ -n "$pkg" ] && [ -e "$pkg" ] || fatal "No package supplied" _dd() { diff --git a/scripts/rpmdb_loadcvt b/scripts/rpmdb_loadcvt index aa701065f..bb21b0337 100755 --- a/scripts/rpmdb_loadcvt +++ b/scripts/rpmdb_loadcvt @@ -28,7 +28,7 @@ loadfmt="${5%%:}" exit 0 } -[ "$ac" != "0" -o "`/usr/bin/id -u`" != "0" ] && { +[ "$ac" != "0" ] || [ "`/usr/bin/id -u`" != "0" ] && { echo "$cmd: Convert $rpmdb files to db-$loadfmt format." echo "$cmd: Must be run as root, takes no arguments." exit 1 diff --git a/scripts/tgpg b/scripts/tgpg index 238cffbb4..fabba8046 100755 --- a/scripts/tgpg +++ b/scripts/tgpg @@ -3,7 +3,7 @@ for pkg in $* do - if [ "$pkg" = "" -o ! -e "$pkg" ]; then + if [ "$pkg" = "" ] || [ ! -e "$pkg" ]; then echo "no package supplied" 1>&2 exit 1 fi |