From f7aa9d7aaf479a5a3551e05b838197344ee94b10 Mon Sep 17 00:00:00 2001 From: TLINDEN Date: Sun, 15 Nov 2015 17:02:51 +0100 Subject: [PATCH] catch sodium_init() return --- libpcp/context.c | 5 ++++- tests/gencheader.c | 2 +- tests/invalidkeys.c | 2 +- tests/pwhashes.c | 2 +- tests/statictest.c | 2 +- 5 files changed, 8 insertions(+), 5 deletions(-) diff --git a/libpcp/context.c b/libpcp/context.c index 1e25fd5..f9778a2 100644 --- a/libpcp/context.c +++ b/libpcp/context.c @@ -43,7 +43,10 @@ PCPCTX *ptx_new() { p->pcppubkey_hash = NULL; p->pcpkeysig_hash = NULL; - sodium_init(); + if(sodium_init() == -1) { + perror("failed to initialize libsodium"); + exit(1); + } return p; } diff --git a/tests/gencheader.c b/tests/gencheader.c index cbc8f98..7505abe 100644 --- a/tests/gencheader.c +++ b/tests/gencheader.c @@ -12,7 +12,7 @@ void pr(char *var, unsigned char *d, size_t len) { } int main() { - sodium_init(); + if(sodium_init() == -1) return 1; pcp_key_t *a = pcpkey_new(); pcp_key_t *b = pcpkey_new(); diff --git a/tests/invalidkeys.c b/tests/invalidkeys.c index 112ee8a..e1b00b1 100644 --- a/tests/invalidkeys.c +++ b/tests/invalidkeys.c @@ -10,7 +10,7 @@ int main() { strcpy(o, "xxxx"); strcpy(m, "xxxx"); - sodium_init(); + if(sodium_init() == -1) return 1; PCPCTX *ptx = ptx_new(); pcp_key_t *k = pcpkey_new (); diff --git a/tests/pwhashes.c b/tests/pwhashes.c index 2728852..76ba429 100644 --- a/tests/pwhashes.c +++ b/tests/pwhashes.c @@ -25,7 +25,7 @@ int main() { pw *have = NULL; unsigned char nonce[32] = {1}; - sodium_init(); + if(sodium_init() == -1) return 1; for(i=97; i<126; ++i) { pass[0] = i; diff --git a/tests/statictest.c b/tests/statictest.c index 6fca11b..bab2071 100644 --- a/tests/statictest.c +++ b/tests/statictest.c @@ -2,7 +2,7 @@ #include "static.h" int main() { - sodium_init(); + if(sodium_init() == -1) return 1; unsigned char *t = ucmalloc(12); if(crypto_box_open_easy(t, cipher, cipher_len, nonce, public_a, secret_b) == 0) { if(memcmp(t, message, message_len) == 0) {