* [PATCH] net: irda: using kzalloc() instead of kmalloc() to avoid strncpy() issue.
@ 2013-05-17 9:13 Chen Gang
2013-05-19 22:11 ` David Miller
0 siblings, 1 reply; 3+ messages in thread
From: Chen Gang @ 2013-05-17 9:13 UTC (permalink / raw)
To: samuel; +Cc: David Miller, netdev
'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>
---
net/irda/irlap_frame.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/net/irda/irlap_frame.c b/net/irda/irlap_frame.c
index 8c00416..9ea0c93 100644
--- a/net/irda/irlap_frame.c
+++ b/net/irda/irlap_frame.c
@@ -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;
--
1.7.7.6
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] net: irda: using kzalloc() instead of kmalloc() to avoid strncpy() issue.
2013-05-17 9:13 [PATCH] net: irda: using kzalloc() instead of kmalloc() to avoid strncpy() issue Chen Gang
@ 2013-05-19 22:11 ` David Miller
2013-05-20 1:04 ` Chen Gang
0 siblings, 1 reply; 3+ messages in thread
From: David Miller @ 2013-05-19 22:11 UTC (permalink / raw)
To: gang.chen; +Cc: samuel, netdev
From: Chen Gang <gang.chen@asianux.com>
Date: Fri, 17 May 2013 17:13:04 +0800
>
> '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>
Applied, thanks.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] net: irda: using kzalloc() instead of kmalloc() to avoid strncpy() issue.
2013-05-19 22:11 ` David Miller
@ 2013-05-20 1:04 ` Chen Gang
0 siblings, 0 replies; 3+ messages in thread
From: Chen Gang @ 2013-05-20 1:04 UTC (permalink / raw)
To: David Miller; +Cc: samuel, netdev
On 05/20/2013 06:11 AM, David Miller wrote:
> From: Chen Gang <gang.chen@asianux.com>
> Date: Fri, 17 May 2013 17:13:04 +0800
>
>> >
>> > '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>
> Applied, thanks.
>
>
Thank you, too.
Thanks.
--
Chen Gang
Asianux Corporation
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-05-20 1:05 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-05-17 9:13 [PATCH] net: irda: using kzalloc() instead of kmalloc() to avoid strncpy() issue Chen Gang
2013-05-19 22:11 ` David Miller
2013-05-20 1:04 ` Chen Gang
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.