]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[peerdist] Avoid NULL pointer dereference for plaintext blocks
authorMichael Brown <mcb30@ipxe.org>
Tue, 29 Sep 2015 00:24:36 +0000 (01:24 +0100)
committerMichael Brown <mcb30@ipxe.org>
Tue, 29 Sep 2015 00:24:36 +0000 (01:24 +0100)
Avoid accidentally dereferencing a NULL cipher context pointer for
plaintext blocks (which are usually messages with a block length of
zero, indicating a missing block).

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

index fd7ea0893737b058ede9c535ebcdeae5ae710a84..9fd52b736572bb8490aaa38df44aa5ec9a188c21 100644 (file)
@@ -700,17 +700,20 @@ static int peerblk_parse_header ( struct peerdist_block *peerblk ) {
                return -EPROTO;
        }
 
-       /* Allocate cipher context.  Freeing the cipher context (on
-        * error or otherwise) is handled by peerblk_reset().
+       /* Allocate cipher context, if applicable.  Freeing the cipher
+        * context (on error or otherwise) is handled by peerblk_reset().
         */
        peerblk->cipher = cipher;
        assert ( peerblk->cipherctx == NULL );
-       peerblk->cipherctx = malloc ( cipher->ctxsize );
-       if ( ! peerblk->cipherctx )
-               return -ENOMEM;
+       if ( cipher ) {
+               peerblk->cipherctx = malloc ( cipher->ctxsize );
+               if ( ! peerblk->cipherctx )
+                       return -ENOMEM;
+       }
 
-       /* Initialise cipher */
-       if ( ( rc = cipher_setkey ( cipher, peerblk->cipherctx, peerblk->secret,
+       /* Initialise cipher, if applicable */
+       if ( cipher &&
+            ( rc = cipher_setkey ( cipher, peerblk->cipherctx, peerblk->secret,
                                    keylen ) ) != 0 ) {
                DBGC ( peerblk, "PEERBLK %p %d.%d could not set key: %s\n",
                       peerblk, peerblk->segment, peerblk->block,