mirror of
https://github.com/amnezia-vpn/amneziawg-tools.git
synced 2025-08-02 09:32:51 +02:00
fix: handle empty awg params
This commit is contained in:
parent
44462751a6
commit
b1f5d05e93
1 changed files with 20 additions and 4 deletions
24
src/config.c
24
src/config.c
|
@ -22,6 +22,13 @@
|
|||
|
||||
#define COMMENT_CHAR '#'
|
||||
|
||||
// Keys that should return empty string instead of NULL when not found
|
||||
static const char *awg_optional_keys[] = {
|
||||
"I1", "I2", "I3", "I4", "I5",
|
||||
"J1", "J2", "J3",
|
||||
NULL
|
||||
};
|
||||
|
||||
static const char *get_value(const char *line, const char *key)
|
||||
{
|
||||
size_t linelen = strlen(line);
|
||||
|
@ -33,6 +40,7 @@ static const char *get_value(const char *line, const char *key)
|
|||
if (strncasecmp(line, key, keylen))
|
||||
return NULL;
|
||||
|
||||
|
||||
return line + keylen;
|
||||
}
|
||||
|
||||
|
@ -413,12 +421,12 @@ err:
|
|||
static inline bool parse_awg_string(char **device_value, const char *name, const char *value) {
|
||||
size_t len = strlen(value);
|
||||
if (!len) {
|
||||
fprintf(stderr, "Unable to parse empty string for: %s\n", name);
|
||||
return false;
|
||||
*device_value = "";
|
||||
return true;
|
||||
}
|
||||
|
||||
if( len >= MAX_AWG_JUNK_LEN) {
|
||||
fprintf(stderr, "Unable to process hex string longer than: %d\n", MAX_AWG_JUNK_LEN);
|
||||
fprintf(stderr, "Unable to process string for: %s; longer than: %d\n", name, MAX_AWG_JUNK_LEN);
|
||||
return false;
|
||||
}
|
||||
*device_value = strdup(value);
|
||||
|
@ -610,8 +618,16 @@ static bool process_line(struct config_ctx *ctx, const char *line)
|
|||
ret = parse_uint32(&ctx->device->itime, "Itime", value);
|
||||
if (ret)
|
||||
ctx->device->flags |= WGDEVICE_HAS_ITIME;
|
||||
} else
|
||||
} else {
|
||||
// Check if this is an AWG optional key
|
||||
if (strlen(line) == 3) {
|
||||
for (int i = 0; awg_optional_keys[i] != NULL; i++) {
|
||||
if (!strncasecmp(line, awg_optional_keys[i], 2))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
goto error;
|
||||
}
|
||||
} else if (ctx->is_peer_section) {
|
||||
if (key_match("Endpoint"))
|
||||
ret = parse_endpoint(&ctx->last_peer->endpoint.addr, value);
|
||||
|
|
Loading…
Add table
Reference in a new issue