From 742f038fc2d57b15d1539c3cfc7d0c2fe45ac530 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Sun, 3 Jul 2016 20:06:33 +0200 Subject: wg: improve error reporting and detection Signed-off-by: Jason A. Donenfeld --- src/config.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'src/config.c') diff --git a/src/config.c b/src/config.c index 0cec30e..9066178 100644 --- a/src/config.c +++ b/src/config.c @@ -93,12 +93,8 @@ static inline uint16_t parse_port(const char *value) static inline bool parse_key(uint8_t key[WG_KEY_LEN], const char *value) { uint8_t tmp[WG_KEY_LEN + 1]; - if (strlen(value) != b64_len(WG_KEY_LEN) - 1) { - fprintf(stderr, "Key is not the correct length: `%s`\n", value); - return false; - } - if (b64_pton(value, tmp, WG_KEY_LEN + 1) < 0) { - fprintf(stderr, "Could not parse base64 key: `%s`\n", value); + if (strlen(value) != b64_len(WG_KEY_LEN) - 1 || b64_pton(value, tmp, WG_KEY_LEN + 1) != WG_KEY_LEN) { + fprintf(stderr, "Key is not the correct length or format: `%s`\n", value); return false; } memcpy(key, tmp, WG_KEY_LEN); -- cgit v1.2.3-59-g8ed1b