Skip to content

netinfo_to_resolv_conf: clear variables between sourcing

The function netinfo_to_resolv_conf does not clear the variables between reading multiples files. This can lead to duplicate entries in the resolv.conf in case the files do not specify the same variables.

Distilled problem:

#!/bin/sh

sourcing() {
    for file in "$@"; do
        local A B C
        . "./$file"
        echo "A: ${A-}"
        echo "B: ${B-}"
        echo "C: ${C-}"
        echo
    done
}

printf "A=1\nB=2\n" > first
printf "A=a\nC=c\n" > second
sourcing first second

B is only defined in the first file and will still contain this value after sourcing the second file:

A: 1
B: 2
C:

A: a
B: 2
C: c

So set the local variables to empty strings to clear them before sourcing the next configuration file.

Merge request reports

Loading