diff --git a/src/gnutls_auth.cpp b/src/gnutls_auth.cpp index cd2b931..49572f0 100644 --- a/src/gnutls_auth.cpp +++ b/src/gnutls_auth.cpp @@ -191,15 +191,15 @@ size_t get_md5_digest_length() unsigned char* s3fs_md5hexsum(int fd, off_t start, off_t size) { struct md5_ctx ctx_md5; - unsigned char buf[512]; off_t bytes; unsigned char* result; - memset(buf, 0, 512); md5_init(&ctx_md5); for(off_t total = 0; total < size; total += bytes){ - bytes = 512 < (size - total) ? 512 : (size - total); + off_t len = 512; + unsigned char buf[len]; + bytes = len < (size - total) ? len : (size - total); bytes = pread(fd, buf, bytes, start + total); if(0 == bytes){ // end of file @@ -210,7 +210,6 @@ unsigned char* s3fs_md5hexsum(int fd, off_t start, off_t size) return NULL; } md5_update(&ctx_md5, bytes, buf); - memset(buf, 0, 512); } result = new unsigned char[get_md5_digest_length()]; md5_digest(&ctx_md5, get_md5_digest_length(), result); @@ -224,7 +223,6 @@ unsigned char* s3fs_md5hexsum(int fd, off_t start, off_t size) { gcry_md_hd_t ctx_md5; gcry_error_t err; - char buf[512]; off_t bytes; unsigned char* result; @@ -236,14 +234,15 @@ unsigned char* s3fs_md5hexsum(int fd, off_t start, off_t size) size = st.st_size; } - memset(buf, 0, 512); if(GPG_ERR_NO_ERROR != (err = gcry_md_open(&ctx_md5, GCRY_MD_MD5, 0))){ S3FS_PRN_ERR("MD5 context creation failure: %s/%s", gcry_strsource(err), gcry_strerror(err)); return NULL; } for(off_t total = 0; total < size; total += bytes){ - bytes = 512 < (size - total) ? 512 : (size - total); + off_t len = 512; + char buf[len]; + bytes = len < (size - total) ? len : (size - total); bytes = pread(fd, buf, bytes, start + total); if(0 == bytes){ // end of file @@ -255,7 +254,6 @@ unsigned char* s3fs_md5hexsum(int fd, off_t start, off_t size) return NULL; } gcry_md_write(ctx_md5, buf, bytes); - memset(buf, 0, 512); } result = new unsigned char[get_md5_digest_length()]; memcpy(result, gcry_md_read(ctx_md5, 0), get_md5_digest_length()); @@ -291,15 +289,15 @@ bool s3fs_sha256(const unsigned char* data, unsigned int datalen, unsigned char* unsigned char* s3fs_sha256hexsum(int fd, off_t start, off_t size) { struct sha256_ctx ctx_sha256; - unsigned char buf[512]; off_t bytes; unsigned char* result; - memset(buf, 0, 512); sha256_init(&ctx_sha256); for(off_t total = 0; total < size; total += bytes){ - bytes = 512 < (size - total) ? 512 : (size - total); + off_t len = 512; + unsigned char buf[len]; + bytes = len < (size - total) ? len : (size - total); bytes = pread(fd, buf, bytes, start + total); if(0 == bytes){ // end of file @@ -310,7 +308,6 @@ unsigned char* s3fs_sha256hexsum(int fd, off_t start, off_t size) return NULL; } sha256_update(&ctx_sha256, bytes, buf); - memset(buf, 0, 512); } result = new unsigned char[get_sha256_digest_length()]; sha256_digest(&ctx_sha256, get_sha256_digest_length(), result); @@ -343,7 +340,6 @@ unsigned char* s3fs_sha256hexsum(int fd, off_t start, off_t size) { gcry_md_hd_t ctx_sha256; gcry_error_t err; - char buf[512]; off_t bytes; unsigned char* result; @@ -355,14 +351,15 @@ unsigned char* s3fs_sha256hexsum(int fd, off_t start, off_t size) size = st.st_size; } - memset(buf, 0, 512); if(GPG_ERR_NO_ERROR != (err = gcry_md_open(&ctx_sha256, GCRY_MD_SHA256, 0))){ S3FS_PRN_ERR("SHA256 context creation failure: %s/%s", gcry_strsource(err), gcry_strerror(err)); return NULL; } for(off_t total = 0; total < size; total += bytes){ - bytes = 512 < (size - total) ? 512 : (size - total); + off_t len = 512; + char buf[len]; + bytes = len < (size - total) ? len : (size - total); bytes = pread(fd, buf, bytes, start + total); if(0 == bytes){ // end of file @@ -374,7 +371,6 @@ unsigned char* s3fs_sha256hexsum(int fd, off_t start, off_t size) return NULL; } gcry_md_write(ctx_sha256, buf, bytes); - memset(buf, 0, 512); } result = new unsigned char[get_sha256_digest_length()]; memcpy(result, gcry_md_read(ctx_sha256, 0), get_sha256_digest_length()); diff --git a/src/nss_auth.cpp b/src/nss_auth.cpp index 5fba304..2348581 100644 --- a/src/nss_auth.cpp +++ b/src/nss_auth.cpp @@ -153,7 +153,6 @@ size_t get_md5_digest_length() unsigned char* s3fs_md5hexsum(int fd, off_t start, off_t size) { PK11Context* md5ctx; - unsigned char buf[512]; off_t bytes; unsigned char* result; unsigned int md5outlen; @@ -166,11 +165,12 @@ unsigned char* s3fs_md5hexsum(int fd, off_t start, off_t size) size = st.st_size; } - memset(buf, 0, 512); md5ctx = PK11_CreateDigestContext(SEC_OID_MD5); for(off_t total = 0; total < size; total += bytes){ - bytes = 512 < (size - total) ? 512 : (size - total); + off_t len = 512; + unsigned char buf[len]; + bytes = len < (size - total) ? len : (size - total); bytes = pread(fd, buf, bytes, start + total); if(0 == bytes){ // end of file @@ -182,7 +182,6 @@ unsigned char* s3fs_md5hexsum(int fd, off_t start, off_t size) return NULL; } PK11_DigestOp(md5ctx, buf, bytes); - memset(buf, 0, 512); } result = new unsigned char[get_md5_digest_length()]; PK11_DigestFinal(md5ctx, result, &md5outlen, get_md5_digest_length()); @@ -219,7 +218,6 @@ bool s3fs_sha256(const unsigned char* data, unsigned int datalen, unsigned char* unsigned char* s3fs_sha256hexsum(int fd, off_t start, off_t size) { PK11Context* sha256ctx; - unsigned char buf[512]; off_t bytes; unsigned char* result; unsigned int sha256outlen; @@ -232,11 +230,12 @@ unsigned char* s3fs_sha256hexsum(int fd, off_t start, off_t size) size = st.st_size; } - memset(buf, 0, 512); sha256ctx = PK11_CreateDigestContext(SEC_OID_SHA256); for(off_t total = 0; total < size; total += bytes){ - bytes = 512 < (size - total) ? 512 : (size - total); + off_t len = 512; + unsigned char buf[len]; + bytes = len < (size - total) ? len : (size - total); bytes = pread(fd, buf, bytes, start + total); if(0 == bytes){ // end of file @@ -248,7 +247,6 @@ unsigned char* s3fs_sha256hexsum(int fd, off_t start, off_t size) return NULL; } PK11_DigestOp(sha256ctx, buf, bytes); - memset(buf, 0, 512); } result = new unsigned char[get_sha256_digest_length()]; PK11_DigestFinal(sha256ctx, result, &sha256outlen, get_sha256_digest_length()); diff --git a/src/openssl_auth.cpp b/src/openssl_auth.cpp index 40ff8a9..96ad694 100644 --- a/src/openssl_auth.cpp +++ b/src/openssl_auth.cpp @@ -256,7 +256,6 @@ size_t get_md5_digest_length() unsigned char* s3fs_md5hexsum(int fd, off_t start, off_t size) { MD5_CTX md5ctx; - char buf[512]; off_t bytes; unsigned char* result; @@ -268,11 +267,12 @@ unsigned char* s3fs_md5hexsum(int fd, off_t start, off_t size) size = st.st_size; } - memset(buf, 0, 512); MD5_Init(&md5ctx); for(off_t total = 0; total < size; total += bytes){ - bytes = 512 < (size - total) ? 512 : (size - total); + const off_t len = 512; + char buf[len]; + bytes = len < (size - total) ? len : (size - total); bytes = pread(fd, buf, bytes, start + total); if(0 == bytes){ // end of file @@ -283,7 +283,6 @@ unsigned char* s3fs_md5hexsum(int fd, off_t start, off_t size) return NULL; } MD5_Update(&md5ctx, buf, bytes); - memset(buf, 0, 512); } result = new unsigned char[get_md5_digest_length()]; @@ -319,7 +318,6 @@ unsigned char* s3fs_sha256hexsum(int fd, off_t start, off_t size) { const EVP_MD* md = EVP_get_digestbyname("sha256"); EVP_MD_CTX* sha256ctx; - char buf[512]; off_t bytes; unsigned char* result; @@ -334,9 +332,10 @@ unsigned char* s3fs_sha256hexsum(int fd, off_t start, off_t size) sha256ctx = EVP_MD_CTX_create(); EVP_DigestInit_ex(sha256ctx, md, NULL); - memset(buf, 0, 512); for(off_t total = 0; total < size; total += bytes){ - bytes = 512 < (size - total) ? 512 : (size - total); + const off_t len = 512; + char buf[len]; + bytes = len < (size - total) ? len : (size - total); bytes = pread(fd, buf, bytes, start + total); if(0 == bytes){ // end of file @@ -348,7 +347,6 @@ unsigned char* s3fs_sha256hexsum(int fd, off_t start, off_t size) return NULL; } EVP_DigestUpdate(sha256ctx, buf, bytes); - memset(buf, 0, 512); } result = new unsigned char[get_sha256_digest_length()]; EVP_DigestFinal_ex(sha256ctx, result, NULL);