From f89473d29ce0bb1b275b47b8b70b2399696c7b26 Mon Sep 17 00:00:00 2001 From: Moinak Ghosh Date: Fri, 15 Feb 2013 22:53:17 +0530 Subject: [PATCH] Fixes for issues/warnings reported in issue #4. --- allocator.c | 2 +- crypto/crypto_utils.c | 1 + crypto/keccak/genKAT.c | 19 +++++++++++++++++++ rabin/global/config.c | 10 +++++----- rabin/rabin_dedup.c | 2 +- 5 files changed, 27 insertions(+), 7 deletions(-) diff --git a/allocator.c b/allocator.c index c9d48b5..cfc0fb1 100644 --- a/allocator.c +++ b/allocator.c @@ -489,8 +489,8 @@ slab_free(void *p, void *address) } if (!found) { pthread_mutex_unlock(&hbucket_locks[hindx]); - free(address); fprintf(stderr, "Freed buf(%p) not in slab allocations!\n", address); + free(address); abort(); fflush(stderr); } diff --git a/crypto/crypto_utils.c b/crypto/crypto_utils.c index ac48299..a945741 100644 --- a/crypto/crypto_utils.c +++ b/crypto/crypto_utils.c @@ -737,6 +737,7 @@ init_crypto(crypto_ctx_t *cctx, uchar_t *pwd, int pwd_len, int crypto_alg, if (saltlen > MAX_SALTLEN) { fprintf(stderr, "Salt too long. Max allowed length is %d\n", MAX_SALTLEN); + free(actx); return (-1); } cctx->salt = (uchar_t *)malloc(saltlen); diff --git a/crypto/keccak/genKAT.c b/crypto/keccak/genKAT.c index 1bd0733..41390f1 100755 --- a/crypto/keccak/genKAT.c +++ b/crypto/keccak/genKAT.c @@ -105,6 +105,7 @@ genShortMsg(int hashbitlen) sprintf(fn, "ShortMsgKAT_%d.txt", hashbitlen); if ( (fp_out = fopen(fn, "w")) == NULL ) { printf("Couldn't open <%s> for write\n", fn); + fclose(fp_in); return KAT_FILE_OPEN_ERROR; } fprintf(fp_out, "# %s\n", fn); @@ -114,6 +115,8 @@ genShortMsg(int hashbitlen) } else { printf("genShortMsg: Couldn't read Algorithm Name\n"); + fclose(fp_in); + fclose(fp_out); return KAT_HEADER_ERROR; } if ( FindMarker(fp_in, "# Principal Submitter:") ) { @@ -175,6 +178,7 @@ genShortMsgSponge(unsigned int rate, unsigned int capacity, int outputLength, co if ( (fp_out = fopen(fileName, "w")) == NULL ) { printf("Couldn't open <%s> for write\n", fileName); + fclose(fp_in); return KAT_FILE_OPEN_ERROR; } fprintf(fp_out, "# %s\n", fileName); @@ -184,6 +188,8 @@ genShortMsgSponge(unsigned int rate, unsigned int capacity, int outputLength, co } else { printf("genShortMsg: Couldn't read Algorithm Name\n"); + fclose(fp_in); + fclose(fp_out); return KAT_HEADER_ERROR; } if ( FindMarker(fp_in, "# Principal Submitter:") ) { @@ -248,6 +254,7 @@ genLongMsg(int hashbitlen) sprintf(fn, "LongMsgKAT_%d.txt", hashbitlen); if ( (fp_out = fopen(fn, "w")) == NULL ) { printf("Couldn't open <%s> for write\n", fn); + fclose(fp_in); return KAT_FILE_OPEN_ERROR; } fprintf(fp_out, "# %s\n", fn); @@ -257,6 +264,8 @@ genLongMsg(int hashbitlen) } else { printf("genLongMsg: Couldn't read Algorithm Name\n"); + fclose(fp_in); + fclose(fp_out); return KAT_HEADER_ERROR; } if ( FindMarker(fp_in, "# Principal Submitter:") ) { @@ -332,6 +341,7 @@ genExtremelyLongMsg(int hashbitlen) sprintf(fn, "ExtremelyLongMsgKAT_%d.txt", hashbitlen); if ( (fp_out = fopen(fn, "w")) == NULL ) { printf("Couldn't open <%s> for write\n", fn); + fclose(fp_in); return KAT_FILE_OPEN_ERROR; } fprintf(fp_out, "# %s\n", fn); @@ -341,6 +351,8 @@ genExtremelyLongMsg(int hashbitlen) } else { printf("genExtremelyLongMsg: Couldn't read Algorithm Name\n"); + fclose(fp_in); + fclose(fp_out); return KAT_HEADER_ERROR; } if ( FindMarker(fp_in, "# Principal Submitter:") ) { @@ -419,6 +431,7 @@ genMonteCarlo(int hashbitlen) sprintf(fn, "MonteCarlo_%d.txt", hashbitlen); if ( (fp_out = fopen(fn, "w")) == NULL ) { printf("Couldn't open <%s> for write\n", fn); + fclose(fp_in); return KAT_FILE_OPEN_ERROR; } fprintf(fp_out, "# %s\n", fn); @@ -428,6 +441,8 @@ genMonteCarlo(int hashbitlen) } else { printf("genMonteCarlo: Couldn't read Algorithm Name\n"); + fclose(fp_in); + fclose(fp_out); return KAT_HEADER_ERROR; } if ( FindMarker(fp_in, "# Principal Submitter:") ) { @@ -484,6 +499,7 @@ genMonteCarloSqueezing(int hashbitlen) sprintf(fn, "MonteCarlo_%d.txt", hashbitlen); if ( (fp_out = fopen(fn, "w")) == NULL ) { printf("Couldn't open <%s> for write\n", fn); + fclose(fp_in); return KAT_FILE_OPEN_ERROR; } fprintf(fp_out, "# %s\n", fn); @@ -493,6 +509,8 @@ genMonteCarloSqueezing(int hashbitlen) } else { printf("genMonteCarlo: Couldn't read Algorithm Name\n"); + fclose(fp_in); + fclose(fp_out); return KAT_HEADER_ERROR; } if ( FindMarker(fp_in, "# Principal Submitter:") ) { @@ -558,6 +576,7 @@ genDuplexKAT(unsigned int rate, unsigned int capacity, const char *fileName) if ( (fp_out = fopen(fileName, "w")) == NULL ) { printf("Couldn't open <%s> for write\n", fileName); + fclose(fp_in); return KAT_FILE_OPEN_ERROR; } fprintf(fp_out, "# %s\n", fileName); diff --git a/rabin/global/config.c b/rabin/global/config.c index 822707a..9f9f058 100644 --- a/rabin/global/config.c +++ b/rabin/global/config.c @@ -111,19 +111,19 @@ get_cksum_type(char *cksum_name) if (strcmp(cksum_name, "SHA256") == 0) { return (CKSUM_SHA256); - } else if (cksum_name, "SHA512") == 0) { + } else if (strcmp(cksum_name, "SHA512") == 0) { return (CKSUM_SHA512); - } else if (cksum_name, "BLAKE256") == 0) { + } else if (strcmp(cksum_name, "BLAKE256") == 0) { return (CKSUM_BLAKE256); - } else if (cksum_name, "BLAKE512") == 0) { + } else if (strcmp(cksum_name, "BLAKE512") == 0) { return (CKSUM_BLAKE512); - } else if (cksum_name, "KECCAK256") == 0) { + } else if (strcmp(cksum_name, "KECCAK256") == 0) { return (CKSUM_KECCAK256); - } else if (cksum_name, "KECCAK512") == 0) { + } else if (strcmp(cksum_name, "KECCAK512") == 0) { return (CKSUM_KECCAK512); } return (CKSUM_INVALID); diff --git a/rabin/rabin_dedup.c b/rabin/rabin_dedup.c index 8ecdb85..d3e0b62 100755 --- a/rabin/rabin_dedup.c +++ b/rabin/rabin_dedup.c @@ -526,7 +526,7 @@ dedupe_compress(dedupe_context_t *ctx, uchar_t *buf, uint64_t *size, uint64_t of if (ctx->delta_flag) { uint64_t cur_sketch; - uint64_t pc[3]; + uint64_t pc[4]; if (length > ctx->rabin_poly_min_block_size) { memcpy(ctx_heap, buf1+last_offset, length);