mirror of https://github.com/ipxe/ipxe.git
[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>pull/41/head
parent
f3fbb5ff1c
commit
0a4805bf94
|
@ -700,17 +700,20 @@ static int peerblk_parse_header ( struct peerdist_block *peerblk ) {
|
||||||
return -EPROTO;
|
return -EPROTO;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Allocate cipher context. Freeing the cipher context (on
|
/* Allocate cipher context, if applicable. Freeing the cipher
|
||||||
* error or otherwise) is handled by peerblk_reset().
|
* context (on error or otherwise) is handled by peerblk_reset().
|
||||||
*/
|
*/
|
||||||
peerblk->cipher = cipher;
|
peerblk->cipher = cipher;
|
||||||
assert ( peerblk->cipherctx == NULL );
|
assert ( peerblk->cipherctx == NULL );
|
||||||
peerblk->cipherctx = malloc ( cipher->ctxsize );
|
if ( cipher ) {
|
||||||
if ( ! peerblk->cipherctx )
|
peerblk->cipherctx = malloc ( cipher->ctxsize );
|
||||||
return -ENOMEM;
|
if ( ! peerblk->cipherctx )
|
||||||
|
return -ENOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
/* Initialise cipher */
|
/* Initialise cipher, if applicable */
|
||||||
if ( ( rc = cipher_setkey ( cipher, peerblk->cipherctx, peerblk->secret,
|
if ( cipher &&
|
||||||
|
( rc = cipher_setkey ( cipher, peerblk->cipherctx, peerblk->secret,
|
||||||
keylen ) ) != 0 ) {
|
keylen ) ) != 0 ) {
|
||||||
DBGC ( peerblk, "PEERBLK %p %d.%d could not set key: %s\n",
|
DBGC ( peerblk, "PEERBLK %p %d.%d could not set key: %s\n",
|
||||||
peerblk, peerblk->segment, peerblk->block,
|
peerblk, peerblk->segment, peerblk->block,
|
||||||
|
|
Loading…
Reference in New Issue