Sfoglia il codice sorgente

[peerdist] Avoid NULL pointer dereference for plaintext blocks

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>
tags/v1.20.1
Michael Brown 9 anni fa
parent
commit
0a4805bf94
1 ha cambiato i file con 10 aggiunte e 7 eliminazioni
  1. 10
    7
      src/net/peerblk.c

+ 10
- 7
src/net/peerblk.c Vedi File

@@ -700,17 +700,20 @@ static int peerblk_parse_header ( struct peerdist_block *peerblk ) {
700 700
 		return -EPROTO;
701 701
 	}
702 702
 
703
-	/* Allocate cipher context.  Freeing the cipher context (on
704
-	 * error or otherwise) is handled by peerblk_reset().
703
+	/* Allocate cipher context, if applicable.  Freeing the cipher
704
+	 * context (on error or otherwise) is handled by peerblk_reset().
705 705
 	 */
706 706
 	peerblk->cipher = cipher;
707 707
 	assert ( peerblk->cipherctx == NULL );
708
-	peerblk->cipherctx = malloc ( cipher->ctxsize );
709
-	if ( ! peerblk->cipherctx )
710
-		return -ENOMEM;
708
+	if ( cipher ) {
709
+		peerblk->cipherctx = malloc ( cipher->ctxsize );
710
+		if ( ! peerblk->cipherctx )
711
+			return -ENOMEM;
712
+	}
711 713
 
712
-	/* Initialise cipher */
713
-	if ( ( rc = cipher_setkey ( cipher, peerblk->cipherctx, peerblk->secret,
714
+	/* Initialise cipher, if applicable */
715
+	if ( cipher &&
716
+	     ( rc = cipher_setkey ( cipher, peerblk->cipherctx, peerblk->secret,
714 717
 				    keylen ) ) != 0 ) {
715 718
 		DBGC ( peerblk, "PEERBLK %p %d.%d could not set key: %s\n",
716 719
 		       peerblk, peerblk->segment, peerblk->block,

Loading…
Annulla
Salva