Skip to content

Commit

Permalink
[peerdist] Avoid NULL pointer dereference for plaintext blocks
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
mcb30 committed Sep 29, 2015
1 parent f3fbb5f commit 0a4805b
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/net/peerblk.c
Expand Up @@ -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,
Expand Down

0 comments on commit 0a4805b

Please sign in to comment.