File 0026-ifup-check-for-valid-characters-in-interface-names.patch of Package sysconfig.openSUSE_12.1_Update

From 26e8b76f7934fe0e268d35fad2fe0c66c5bedc41 Mon Sep 17 00:00:00 2001
From: Marius Tomaschewski <mt@suse.com>
Date: Mon, 15 Oct 2012 14:12:38 +0200
References: bnc#784952
Subject: [PATCH 08/11] ifup: check for valid characters in interface names

---
 scripts/functions |    8 ++++++++
 scripts/ifup      |   18 ++++++++++--------
 2 Dateien geändert, 18 Zeilen hinzugefügt(+), 8 Zeilen entfernt(-)

diff --git a/scripts/functions b/scripts/functions
index 16f90da..ae617fe 100644
--- a/scripts/functions
+++ b/scripts/functions
@@ -82,6 +82,14 @@ add_to_wordlist() {
 	eval "$v='${l[@]}'"
 }
 
+is_valid_interface_name()
+{
+	local LANG=C LC_ALL=C
+	local INTERFACE="$1"
+	local IFNAME_RX='^[[:alnum:]._:-]{1,15}$'
+	[[ ${INTERFACE} =~ ${IFNAME_RX} ]]
+}
+
 is_iface_available () {
 	local IFNAME=${1}
 	local IFTYPE=${2:-$INTERFACETYPE}
diff --git a/scripts/ifup b/scripts/ifup
index cb62ccc..9a35c9a 100755
--- a/scripts/ifup
+++ b/scripts/ifup
@@ -137,20 +137,22 @@ test -f scripts/functions.common \
 # Get a configuration name
 
 if [ -z "$CONFIG" ] ; then
-	read CONFIG < <(read_cached_config_data config $INTERFACE)
+	read CONFIG < <(read_cached_config_data config "$INTERFACE")
 fi
 if [ -z "$CONFIG" ] ; then
 	CONFIG=$INTERFACE
 fi
 
+# Check valid interface name length and content
+if [ ${#INTERFACE} -gt 15 ] ; then
+	message "`printf "    %-9s: interface name too long" "$INTERFACE"`"
+	exit $R_ERROR
+elif ! is_valid_interface_name "$INTERFACE" ; then
+	message "`printf "    %-9s: invalid interface name" "$INTERFACE"`"
+	exit $R_ERROR
+fi
+
 case $SCRIPTNAME in
-	ifup)
-		if [ ${#INTERFACE} -gt 15 ] ; then
-			message "`printf "    %-9s: name too long" "$INTERFACE"`"
-			exit $R_ERROR
-			#exit $R_NOCONFIG
-		fi
-	;;
 	ifprobe)
 		IFUPFILE=$RUN_FILES_BASE/ifup-$INTERFACE
 		if [ ! -e "$IFUPFILE" ] ; then
-- 
1.7.10.4

openSUSE Build Service is sponsored by