diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2016-07-03 20:06:33 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2016-07-03 20:45:48 +0200 |
commit | 742f038fc2d57b15d1539c3cfc7d0c2fe45ac530 (patch) | |
tree | 5713d6b29fb56bb07615cae7d778260627f71cbc /src/config.c | |
parent | contrib: remove extraneous cruft (diff) | |
download | wireguard-tools-742f038fc2d57b15d1539c3cfc7d0c2fe45ac530.tar.xz wireguard-tools-742f038fc2d57b15d1539c3cfc7d0c2fe45ac530.zip |
wg: improve error reporting and detection
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'src/config.c')
-rw-r--r-- | src/config.c | 8 |
1 files changed, 2 insertions, 6 deletions
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); |