CVE-2015-5232 (Shell, published 2017-06-07T20:29Z)
Description: value: Race conditions in opa-fm before 10.4.0.0.196 and opa-ff before 10.4.0.0.197.
Severity: HIGH (CVSS v3 base score: 8.1)
Weakness: CWE-362 \u2014 Concurrent Execution using Shared Resource with Improper Synchronization ('Race Condition')
The product contains a code sequence that can run concurrently with other code, and the code sequence requires temporary, exclusive access to a shared resource, but a timing window exists in which the shared resource can be modified by another code sequence that is operating concurrently.
Repository: https://github.com/01org/opa-ff
Files changed:
IbaTools/FastFabric/opascpall.sh
IbaTools/FastFabric/opatest.sh
IbaTools/disable_ports/opadisablehosts.sh
IbaTools/disable_ports/opaenableports.sh
IbaTools/disable_ports/opaextractbadlinks.sh
IbaTools/disable_ports/opaextractlids.sh
IbaTools/disable_ports/opaextractsellinks.sh
IbaTools/opacabletest/opacabletest.sh
IbaTools/opagenswitches/opagenswitches.sh
IbaTools/opalinkanalysis/opalinkanalysis.sh
IbaTools/opasw/opaswscript/opamanageswitch.sh
IbaTools/opaxlattopology/opaxlattopology.sh
IbaTools/opaxlattopology/opaxlattopology_cust.sh
fm_config/config_diff.sh
fm_config/config_generate.sh
Commit message: Fix scripts that use well-known temp files.


Vulnerable code:
trap "exit 1" SIGHUP SIGTERM SIGINT
temp=/tmp/opascpall$$
temp=/tmp/opatest$$
tempfile=/tmp/opadisablehosts$$
tempfile=/tmp/opaenableports$$
tempfile=/tmp/opaextractbadlinks$$
tempfile=/tmp/opaextractlids$$
tempfile=/tmp/opaextractsellinks$$
tempfile=/tmp/opacabletest$$
## Includes
trap "exit 1" SIGHUP SIGTERM SIGINT

	clean_files
tempfile=/tmp/opalinkanalysis$$
	tmpdir=/tmp/12200FW$$
	mkdir $tmpdir
  if [ $fl_clean == 1 ]
    then
    rm -f $FILE_TEMP
    rm -f $FILE_TEMP2
    rm -f $FILE_LINKSUM
    rm -f $FILE_LINKSUM_NOCORE
    rm -f $FILE_LINKSUM_NOCABLE
    rm -f $FILE_NODEFIS
    rm -f $FILE_NODESWITCHES
    rm -f $FILE_NODELEAVES
    rm -f $FILE_NODECHASSIS
  fi
rm -f $FILE_DEBUG
rm -f $FILE_DEBUG2

rm -f $FILE_DEBUG
rm -f $FILE_DEBUG2

if [ $fl_clean == 1 ]
	then
	rm -f $FILE_TEMP
	rm -f $FILE_TEMP2
fi
TEMP1=/tmp/smdiffa$$
TEMP2=/tmp/smdiffb$$
TEMP=/tmp/smgen$$

Fixed code:
temp="$(mktemp --tmpdir "opascpall.XXXXXX")"
trap "rm -f $temp; exit 1" SIGHUP SIGTERM SIGINT
trap "rm -f $temp" EXIT
temp=`mktemp`
temp=`mktemp`
tempfile=`mktemp`
trap "rm -f $tempfile" EXIT
tempfile=`mktemp`
trap "rm -f $tempfile" EXIT
tempfile=`mktemp`
trap "rm -f $tempfile" EXIT
tempfile=`mktemp`
trap "rm -f $tempfile" EXIT
tempfile=`mktemp`
trap "rm -f $tempfile" EXIT
tempfile=`mktemp`
trap "rm -f $tempfile" EXIT
trap 'clean_files; exit 1' SIGINT SIGHUP SIGTERM 
trap clean_files EXIT

tempfile=`mktemp`
trap "rm -f $tempfile" EXIT
	tmpdir=`mktemp -d`
function clean_tempfiles() {
  if [ $fl_clean == 1 ]
    then
    rm -f $FILE_TEMP
    rm -f $FILE_TEMP2
    rm -f $FILE_LINKSUM
    rm -f $FILE_LINKSUM_NOCORE
    rm -f $FILE_LINKSUM_NOCABLE
    rm -f $FILE_NODEFIS
    rm -f $FILE_NODESWITCHES
    rm -f $FILE_NODELEAVES
    rm -f $FILE_NODECHASSIS
  fi
}

trap 'clean_tempfiles; exit 1' SIGINT SIGHUP SIGTERM
trap 'clean_tempfiles' EXIT
  clean_tempfiles
function clean_tempfiles() {
	if [ $fl_clean == 1 ]
	then
		rm -f $FILE_TEMP $FILE_TEMP2
	fi
}

trap 'clean_tempfiles; exit 1' SIGINT SIGHUP SIGTERM
trap 'clean_tempfiles' EXIT

clean_tempfiles
TEMP1=`mktemp`
TEMP2=`mktemp`
trap "rm -f $TEMP1 $TEMP2" EXIT
TEMP=`mktemp`
trap "rm -f $TEMP" EXIT