Skip to contentSkip to conversation

drivers/net/wireless/iwlegacy: use strlcpy instead of strncpy

PATCH In review Chen Gang 4 participants 5 messages Jan 7, 2013 – Jan 20, 2013 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore

Chen Gang

author
#0 lore raw

PATCH 1/1 drivers/net/wireless/iwlegacy: use strlcpy instead of strncpy

The fields must be null-terminated, or simple_strtoul will cause issue.

---
 drivers/net/wireless/iwlegacy/3945-mac.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/iwlegacy/3945-mac.c +1 -1
index d604b40..3726cd6 100644
@@ -3273,7 +3273,7 @@ il3945_store_measurement(struct device *d, struct device_attribute *attr,
 
 	if (count) {
 		char *p = buffer;
-		strncpy(buffer, buf, min(sizeof(buffer), count));
+		strlcpy(buffer, buf, sizeof(buffer));
 		channel = simple_strtoul(p, NULL, 0);
 		if (channel)
 			params.channel = channel;
Signature · 1 line
1.7.10.4
#2 lore raw
Quoted 2 lines · Stanislaw Gruszka
Quoted 1 line
Quoted 1 line

ACK

thank you very much.

:-)

Signature · 3 lines
Chen Gang

Flying Transformer

begin:vcard
fn:Chen Gang
n:;Chen Gang
version:2.1
end:vcard

A message that is not in the archive (sent off-list or not yet received): [email protected]

#4 lore raw

Hello all:

sorry, after checking the details:
I think this patch is incorrect.
we can not assume that the parameter "char *buf" is terminated by '\0' so we should only use strlcpy instead of strncpy, without touching 'min(...'

since it is already integrated into main branch (at least, in next-20130118).
I should send additional patch to fix it.

please help to check, thanks.

gchen.

Quoted 22 lines · Chen Gang

The fields must be null-terminated, or simple_strtoul will cause issue.

---
 drivers/net/wireless/iwlegacy/3945-mac.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/iwlegacy/3945-mac.c +1 -1
index d604b40..3726cd6 100644
@@ -3273,7 +3273,7 @@ il3945_store_measurement(struct device *d, struct device_attribute *attr,
 
 	if (count) {
 		char *p = buffer;
-		strncpy(buffer, buf, min(sizeof(buffer), count));
+		strlcpy(buffer, buf, sizeof(buffer));
 		channel = simple_strtoul(p, NULL, 0);
 		if (channel)
 			params.channel = channel;
Signature · 3 lines
Chen Gang

Asianux Corporation
#5 lore raw

oh, sorry, it is my fault.

according to fill_write_buffer in fs/sysfs/file.c,
we can assume that 'const char *buf' must be '\0' based string.

please skip original reply.

gchen.

Quoted 41 lines · Chen Gang

Hello all:

sorry, after checking the details:
I think this patch is incorrect.
we can not assume that the parameter "char *buf" is terminated by '\0' so we should only use strlcpy instead of strncpy, without touching 'min(...'

since it is already integrated into main branch (at least, in next-20130118).
I should send additional patch to fix it.

please help to check, thanks.

gchen.

Quoted 22 lines · Chen Gang

The fields must be null-terminated, or simple_strtoul will cause issue.

---
 drivers/net/wireless/iwlegacy/3945-mac.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/iwlegacy/3945-mac.c +1 -1
index d604b40..3726cd6 100644
@@ -3273,7 +3273,7 @@ il3945_store_measurement(struct device *d, struct device_attribute *attr,
 
 	if (count) {
 		char *p = buffer;
-		strncpy(buffer, buf, min(sizeof(buffer), count));
+		strlcpy(buffer, buf, sizeof(buffer));
 		channel = simple_strtoul(p, NULL, 0);
 		if (channel)
 			params.channel = channel;
Signature · 3 lines
Chen Gang

Flying Transformer

begin:vcard
fn:Chen Gang
n:;Chen Gang
version:2.1
end:vcard