Browse Source

Specify strstr tightly, add strglob/strglobin.

By convention, strstr should be a literal string match. Previously, it
would match as a glob pattern. Some code used that, so add new
functions strglob and strglobin to do what that code expects, and
specify them tightly too. strglob tests whether the glob pattern
matches the entire string (the name strglob is also used in the yorick
language, and that's what it does there), while strglobin tests whether
the glob pattern matches anywhere in the string.

Also tightens str_starts, str_ends, and str_replace to deal with
literal strings only. In a quick grep I did not find code that depended
on these functions matching globs.

Changes the call sites where strstr was used with glob patterns to use
strglobin or strglob as the intention seemed to be (or, in one case,
strstr with the * removed as it did not affect the result anyway).
master
Chapman Flack 10 years ago committed by Harald Hoyer
parent
commit
2c19a5fa78
  1. 6
      dracut-functions.sh
  2. 4
      modules.d/40network/ifup.sh
  3. 2
      modules.d/40network/net-lib.sh
  4. 6
      modules.d/45ifcfg/write-ifcfg.sh
  5. 2
      modules.d/80cms/cms-write-ifcfg.sh
  6. 2
      modules.d/80cms/cmsifup.sh
  7. 2
      modules.d/95nfs/nfs-lib.sh
  8. 32
      modules.d/99base/dracut-lib.sh
  9. 2
      test/TEST-01-BASIC/test-init.sh
  10. 2
      test/TEST-02-SYSTEMD/test-init.sh
  11. 2
      test/TEST-03-USR-MOUNT/test-init.sh
  12. 2
      test/TEST-04-FULL-SYSTEMD/test-init.sh
  13. 2
      test/TEST-10-RAID/test-init.sh
  14. 2
      test/TEST-11-LVM/test-init.sh
  15. 2
      test/TEST-12-RAID-DEG/test-init.sh
  16. 2
      test/TEST-14-IMSM/test-init.sh
  17. 2
      test/TEST-16-DMSQUASH/test-init.sh
  18. 2
      test/TEST-17-LVM-THIN/test-init.sh
  19. 2
      test/TEST-20-NFS/client-init.sh
  20. 5
      test/TEST-50-MULTINIC/client-init.sh

6
dracut-functions.sh

@ -33,7 +33,11 @@ if [[ $initdir ]] && ! [[ -d $initdir ]]; then @@ -33,7 +33,11 @@ if [[ $initdir ]] && ! [[ -d $initdir ]]; then
fi

# Generic substring function. If $2 is in $1, return 0.
strstr() { [[ $1 = *$2* ]]; }
strstr() { [[ $1 = *"$2"* ]]; }
# Generic glob matching function. If glob pattern $2 matches anywhere in $1, OK
strglobin() { [[ $1 = *$2* ]]; }
# Generic glob matching function. If glob pattern $2 matches all of $1, OK
strglob() { [[ $1 = $2 ]]; }

# helper function for check() in module-setup.sh
# to check for required installed binaries

4
modules.d/40network/ifup.sh

@ -130,12 +130,12 @@ do_ipv6auto() { @@ -130,12 +130,12 @@ do_ipv6auto() {

# Handle static ip configuration
do_static() {
strstr $ip '*:*:*' && load_ipv6
strglobin $ip '*:*:*' && load_ipv6

linkup $netif
[ -n "$macaddr" ] && ip link set address $macaddr dev $netif
[ -n "$mtu" ] && ip link set mtu $mtu dev $netif
if strstr $ip '*:*:*'; then
if strglobin $ip '*:*:*'; then
# note no ip addr flush for ipv6
ip addr add $ip/$mask ${srv:+peer $srv} dev $netif
wait_for_ipv6_dad $netif

2
modules.d/40network/net-lib.sh

@ -377,7 +377,7 @@ ip_to_var() { @@ -377,7 +377,7 @@ ip_to_var() {
# ip=<ipv4-address> means anaconda-style static config argument cluster:
# ip=<ip> gateway=<gw> netmask=<nm> hostname=<host> mtu=<mtu>
# ksdevice={link|bootif|ibft|<MAC>|<ifname>}
if strstr "$autoconf" "*.*.*.*"; then
if strglob "$autoconf" "*.*.*.*"; then
ip="$autoconf"
gw=$(getarg gateway=)
mask=$(getarg netmask=)

6
modules.d/45ifcfg/write-ifcfg.sh

@ -85,7 +85,7 @@ for netup in /tmp/net.*.did-setup ; do @@ -85,7 +85,7 @@ for netup in /tmp/net.*.did-setup ; do

netif=${netup%%.did-setup}
netif=${netif##*/net.}
strstr "$netif" ":*:*:*:*:" && continue
strglobin "$netif" ":*:*:*:*:" && continue
[ -e /tmp/ifcfg/ifcfg-$netif ] && continue
unset bridge
unset bond
@ -132,7 +132,7 @@ for netup in /tmp/net.*.did-setup ; do @@ -132,7 +132,7 @@ for netup in /tmp/net.*.did-setup ; do
else
# If we've booted with static ip= lines, the override file is there
[ -e /tmp/net.$netif.override ] && . /tmp/net.$netif.override
if strstr "$ip" '*:*:*'; then
if strglobin "$ip" '*:*:*'; then
echo "IPV6INIT=yes"
echo "IPV6_AUTOCONF=no"
echo "IPV6ADDR=\"$ip/$mask\""
@ -149,7 +149,7 @@ for netup in /tmp/net.*.did-setup ; do @@ -149,7 +149,7 @@ for netup in /tmp/net.*.did-setup ; do
fi
fi
fi
if strstr "$gw" '*:*:*'; then
if strglobin "$gw" '*:*:*'; then
echo "IPV6_DEFAULTGW=\"$gw\""
elif [ -n "$gw" ]; then
echo "GATEWAY=\"$gw\""

2
modules.d/80cms/cms-write-ifcfg.sh

@ -26,7 +26,7 @@ function cms_write_config() @@ -26,7 +26,7 @@ function cms_write_config()

IFCFGFILE=/run/initramfs/state/etc/sysconfig/network-scripts/ifcfg-$DEVICE

strstr "$IPADDR" '*:*:*' && ipv6=1
strglobin "$IPADDR" '*:*:*' && ipv6=1

# to please NetworkManager on startup in loader before loader reconfigures net
cat > /etc/sysconfig/network << EOF

2
modules.d/80cms/cmsifup.sh

@ -8,7 +8,7 @@ DEVICE=$1 @@ -8,7 +8,7 @@ DEVICE=$1

. /tmp/cms.conf

strstr "$IPADDR" '*:*:*' && ipv6=1
strglobin "$IPADDR" '*:*:*' && ipv6=1

if [ "$ipv6" ] && ! str_starts "$IPADDR" "["; then
IPADDR="[$IPADDR]"

2
modules.d/95nfs/nfs-lib.sh

@ -40,7 +40,7 @@ nfsroot_to_var() { @@ -40,7 +40,7 @@ nfsroot_to_var() {
arg="${arg##$nfs:}"

# check if we have a server
if strstr "$arg" ':/*' ; then
if strstr "$arg" ':/' ; then
server="${arg%%:/*}"
arg="/${arg##*:/}"
fi

32
modules.d/99base/dracut-lib.sh

@ -20,19 +20,33 @@ debug_on() { @@ -20,19 +20,33 @@ debug_on() {
[ "$RD_DEBUG" = "yes" ] && set -x
}

# returns OK if $1 contains $2
# returns OK if $1 contains literal string $2 (and isn't empty)
strstr() {
[ "${1#*$2*}" != "$1" ]
[ "${1##*"$2"*}" != "$1" ]
}

# returns OK if $1 contains $2 at the beginning
# returns OK if $1 matches (completely) glob pattern $2
# An empty $1 will not be considered matched, even if $2 is * which technically
# matches; as it would match anything, it's not an interesting case.
strglob() {
[ -n "$1" -a -z "${1##$2}" ]
}

# returns OK if $1 contains (anywhere) a match of glob pattern $2
# An empty $1 will not be considered matched, even if $2 is * which technically
# matches; as it would match anything, it's not an interesting case.
strglobin() {
[ -n "$1" -a -z "${1##*$2*}" ]
}

# returns OK if $1 contains literal string $2 at the beginning, and isn't empty
str_starts() {
[ "${1#$2*}" != "$1" ]
[ "${1#"$2"*}" != "$1" ]
}

# returns OK if $1 contains $2 at the end
# returns OK if $1 contains literal string $2 at the end, and isn't empty
str_ends() {
[ "${1%*$2}" != "$1" ]
[ "${1%*"$2"}" != "$1" ]
}

if [ -z "$DRACUT_SYSTEMD" ]; then
@ -85,9 +99,9 @@ str_replace() { @@ -85,9 +99,9 @@ str_replace() {
local out=''

while strstr "${in}" "$s"; do
chop="${in%%$s*}"
chop="${in%%"$s"*}"
out="${out}${chop}$r"
in="${in#*$s}"
in="${in#*"$s"}"
done
echo "${out}${in}"
}
@ -555,7 +569,7 @@ nfsroot_to_var() { @@ -555,7 +569,7 @@ nfsroot_to_var() {
arg="${arg##$nfs:}"

# check if we have a server
if strstr "$arg" ':/*' ; then
if strstr "$arg" ':/' ; then
server="${arg%%:/*}"
arg="/${arg##*:/}"
fi

2
test/TEST-01-BASIC/test-init.sh

@ -1,7 +1,7 @@ @@ -1,7 +1,7 @@
#!/bin/sh
>/dev/watchdog
export PATH=/sbin:/bin:/usr/sbin:/usr/bin
strstr() { [ "${1#*$2*}" != "$1" ]; }
strstr() { [ "${1#*"$2"*}" != "$1" ]; }
CMDLINE=$(while read line; do echo $line;done < /proc/cmdline)
plymouth --quit
exec >/dev/console 2>&1

2
test/TEST-02-SYSTEMD/test-init.sh

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
#!/bin/sh
export PATH=/sbin:/bin:/usr/sbin:/usr/bin
strstr() { [ "${1#*$2*}" != "$1" ]; }
strstr() { [ "${1#*"$2"*}" != "$1" ]; }
CMDLINE=$(while read line; do echo $line;done < /proc/cmdline)
plymouth --quit
exec </dev/console >/dev/console 2>&1

2
test/TEST-03-USR-MOUNT/test-init.sh

@ -1,7 +1,7 @@ @@ -1,7 +1,7 @@
#!/bin/sh
>/dev/watchdog
export PATH=/sbin:/bin:/usr/sbin:/usr/bin
strstr() { [ "${1#*$2*}" != "$1" ]; }
strstr() { [ "${1#*"$2"*}" != "$1" ]; }
CMDLINE=$(while read line; do echo $line;done < /proc/cmdline)
plymouth --quit
exec </dev/console >/dev/console 2>&1

2
test/TEST-04-FULL-SYSTEMD/test-init.sh

@ -1,7 +1,7 @@ @@ -1,7 +1,7 @@
#!/bin/sh
>/dev/watchdog
export PATH=/sbin:/bin:/usr/sbin:/usr/bin
strstr() { [ "${1#*$2*}" != "$1" ]; }
strstr() { [ "${1#*"$2"*}" != "$1" ]; }
CMDLINE=$(while read line; do echo $line;done < /proc/cmdline)
plymouth --quit
exec </dev/console >/dev/console 2>&1

2
test/TEST-10-RAID/test-init.sh

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
#!/bin/sh
export PATH=/sbin:/bin:/usr/sbin:/usr/bin
strstr() { [ "${1#*$2*}" != "$1" ]; }
strstr() { [ "${1#*"$2"*}" != "$1" ]; }
CMDLINE=$(while read line; do echo $line;done < /proc/cmdline)
command -v plymouth >/dev/null && plymouth --quit
exec >/dev/console 2>&1

2
test/TEST-11-LVM/test-init.sh

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
#!/bin/sh
export PATH=/sbin:/bin:/usr/sbin:/usr/bin
strstr() { [ "${1#*$2*}" != "$1" ]; }
strstr() { [ "${1#*"$2"*}" != "$1" ]; }
CMDLINE=$(while read line; do echo $line;done < /proc/cmdline)
plymouth --quit
exec >/dev/console 2>&1

2
test/TEST-12-RAID-DEG/test-init.sh

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
#!/bin/sh
export PATH=/sbin:/bin:/usr/sbin:/usr/bin
strstr() { [ "${1#*$2*}" != "$1" ]; }
strstr() { [ "${1#*"$2"*}" != "$1" ]; }
CMDLINE=$(while read line; do echo $line;done < /proc/cmdline)
command -v plymouth >/dev/null && plymouth --quit
exec >/dev/console 2>&1

2
test/TEST-14-IMSM/test-init.sh

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
#!/bin/sh
export PATH=/sbin:/bin:/usr/sbin:/usr/bin
strstr() { [ "${1#*$2*}" != "$1" ]; }
strstr() { [ "${1#*"$2"*}" != "$1" ]; }
CMDLINE=$(while read line; do echo $line;done < /proc/cmdline)
plymouth --quit
exec >/dev/console 2>&1

2
test/TEST-16-DMSQUASH/test-init.sh

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
#!/bin/sh
export PATH=/sbin:/bin:/usr/sbin:/usr/bin
strstr() { [ "${1#*$2*}" != "$1" ]; }
strstr() { [ "${1#*"$2"*}" != "$1" ]; }
CMDLINE=$(while read line; do echo $line;done < /proc/cmdline)
plymouth --quit
exec >/dev/console 2>&1

2
test/TEST-17-LVM-THIN/test-init.sh

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
#!/bin/sh
export PATH=/sbin:/bin:/usr/sbin:/usr/bin
strstr() { [ "${1#*$2*}" != "$1" ]; }
strstr() { [ "${1#*"$2"*}" != "$1" ]; }
CMDLINE=$(while read line; do echo $line;done < /proc/cmdline)
plymouth --quit
exec >/dev/console 2>&1

2
test/TEST-20-NFS/client-init.sh

@ -4,7 +4,7 @@ exec >/dev/console 2>&1 @@ -4,7 +4,7 @@ exec >/dev/console 2>&1
export TERM=linux
export PS1='initramfs-test:\w\$ '
CMDLINE=$(while read line; do echo $line;done < /proc/cmdline)
strstr() { [ "${1#*$2*}" != "$1" ]; }
strstr() { [ "${1#*"$2"*}" != "$1" ]; }

stty sane
strstr "$CMDLINE" "rd.shell" && sh -i

5
test/TEST-50-MULTINIC/client-init.sh

@ -2,14 +2,15 @@ @@ -2,14 +2,15 @@
exec >/dev/console 2>&1
set -x
export PATH=/sbin:/bin:/usr/sbin:/usr/bin
strstr() { [ "${1#*$2*}" != "$1" ]; }
strstr() { [ "${1#*"$2"*}" != "$1" ]; }
strglobin() { [ -n "$1" -a -z "${1#*$2*}" ]; }
CMDLINE=$(while read line; do echo $line;done < /proc/cmdline)
export TERM=linux
export PS1='initramfs-test:\w\$ '
stty sane
echo "made it to the rootfs! Powering down."
for i in /run/initramfs/net.*.did-setup; do
strstr "$i" ":*:*:*:*:" && continue
strglobin "$i" ":*:*:*:*:" && continue
i=${i%.did-setup}
IFACES+="${i##*/net.} "
done

Loading…
Cancel
Save