Skip to content

Commit 31f7757

Browse files
committed
resolvconf: quote on printf rather than on value (#42)
This allows us to test values, for example matching a localhost address. Fixes #40.
1 parent 2c45197 commit 31f7757

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

resolvconf.in

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,8 @@ quote()
259259

260260
# Parse resolv.conf's and make variables
261261
# for domain name servers, search name servers and global nameservers
262+
# Important! Each printf here should use the above quote function
263+
# to ensure that user input is quoted for eval.
262264
parse_resolv()
263265
{
264266
domain=
@@ -270,8 +272,7 @@ parse_resolv()
270272
search=
271273

272274
while read -r line; do
273-
# Ensure the value is quoted for eval
274-
value="$(quote "${line#* }")"
275+
value="${line#* }"
275276
case "$line" in
276277
"# resolv.conf from "*)
277278
if ${new}; then
@@ -300,7 +301,7 @@ parse_resolv()
300301
esac
301302
done
302303
if $islocal; then
303-
printf '%s\n' "LOCALNAMESERVERS=\"\$LOCALNAMESERVERS \"$value"
304+
printf 'LOCALNAMESERVERS="$LOCALNAMESERVERS "%s\n' "$(quote "$value")"
304305
else
305306
ns="$ns${ns:+ }$value"
306307
fi
@@ -310,7 +311,7 @@ parse_resolv()
310311
if [ -z "$domain" ]; then
311312
domain="$search"
312313
if ! $nosearch; then
313-
printf '%s\n' "DOMAIN=$domain"
314+
printf 'DOMAIN=%s\n' "$(quote "$domain")"
314315
fi
315316
fi
316317
;;
@@ -328,13 +329,13 @@ parse_resolv()
328329
for d in $search; do
329330
ds="$ds${ds:+ }$d:$newns"
330331
done
331-
printf '%s\n' "DOMAINS=\"\$DOMAINS \"$ds"
332+
printf 'DOMAINS="$DOMAINS "%s\n' "$(quote "$ds")"
332333
fi
333334
if ! $nosearch; then
334-
printf '%s\n' "SEARCH=\"\$SEARCH \"$search"
335+
printf 'SEARCH="$SEARCH "%s\n' "$(quote "$search")"
335336
fi
336337
if ! $private; then
337-
printf '%s\n' "NAMESERVERS=\"\$NAMESERVERS \"$ns"
338+
printf 'NAMESERVERS="$NAMESERVERS "%s\n' "$(quote "$ns")"
338339
fi
339340
ns=
340341
search=
@@ -1039,11 +1040,11 @@ make_vars()
10391040
LOCALNAMESERVERS="$(list_remove name_server_blacklist $LOCALNAMESERVERS)"
10401041

10411042
# Ensure output is quoted for eval
1042-
printf '%s\n' "DOMAIN=$(quote "$DOMAIN")"
1043-
printf '%s\n' "SEARCH=$(quote "$SEARCH")"
1044-
printf '%s\n' "NAMESERVERS=$(quote "$NAMESERVERS")"
1045-
printf '%s\n' "LOCALNAMESERVERS=$(quote "$LOCALNAMESERVERS")"
1046-
printf '%s\n' "DOMAINS=$(quote "$newdomains")"
1043+
printf 'DOMAIN=%s\n' "$(quote "$DOMAIN")"
1044+
printf 'SEARCH=%s\n' "$(quote "$SEARCH")"
1045+
printf 'NAMESERVERS=%s\n' "$(quote "$NAMESERVERS")"
1046+
printf 'LOCALNAMESERVERS=%s\n' "$(quote "$LOCALNAMESERVERS")"
1047+
printf 'DOMAINS=%s\n' "$(quote "$newdomains")"
10471048
}
10481049

10491050
force=false

0 commit comments

Comments
 (0)