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>
struct stat sb = {0};
size_t alloc_size;
size_t count;
- DATA_BLOB blob;
+ DATA_BLOB blob = data_blob_null;
FILE *fp;
int rc;
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;
}
}