All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drivers/staging/irda: fix max dup length for kstrndup
@ 2017-12-12  8:54 Ma Shimiao
  2017-12-12 18:27 ` Stephen Hemminger
  0 siblings, 1 reply; 3+ messages in thread
From: Ma Shimiao @ 2017-12-12  8:54 UTC (permalink / raw)
  To: samuel; +Cc: netdev, linux-kernel, Ma Shimiao

If source string longer than max, kstrndup will alloc max+1 space.
So, we should make sure the result will not over limit.

Signed-off-by: Ma Shimiao <mashimiao.fnst@cn.fujitsu.com>
---
 drivers/staging/irda/net/irias_object.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/irda/net/irias_object.c b/drivers/staging/irda/net/irias_object.c
index 53b86d0e1630..b626f796a3ff 100644
--- a/drivers/staging/irda/net/irias_object.c
+++ b/drivers/staging/irda/net/irias_object.c
@@ -56,7 +56,7 @@ struct ias_object *irias_new_object( char *name, int id)
 	}
 
 	obj->magic = IAS_OBJECT_MAGIC;
-	obj->name = kstrndup(name, IAS_MAX_CLASSNAME, GFP_ATOMIC);
+	obj->name = kstrndup(name, IAS_MAX_CLASSNAME - 1, GFP_ATOMIC);
 	if (!obj->name) {
 		net_warn_ratelimited("%s(), Unable to allocate name!\n",
 				     __func__);
@@ -326,7 +326,7 @@ void irias_add_integer_attrib(struct ias_object *obj, char *name, int value,
 	}
 
 	attrib->magic = IAS_ATTRIB_MAGIC;
-	attrib->name = kstrndup(name, IAS_MAX_ATTRIBNAME, GFP_ATOMIC);
+	attrib->name = kstrndup(name, IAS_MAX_ATTRIBNAME - 1, GFP_ATOMIC);
 
 	/* Insert value */
 	attrib->value = irias_new_integer_value(value);
@@ -370,7 +370,7 @@ void irias_add_octseq_attrib(struct ias_object *obj, char *name, __u8 *octets,
 	}
 
 	attrib->magic = IAS_ATTRIB_MAGIC;
-	attrib->name = kstrndup(name, IAS_MAX_ATTRIBNAME, GFP_ATOMIC);
+	attrib->name = kstrndup(name, IAS_MAX_ATTRIBNAME - 1, GFP_ATOMIC);
 
 	attrib->value = irias_new_octseq_value( octets, len);
 	if (!attrib->name || !attrib->value) {
@@ -412,7 +412,7 @@ void irias_add_string_attrib(struct ias_object *obj, char *name, char *value,
 	}
 
 	attrib->magic = IAS_ATTRIB_MAGIC;
-	attrib->name = kstrndup(name, IAS_MAX_ATTRIBNAME, GFP_ATOMIC);
+	attrib->name = kstrndup(name, IAS_MAX_ATTRIBNAME - 1, GFP_ATOMIC);
 
 	attrib->value = irias_new_string_value(value);
 	if (!attrib->name || !attrib->value) {
@@ -468,7 +468,7 @@ struct ias_value *irias_new_string_value(char *string)
 
 	value->type = IAS_STRING;
 	value->charset = CS_ASCII;
-	value->t.string = kstrndup(string, IAS_MAX_STRING, GFP_ATOMIC);
+	value->t.string = kstrndup(string, IAS_MAX_STRING - 1, GFP_ATOMIC);
 	if (!value->t.string) {
 		net_warn_ratelimited("%s: Unable to kmalloc!\n", __func__);
 		kfree(value);
-- 
2.13.6

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] drivers/staging/irda: fix max dup length for kstrndup
  2017-12-12  8:54 [PATCH] drivers/staging/irda: fix max dup length for kstrndup Ma Shimiao
@ 2017-12-12 18:27 ` Stephen Hemminger
  2017-12-13  1:03   ` Ma Shimiao
  0 siblings, 1 reply; 3+ messages in thread
From: Stephen Hemminger @ 2017-12-12 18:27 UTC (permalink / raw)
  To: Ma Shimiao; +Cc: samuel, netdev, linux-kernel

On Tue, 12 Dec 2017 16:54:44 +0800
Ma Shimiao <mashimiao.fnst@cn.fujitsu.com> wrote:

> If source string longer than max, kstrndup will alloc max+1 space.
> So, we should make sure the result will not over limit.
> 
> Signed-off-by: Ma Shimiao <mashimiao.fnst@cn.fujitsu.com>

Did you read the TODO file in drivers/staging/irda?
	
	The irda code will be removed soon from the kernel tree as it is old and
	obsolete and broken.

	Don't worry about fixing up anything here, it's not needed.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] drivers/staging/irda: fix max dup length for kstrndup
  2017-12-12 18:27 ` Stephen Hemminger
@ 2017-12-13  1:03   ` Ma Shimiao
  0 siblings, 0 replies; 3+ messages in thread
From: Ma Shimiao @ 2017-12-13  1:03 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: samuel, netdev, linux-kernel

On 12/13/2017 02:27 AM, Stephen Hemminger wrote:
> On Tue, 12 Dec 2017 16:54:44 +0800
> Ma Shimiao <mashimiao.fnst@cn.fujitsu.com> wrote:
> 
>> If source string longer than max, kstrndup will alloc max+1 space.
>> So, we should make sure the result will not over limit.
>>
>> Signed-off-by: Ma Shimiao <mashimiao.fnst@cn.fujitsu.com>
> 
> Did you read the TODO file in drivers/staging/irda?
> 	
> 	The irda code will be removed soon from the kernel tree as it is old and
> 	obsolete and broken.
> 
> 	Don't worry about fixing up anything here, it's not needed.

Ah.. OK. Did not enter into the directory and notice it.
> 
> 
> 


-- 
Ma Shimiao
Development Dept.I
Nanjing Fujitsu Nanda Software Tech. Co., Ltd.(FNST)

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-12-13  1:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-12  8:54 [PATCH] drivers/staging/irda: fix max dup length for kstrndup Ma Shimiao
2017-12-12 18:27 ` Stephen Hemminger
2017-12-13  1:03   ` Ma Shimiao

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.