Browse Source

Fix tests, use guard page instead of NULL because of Wasm

coverity_scan
Frank Denis 5 years ago
parent
commit
83a873ea1b
  1. 14
      test/default/auth.c
  2. 5
      test/default/auth3.c
  3. 5
      test/default/auth5.c
  4. 5
      test/default/auth7.c
  5. 2
      test/default/box_easy.c
  6. 4
      test/default/cmptest.h
  7. 21
      test/default/codecs.c
  8. 3
      test/default/codecs.exp
  9. 16
      test/default/sodium_utils.c

14
test/default/auth.c

@ -67,7 +67,7 @@ main(void)
printf("\n");
}
// Empty message tests: HMAC-SHA512
/* Empty message tests: HMAC-SHA512 */
memset(a2, 0, sizeof a2);
crypto_auth_hmacsha512_init(&st, key, sizeof key);
crypto_auth_hmacsha512_final(&st, a2);
@ -80,11 +80,11 @@ main(void)
memset(a3, 0, sizeof a3);
crypto_auth_hmacsha512_init(&st, key, sizeof key);
crypto_auth_hmacsha512_update(&st, NULL, 0U);
crypto_auth_hmacsha512_update(&st, guard_page, 0U);
crypto_auth_hmacsha512_final(&st, a3);
assert(sodium_memcmp(a2, a3, sizeof a2) == 0);
// Empty message tests: HMAC-SHA512-256
/* Empty message tests: HMAC-SHA512-256 */
memset(a2, 0, sizeof a2);
crypto_auth_hmacsha512256_init(&st512_256, key, sizeof key);
crypto_auth_hmacsha512256_final(&st512_256, a2);
@ -97,12 +97,12 @@ main(void)
memset(a3, 0, sizeof a3);
crypto_auth_hmacsha512256_init(&st512_256, key, sizeof key);
crypto_auth_hmacsha512256_update(&st512_256, NULL, 0U);
crypto_auth_hmacsha512256_update(&st512_256, guard_page, 0U);
crypto_auth_hmacsha512256_final(&st512_256, a3);
assert(sodium_memcmp(a2, a3, sizeof a2) == 0);
/* Empty message tests: HMAC-SHA256 */
// Empty message tests: HMAC-SHA256
memset(a2, 0, sizeof a2);
crypto_auth_hmacsha256_init(&st256, key, sizeof key);
crypto_auth_hmacsha256_final(&st256, a2);
@ -115,10 +115,12 @@ main(void)
memset(a3, 0, sizeof a3);
crypto_auth_hmacsha256_init(&st256, key, sizeof key);
crypto_auth_hmacsha256_update(&st256, NULL, 0U);
crypto_auth_hmacsha256_update(&st256, guard_page, 0U);
crypto_auth_hmacsha256_final(&st256, a3);
assert(sodium_memcmp(a2, a3, sizeof a2) == 0);
/* --- */
assert(crypto_auth_bytes() > 0U);
assert(crypto_auth_keybytes() > 0U);
assert(strcmp(crypto_auth_primitive(), "hmacsha512256") == 0);

5
test/default/auth3.c

@ -29,9 +29,8 @@ main(void)
printf("%d\n", crypto_auth_hmacsha256_verify(a, c, sizeof c, key));
// Test empty message with NULL pointer
crypto_auth_hmacsha256(a2, NULL, 0U, key);
assert(crypto_auth_hmacsha256_verify(a2, NULL, 0U, key) == 0);
crypto_auth_hmacsha256(a2, guard_page, 0U, key);
assert(crypto_auth_hmacsha256_verify(a2, guard_page, 0U, key) == 0);
return 0;
}

5
test/default/auth5.c

@ -33,10 +33,9 @@ main(void)
}
}
// Test empty message with NULL pointer
crypto_auth_keygen(key);
crypto_auth(a, NULL, 0U, key);
assert(crypto_auth_verify(a, NULL, 0U, key) == 0);
crypto_auth(a, guard_page, 0U, key);
assert(crypto_auth_verify(a, guard_page, 0U, key) == 0);
return 0;
}

5
test/default/auth7.c

@ -33,10 +33,9 @@ main(void)
}
}
// Test empty message with NULL pointer
crypto_auth_keygen(key);
crypto_auth_hmacsha512(a, NULL, 0U, key);
assert(crypto_auth_hmacsha512_verify(a, NULL, 0U, key) == 0);
crypto_auth_hmacsha512(a, guard_page, 0U, key);
assert(crypto_auth_hmacsha512_verify(a, guard_page, 0U, key) == 0);
return 0;
}

2
test/default/box_easy.c

