mirror of
https://github.com/samba-team/samba.git
synced 2025-08-26 01:49:31 +03:00
samba-o3: fix -Werror=maybe-uninitialized in lib/mscat/mscat_pks7.c
samba-o3 test failed in ubuntu:1804 image with: ../../lib/mscat/mscat_pkcs7.c: In function ‘mscat_pkcs7_import_catfile’: ../../lib/mscat/mscat_pkcs7.c:143:18: error: ‘blob.length’ may be used uninitialized in this function [-Werror=maybe-uninitialized] mscat_data.size = blob.length; ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~ ../../lib/mscat/mscat_pkcs7.c:142:18: error: ‘blob.data’ may be used uninitialized in this function [-Werror=maybe-uninitialized] mscat_data.data = blob.data; ~~~~~~~~~~~~~~~~^~~~~~~~~~~ ../../lib/mscat/mscat_pkcs7.c: In function ‘mscat_pkcs7_verify’: ../../lib/mscat/mscat_pkcs7.c:225:16: error: ‘blob.length’ may be used uninitialized in this function [-Werror=maybe-uninitialized] ca_data.size = blob.length; ~~~~~~~~~~~~~^~~~~~~~~~~~~ ../../lib/mscat/mscat_pkcs7.c:224:16: error: ‘blob.data’ may be used uninitialized in this function [-Werror=maybe-uninitialized] ca_data.data = blob.data; ~~~~~~~~~~~~~^~~~~~~~~~~ cc1: all warnings being treated as errors Since in `mscat_read_file`, it may still return rc = 0 while goto error, ends up with blob uninitialized. Signed-off-by: Joe Guo <joeg@catalyst.net.nz> Reviewed-by: Andreas Schneider <asn@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
This commit is contained in:
@ -66,7 +66,7 @@ static int mscat_read_file(TALLOC_CTX *mem_ctx,
|
||||
struct stat sb = {0};
|
||||
size_t alloc_size;
|
||||
size_t count;
|
||||
DATA_BLOB blob;
|
||||
DATA_BLOB blob = data_blob_null;
|
||||
FILE *fp;
|
||||
int rc;
|
||||
|
||||
@ -82,22 +82,26 @@ static int mscat_read_file(TALLOC_CTX *mem_ctx,
|
||||
|
||||
if (!S_ISREG(sb.st_mode)) {
|
||||
errno = EINVAL;
|
||||
rc = -1;
|
||||
goto error;
|
||||
}
|
||||
if (SIZE_MAX - 1 < (unsigned long)sb.st_size) {
|
||||
errno = ENOMEM;
|
||||
rc = -1;
|
||||
goto error;
|
||||
}
|
||||
alloc_size = sb.st_size + 1;
|
||||
|
||||
blob = data_blob_talloc_zero(mem_ctx, alloc_size);
|
||||
if (blob.data == NULL) {
|
||||
rc = -1;
|
||||
goto error;
|
||||
}
|
||||
|
||||
count = fread(blob.data, 1, blob.length, fp);
|
||||
if (count != blob.length) {
|
||||
if (ferror(fp)) {
|
||||
rc = -1;
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user