diff options
author | Björn Esser <besser82@fedoraproject.org> | 2021-07-22 23:37:59 +0200 |
---|---|---|
committer | Björn Esser <besser82@fedoraproject.org> | 2021-07-22 23:42:18 +0200 |
commit | db97b665c1d3762587071854991894182836ffe2 (patch) | |
tree | a34b9e9f5faeec87f0da81a84a95e9ae23d3fa45 | |
parent | a24f158fd9f12c89cf2290034b4b9620d262bfdf (diff) | |
download | libxcrypt-db97b665c1d3762587071854991894182836ffe2.tar.gz libxcrypt-db97b665c1d3762587071854991894182836ffe2.tar.bz2 libxcrypt-db97b665c1d3762587071854991894182836ffe2.zip |
test/alg-hmac-sha1.c: Fix 'STRING_NULL' found by Covscan.
CWE-170: String not null terminated (STRING_NULL)
string_null: Passing unterminated string dbuf to strcmp,
which expects a null-terminated string.
-rw-r--r-- | test/alg-hmac-sha1.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/test/alg-hmac-sha1.c b/test/alg-hmac-sha1.c index 5a87c7b..b7453ea 100644 --- a/test/alg-hmac-sha1.c +++ b/test/alg-hmac-sha1.c @@ -42,9 +42,9 @@ bin_to_char (char *buf, size_t bufsz, const char *data, size_t nbytes) { size_t i; + buf[0] = '\0'; if (bufsz <= (nbytes * 2)) return NULL; - buf[0] = '\0'; for (i = 0; i < nbytes; i++) { (void)sprintf (&buf[i*2], "%02x", (unsigned char)data[i]); @@ -156,7 +156,7 @@ main (void) X2B(test->data, dbuf); hmac_sha1_process_data ((const uint8_t *)test->data, test->data_size, (const uint8_t *)test->key, strlen(test->key), digest); - memcpy (dbuf, "0x", 2); + strncpy (dbuf, "0x", BUFSIZ); bin_to_char (&dbuf[2], (sizeof dbuf) - 2, digest, HASH_LENGTH); if (strcmp (dbuf, test->expect) != 0) |