Ver código fonte

Use read builtin safely

Alois Mahdal 7 anos atrás
pai
commit
9892a15371
3 arquivos alterados com 12 adições e 12 exclusões
  1. 4
    4
      src/include/build.sh
  2. 5
    5
      src/include/deploy.sh
  3. 3
    3
      src/include/ini.sh

+ 4
- 4
src/include/build.sh Ver arquivo

@@ -68,7 +68,7 @@ _expand_tokens() {
68 68
         do
69 69
             debug_var section
70 70
             ini lskeys "$section" \
71
-              | while read varname;
71
+              | while read -r varname;
72 72
                 do
73 73
                     varvalue="$(ini 1value "$section:$varname" | _qfs )"
74 74
                     echo "s|$varname|$varvalue|g;"
@@ -116,7 +116,7 @@ build() {
116 116
     #
117 117
     local srcpath
118 118
     find -type f -name '*.skel' \
119
-     | while read srcpath;
119
+     | while read -r srcpath;
120 120
        do
121 121
            _build1 "$srcpath"
122 122
        done
@@ -127,7 +127,7 @@ build_manpages() {
127 127
     if command -v ronn >/dev/null;
128 128
     then
129 129
         ini lskeys "files:man" \
130
-          | while read manfile;
130
+          | while read -r manfile;
131 131
             do
132 132
                 mdfile="$manfile.md"
133 133
                 ronn -r "$mdfile"
@@ -174,7 +174,7 @@ debstuff() {
174 174
     mkdir -p debian/source
175 175
     local dfsrc dftgt
176 176
     find "$debian_skel" -type f \
177
-      | while read dfsrc;
177
+      | while read -r dfsrc;
178 178
         do
179 179
             dftgt="debian/${dfsrc#$debian_skel}"
180 180
             mkdir -p "$(dirname "$dftgt")"

+ 5
- 5
src/include/deploy.sh Ver arquivo

@@ -31,7 +31,7 @@ _deploy_item() {
31 31
         _maybe mkdir -vp "$(dirname "$dst")"
32 32
         _maybe cp -Tvr "$src" "$dst"
33 33
         find "$dst" -type f \
34
-          | while read chmod_item;
34
+          | while read -r chmod_item;
35 35
             do
36 36
                 _maybe chmod "$mode" "$chmod_item"
37 37
             done
@@ -88,11 +88,11 @@ install() {
88 88
     ini lskeys "files" \
89 89
       | sort \
90 90
       | uniq \
91
-      | while read group;
91
+      | while read -r group;
92 92
         do
93 93
             mode=$(ini 1value "modes:$group")
94 94
             ini values "files:$group" \
95
-              | while read src dst;
95
+              | while read -r src dst;
96 96
                 do
97 97
                     dst=$(_get_dst "$group" "$src" "$dst")
98 98
                     _deploy_item "$src" "$dst" "$mode"
@@ -110,10 +110,10 @@ uninstall() {
110 110
     ini lskeys "files" \
111 111
       | sort \
112 112
       | uniq \
113
-      | while read group;
113
+      | while read -r group;
114 114
         do
115 115
             ini values "files:$group" \
116
-              | while read src dst;
116
+              | while read -r src dst;
117 117
                 do
118 118
                     dst=$(_get_dst "$group" "$src" "$dst")
119 119
                     _maybe rm -vrf "$dst"

+ 3
- 3
src/include/ini.sh Ver arquivo

@@ -4,7 +4,7 @@ _ini_cat() {
4 4
     #
5 5
     # A no-op for text stream
6 6
     #
7
-    while read line;
7
+    while read -r line;
8 8
     do
9 9
         printf -- "%s\n" "$line"
10 10
     done
@@ -15,7 +15,7 @@ _ini_expand() {
15 15
     # Expand reference value (prefix only)
16 16
     #
17 17
     local line suffix ref value
18
-    while read line;                        # [foo:bar]/path
18
+    while read -r line;                     # [foo:bar]/path
19 19
     do
20 20
         suffix="${line#\[*\]}"              # /path
21 21
         ref="${line%$suffix}"               # [foo:bar]
@@ -71,7 +71,7 @@ _ini_grepsec() {
71 71
     local ok=false
72 72
     grep '.' \
73 73
       | grep -v '\s*#' \
74
-      | while read line;
74
+      | while read -r line;
75 75
         do
76 76
             case "$line" in
77 77
                 \[$wnt\]) ok=true;  continue ;;