@ -50,7 +50,7 @@ main(void)
/* Null message */
ret = crypto_box_easy(c, NULL, 0, nonce, bobpk, alicesk);
ret = crypto_box_easy(c, guard_page, 0, nonce, bobpk, alicesk);
assert(ret == 0);
for (i = 0; i < 1 + crypto_box_MACBYTES; ++i) {
printf(",0x%02x", (unsigned int) c[i]);

4
test/default/cmptest.h

@ -178,11 +178,15 @@ int main(void)
if (sodium_init() != 0) {
return 99;
}
# if defined(__EMSCRIPTEN__) || defined(__SANITIZE_ADDRESS__)
guard_page = _guard_page = NULL;
#else
if ((_guard_page = (unsigned char *) sodium_malloc(0)) == NULL) {
perror("sodium_malloc()");
return 99;
}
guard_page = _guard_page + 1;
#endif
if (xmain() != 0) {
return 99;
}

21
test/default/codecs.c

@ -20,10 +20,10 @@ main(void)
printf("%s\n",
sodium_bin2hex(buf3, 33U, (const unsigned char *) "0123456789ABCDEF",
16U));
printf("bin2hex(..., NULL, 0):%s\n",
sodium_bin2hex(buf4, sizeof(buf4), NULL, 0U));
printf("bin2hex(..., guard_page, 0):%s\n",
sodium_bin2hex(buf3, sizeof buf3, guard_page, 0U));
printf("bin2hex(..., \"\", 0):%s\n",
sodium_bin2hex(buf4, sizeof(buf4), (const unsigned char *) "", 0U));
sodium_bin2hex(buf3, sizeof buf3, (const unsigned char *) "", 0U));
hex = "Cafe : 6942";
sodium_hex2bin(buf4, sizeof buf4, hex, strlen(hex), ": ", &bin_len,
@ -84,10 +84,11 @@ main(void)
printf("sodium_hex2bin() with an extra character and no end pointer\n");
}
assert(sodium_hex2bin(buf4, sizeof(buf4), NULL, 0U, NULL, &bin_len, NULL) == 0);
assert(sodium_hex2bin(buf4, sizeof buf4, (const char *) guard_page, 0U,
NULL, &bin_len, NULL) == 0);
assert(bin_len == 0);
assert(sodium_hex2bin(buf4, sizeof(buf4), "", 0U, NULL, &bin_len, NULL) == 0);
assert(sodium_hex2bin(buf4, sizeof buf4, "", 0U, NULL, &bin_len, NULL) == 0);
assert(bin_len == 0);
printf("%s\n",
@ -105,9 +106,6 @@ main(void)
printf("%s\n",
sodium_bin2base64(buf3, 1U, guard_page,
0U, sodium_base64_VARIANT_ORIGINAL));
printf("%s\n",
sodium_bin2base64(buf3, 1U, NULL,
0U, sodium_base64_VARIANT_ORIGINAL));
printf("%s\n",
sodium_bin2base64(buf3, 5U, (const unsigned char *) "a",
1U, sodium_base64_VARIANT_ORIGINAL));
@ -215,10 +213,11 @@ main(void)
assert(sodium_base642bin(buf1, sizeof buf1, "ka*w*=*", (size_t) 7U, "*~", NULL, NULL,
sodium_base64_VARIANT_ORIGINAL) == 0);
assert(sodium_base642bin(buf1, sizeof buf1, "", 0U, NULL, &bin_len, NULL,
sodium_base64_VARIANT_ORIGINAL) == 0);
assert(sodium_base642bin(buf1, sizeof buf1, (const char *) guard_page, 0U,
NULL, &bin_len, NULL, sodium_base64_VARIANT_ORIGINAL) == 0);
assert(bin_len == 0);
assert(sodium_base642bin(buf1, sizeof buf1, NULL, 0U, NULL, &bin_len, NULL,
assert(sodium_base642bin(buf1, sizeof buf1, "", 0U, NULL, &bin_len, NULL,
sodium_base64_VARIANT_ORIGINAL) == 0);
assert(bin_len == 0);

3
test/default/codecs.exp

@ -1,5 +1,5 @@
30313233343536373839414243444546
bin2hex(..., NULL, 0):
bin2hex(..., guard_page, 0):
bin2hex(..., "", 0):
4:cafe6942
dt1: 11
@ -14,7 +14,6 @@ dt6: 11
-_DxMDEyMzQ1Njc4OUFCQ0RFRmFi
-_DxMDEyMzQ1Njc4OUFCQ0RFRmFiYw
YQ==
YWI=
YWJj

16
test/default/sodium_utils.c

@ -29,10 +29,10 @@ main(void)
printf("%d\n", sodium_memcmp(buf1, buf2, 0U));
sodium_memzero(buf2, sizeof buf2 / 2);
printf("%d\n", sodium_memcmp(buf1, buf2, sizeof buf1));
printf("%d\n", sodium_memcmp(buf1, NULL, 0U));
printf("%d\n", sodium_memcmp(NULL, buf2, 0U));
printf("%d\n", sodium_memcmp(NULL, NULL, 0U));
sodium_memzero(NULL, 0U);
printf("%d\n", sodium_memcmp(buf1, guard_page, 0U));
printf("%d\n", sodium_memcmp(guard_page, buf2, 0U));
printf("%d\n", sodium_memcmp(guard_page, guard_page, 0U));
sodium_memzero(guard_page, 0U);
memset(nonce, 0, sizeof nonce);
sodium_increment(nonce, sizeof nonce);
@ -163,18 +163,18 @@ main(void)
sodium_add(nonce, nonce, 0U);
printf("%s\n",
sodium_bin2hex(nonce_hex, sizeof nonce_hex, nonce, sizeof nonce));
sodium_add(nonce, NULL, 0U);
sodium_add(nonce, guard_page, 0U);
printf("%s\n",
sodium_bin2hex(nonce_hex, sizeof nonce_hex, nonce, sizeof nonce));
sodium_add(NULL, nonce, 0U);
sodium_add(guard_page, nonce, 0U);
sodium_sub(nonce, nonce, 0U);
printf("%s\n",
sodium_bin2hex(nonce_hex, sizeof nonce_hex, nonce, sizeof nonce));
sodium_sub(nonce, NULL, 0U);
sodium_sub(nonce, guard_page, 0U);
printf("%s\n",
sodium_bin2hex(nonce_hex, sizeof nonce_hex, nonce, sizeof nonce));
sodium_sub(NULL, nonce, 0U);
sodium_sub(guard_page, nonce, 0U);
randombytes_buf(buf1, 64U);
randombytes_buf(buf2, 64U);

Loading…
Cancel
Save