Skip to content

Commit

Permalink
net: irda: using kzalloc() instead of kmalloc() to avoid strncpy() is…
Browse files Browse the repository at this point in the history
…sue.

'discovery->data.info' length is 22, NICKNAME_MAX_LEN is 21, so the
strncpy() will always left the last byte of 'discovery->data.info'
uninitialized.

When 'text' length is longer than 21 (NICKNAME_MAX_LEN), if still left
the last byte of 'discovery->data.info' uninitialized, the next
strlen() will cause issue.

Also 'discovery->data' is 'struct irda_device_info' which defined in
"include/uapi/...", it may copy to user mode, so need whole initialized.

All together, need use kzalloc() instead of kmalloc() to initialize all
members firstly.

Signed-off-by: Chen Gang <gang.chen@asianux.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Chen Gang authored and davem330 committed May 19, 2013
1 parent 6b21e1b commit ff0102e
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion net/irda/irlap_frame.c
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ static void irlap_recv_discovery_xid_cmd(struct irlap_cb *self,
/*
* We now have some discovery info to deliver!
*/
discovery = kmalloc(sizeof(discovery_t), GFP_ATOMIC);
discovery = kzalloc(sizeof(discovery_t), GFP_ATOMIC);
if (!discovery) {
IRDA_WARNING("%s: unable to malloc!\n", __func__);
return;
Expand Down

0 comments on commit ff0102e

Please sign in to comment.