]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[crypto] Remove redundant null pointer check
authorMichael Brown <mcb30@ipxe.org>
Wed, 14 May 2025 11:34:27 +0000 (12:34 +0100)
committerMichael Brown <mcb30@ipxe.org>
Wed, 14 May 2025 11:46:23 +0000 (12:46 +0100)
Coverity reports a spurious potential null pointer dereference in
cms_decrypt(), since the null pointer check takes place after the
pointer has already been dereferenced.  The pointer can never be null,
since it is initialised to point to cipher_null at the point that the
containing structure is allocated.

Remove the redundant null pointer check, and for symmetry ensure that
the digest and public-key algorithm pointers are similarly initialised
at the point of allocation.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/crypto/cms.c

index edfcc7fdcda410f27d1213d65b548b3dfd8a703a..e3571f330bfdd575fe866948225ef04046e43630 100644 (file)
@@ -450,6 +450,8 @@ static int cms_parse_participants ( struct cms_message *cms,
                if ( ! part )
                        return -ENOMEM;
                list_add ( &part->list, &cms->participants );
+               part->digest = &digest_null;
+               part->pubkey = &pubkey_null;
 
                /* Allocate certificate chain */
                part->chain = x509_alloc_chain();
@@ -1046,12 +1048,6 @@ int cms_decrypt ( struct cms_message *cms, struct image *image,
        int pad_len;
        int rc;
 
-       /* Sanity checks */
-       if ( ! cipher ) {
-               rc = -ENOTTY;
-               goto err_no_cipher;
-       }
-
        /* Check block size */
        if ( ( image->len & ( cipher->blocksize - 1 ) ) != 0 ) {
                DBGC ( cms, "CMS %p invalid length %zd\n", cms, image->len );
@@ -1145,6 +1141,5 @@ int cms_decrypt ( struct cms_message *cms, struct image *image,
        image->flags = original_flags;
  err_cipher:
  err_blocksize:
- err_no_cipher:
        return rc;
 }