msgb: Check the return value of msgb_alloc (Coverity)

In some places, the return value of msgb_alloc/msgb_alloc_headroom
is not checked before it is dereferenced.

This commit adds NULL checks to return with -ENOMEM from the calling
functions if the alloc function has failed.

Fixes: Coverity CID 1249692, 1293376
Sponsored-by: On-Waves ehf
This commit is contained in:
Jacob Erlbeck 2015-04-09 14:22:21 +02:00 committed by Holger Hans Peter Freyther
parent 8d192d7153
commit d154f8bda2
2 changed files with 6 additions and 0 deletions

View File

@ -675,6 +675,9 @@ static int l2_ph_rach_ind(struct lapdm_entity *le, uint8_t ra, uint32_t fn, uint
struct gsm_time gt;
struct msgb *msg = msgb_alloc_headroom(512, 64, "RSL CHAN RQD");
if (!msg)
return -ENOMEM;
msg->l2h = msgb_push(msg, sizeof(*ch));
ch = (struct abis_rsl_cchan_hdr *)msg->l2h;
rsl_init_cchan_hdr(ch, RSL_MT_CHAN_RQD);

View File

@ -58,6 +58,9 @@ static int transceive_apdu_t0(struct osim_card_hdl *st, struct msgb *amsg)
uint16_t sw;
int rc, num_resp = 0;
if (!tmsg)
return -ENOMEM;
/* create TPDU header from APDU header */
tpduh = (struct osim_apdu_cmd_hdr *) msgb_put(tmsg, sizeof(*tpduh));
memcpy(tpduh, msgb_apdu_h(amsg), sizeof(*tpduh));