Skip to content

fix #40: key length comparison in config.c - #41

Open
miuirussia wants to merge 1 commit into
amnezia-vpn:masterfrom
miuirussia:patch-1
Open

fix #40: key length comparison in config.c#41
miuirussia wants to merge 1 commit into
amnezia-vpn:masterfrom
miuirussia:patch-1

Conversation

@miuirussia

@miuirussia miuirussia commented Mar 5, 2026

Copy link
Copy Markdown

We already have checking emptiness of string in parsers, so empty value is valid. Fixes #40

We already have checking emptiness of string in parsers, so empty value is valid

Signed-off-by: Kirill Kuznetsov <kdevlab@yandex.ru>
@miuirussia miuirussia changed the title fix: key length comparison in config.c fix #40: key length comparison in config.c Mar 5, 2026
@bayes1701

bayes1701 commented Mar 5, 2026

Copy link
Copy Markdown

Probably it's better to skip lines with empty values in awg-quick:

@@ -49,8 +49,10 @@ parse_options() {
        shopt -s nocasematch
        while read -r line || [[ -n $line ]]; do
                stripped="${line%%\#*}"
+               [[ -z "${stripped//[[:space:]]/}" ]] && continue # skip empty lines
                key="${stripped%%=*}"; key="${key##*([[:space:]])}"; key="${key%%*([[:space:]])}"
                value="${stripped#*=}"; value="${value##*([[:space:]])}"; value="${value%%*([[:space:]])}"
+               [[ $stripped == *"="* && -z "$value" ]] && continue # skip lines with empty values
                [[ $key == "["* ]] && interface_section=0
                [[ $key == "[Interface]" ]] && interface_section=1
                if [[ $interface_section -eq 1 ]]; then

The reason is we are setting flags for found keys:

} else if (key_match("I1")) {
ret = parse_awg_string(&ctx->device->i1, "I1", value);
if (ret)
ctx->device->flags |= WGDEVICE_HAS_I1;
} else if (key_match("I2")) {

... and we can set a key unintentionally to an empty string (like PrivateKey=)

@miuirussia

miuirussia commented Mar 5, 2026

Copy link
Copy Markdown
Author

no, not better, as some scripts use directly complied binary, not scripts.

and empty PrivateKey will throw exception Key is not the correct length or format:

@bayes1701

Copy link
Copy Markdown

I think setting ctx->device->flags for empty values may have corner cases

@miuirussia

Copy link
Copy Markdown
Author

If you think, so test it and show me cases with error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

awg-quick crashes when i1–i5 parameters are empty (AmneziaWG v2 protocol)

2 participants