[arch-projects] [netctl][PATCH] Improve handling of untrimmed profile names (FS#55295)

Jouke Witteveen j.witteveen at gmail.com
Sun Oct 8 08:36:12 UTC 2017


Reported by Michaël Cadilhac <michael at cadilhac.name>
---
 src/ifplugd.action | 4 ++--
 src/lib/globals    | 6 +++---
 src/netctl-auto    | 2 +-
 src/netctl.in      | 4 ++--
 src/wifi-menu      | 2 +-
 5 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/src/ifplugd.action b/src/ifplugd.action
index fa0321e..3da1ccc 100755
--- a/src/ifplugd.action
+++ b/src/ifplugd.action
@@ -8,13 +8,13 @@ PROFILE_FILE="$STATE_DIR/ifplugd-$1.profile"
 
 case "$2" in
   up)
-    while read -r profile; do
+    while IFS= read -r profile; do
         if ForceConnect=yes "$SUBR_DIR/network" start "$profile"; then
             mkdir -p "$(dirname "$PROFILE_FILE")"
             printf "%s" "$profile" > "$PROFILE_FILE"
             exit 0
         fi
-    done < <(list_profiles | while read -r profile; do
+    done < <(list_profiles | while IFS= read -r profile; do
         report_debug "Examining profile '$profile'"
         (
           source "$PROFILE_DIR/$profile" > /dev/null
diff --git a/src/lib/globals b/src/lib/globals
index 3caae2f..6cf8968 100644
--- a/src/lib/globals
+++ b/src/lib/globals
@@ -103,7 +103,7 @@ timeout_wait() {
 
 ### Profile management
 
-## List all acceptable profiles names (assume they don't contain newlines)
+## List all acceptable profiles names separated by newlines
 list_profiles() {
     # Follow aliases with -L, skip forbidden/reserved names
     find -L "$PROFILE_DIR/" -maxdepth 1 -type f -not -name '.*' -not -name '*~' -not -name $'*\n*' -not -name '*.action' -not -name '*.conf' -not -name '*.service' -printf "%f\n"
@@ -116,9 +116,9 @@ load_profile() {
     if [[ -z $1 || ! -r "$PROFILE_DIR/$1" ]]; then
         exit_error "Profile '$1' does not exist or is not readable"
     fi
-    while read -r hook; do
+    while IFS= read -r hook; do
         source "$hook"
-    done < <(find -L "$PROFILE_DIR/hooks" -maxdepth 1 -type f -executable -not -name '.*' -not -name '*~' | sort -u)
+    done < <(find -L "$PROFILE_DIR/hooks" -maxdepth 1 -type f -executable -not -name '.*' -not -name '*~' -not -name $'*\n*' | sort -u)
     source "$PROFILE_DIR/$1"
     if [[ -z $Interface ]]; then
         exit_error "Profile '$1' does not specify an interface"
diff --git a/src/netctl-auto b/src/netctl-auto
index 70f56b6..72f06c6 100755
--- a/src/netctl-auto
+++ b/src/netctl-auto
@@ -214,7 +214,7 @@ start() {
     echo "p2p_disabled=1" >> "$wpa_conf"
 
     local profile
-    list_profiles | while read -r profile; do
+    list_profiles | while IFS= read -r profile; do
         report_debug "Examining profile '$profile'"
         (
           source "$PROFILE_DIR/$profile"
diff --git a/src/netctl.in b/src/netctl.in
index 1b81d53..43213bc 100644
--- a/src/netctl.in
+++ b/src/netctl.in
@@ -30,7 +30,7 @@ END
 
 list() {
     local indicators=( ' ' '+' '*' ) i
-    list_profiles | while read -r Profile; do
+    list_profiles | while IFS= read -r Profile; do
         if sd_call "is-active --quiet" "$Profile" &> /dev/null; then
             [[ $(sd_status_text "$Profile") == "online" ]]
             (( i = 2 - $? ))
@@ -43,7 +43,7 @@ list() {
 
 store() {
     mkdir -p "$(dirname "$STATE_FILE")"
-    list_profiles | while read -r Profile; do
+    list_profiles | while IFS= read -r Profile; do
         if sd_call "is-active --quiet" "$Profile" &> /dev/null; then
             printf "%s\n" "$Profile"
         fi
diff --git a/src/wifi-menu b/src/wifi-menu
index eb04342..4774119 100755
--- a/src/wifi-menu
+++ b/src/wifi-menu
@@ -33,7 +33,7 @@ quote_safe() {
 # for interface $1.
 init_profiles() {
     local i=0 essid profile
-    while read -r profile; do
+    while IFS= read -r profile; do
         essid=$(
             unset INTERFACE ESSID
             source "$PROFILE_DIR/$profile" > /dev/null
-- 
2.14.2


More information about the arch-projects mailing list