# The config parser, against hostile input. dryrun is the parser's only # observable behaviour, so every case runs through it. "$VMM" create cfg1 64M >/dev/null 2>&1 : > "$VMMDIR/cfg1/config" exits 0 "minimal config parses" dryrun cfg1 cfg cfg1 < "$VMMDIR/cfg1/config" refuses 'config:2: NUL byte' "a NUL byte is refused on its own line" dryrun cfg1 # The parser is byte oriented whatever the caller's locale says, or a # multibyte character passes for one printable character. printf 'CDROM="/tmp/\303\251.iso"\n' > "$VMMDIR/cfg1/config" out=$(env LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 "$VMM" dryrun cfg1 2>&1) && got=0 || got=$? if [ "$got" != 0 ] && printf '%s' "$out" | grep -q 'non-printable'; then ok "a UTF-8 byte is refused under a UTF-8 locale" else notok "a UTF-8 byte is refused under a UTF-8 locale" "exit $got: $out" fi # A final line with no trailing newline must still be seen. printf 'CPUS=3' > "$VMMDIR/cfg1/config" outputs "-smp '3'" "final line without a newline is parsed" dryrun cfg1 # CRLF must not leak into a value. printf 'CPUS=4\r\n' > "$VMMDIR/cfg1/config" outputs "-smp '4'" "CRLF line endings are handled" dryrun cfg1 # An unreadable config must say so, not blame a key it never got to read. chmod 000 "$VMMDIR/cfg1/config" refuses 'not readable' "an unreadable config names the real problem" dryrun cfg1 chmod 600 "$VMMDIR/cfg1/config" # edit exists to re-read the config once the editor has been through it, # which is the only reason to run one from here. EDITOR=true is exported # by the harness, so what is left of edit is the check. : > "$VMMDIR/cfg1/config" exits 0 "edit re-validates the config it just wrote" edit cfg1 outputs 'config ok' "edit says so when the config parses" edit cfg1 cfg cfg1 <