Possible Race Condition in session_up.sh

Looking for assistance with a cryptostorm connection issue? Post here & we'll help out. Also: if you're not sure where to post, do so here & we'll move things around as needed. Also: for quickest support, email our oddly calm & easygoing support reps at support@cryptostorm.is :)
Posts: 2
Joined: Sun Mar 14, 2021 10:53 pm

Possible Race Condition in session_up.sh

Post by tentacul » Sun Mar 14, 2021 11:02 pm


Code: Select all

 # randomly grab an unused IP from the 10.whatever subnet specific to that instance.
        while [ "$found_one" -eq "0" ]; do
         # randomly generate the last octet, in the range of 3-254 for each. only last octet cause doin c-class on this box
         RANDIP=$POOL.`echo $[ 3 + $[ RANDOM % 251 ]]`
         # not taken yet?
         if [ ! -r $instance_pool_dir/$RANDIP ]; then
          # take it
          touch $instance_pool_dir/$RANDIP
          # write out the ifconfig line to $1 which is picked up by openvpn
          echo "ifconfig-push $RANDIP" > $1
You should possibly use flock between "if [ ! -r $instance_pool_dir/$RANDIP ]; then" and "touch $instance_pool_dir/$RANDIP"
or multiple clients could get assigned the same IP