samba-o3: fix -Werror=maybe-uninitialized in lib/mscat/mscat_pks7.c
authorJoe Guo <joeg@catalyst.net.nz>
Fri, 21 Dec 2018 00:47:45 +0000 (13:47 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Fri, 8 Mar 2019 00:42:19 +0000 (00:42 +0000)
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>
lib/mscat/mscat_pkcs7.c

index d606a86..5d88289 100644 (file)
@@ -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;
                }
        }