net: ipconfig: replace strncpy with strscpy_pad
Subsystems (3)
PATCH 1/1 net: ipconfig: replace strncpy with strscpy_pad
Replace the deprecated strncpy() function with strscpy_pad() as the destination buffer is NUL-terminated and requires trailing NUL-padding
--- net/ipv4/ipconfig.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/ipconfig.c +1 -1
@@ -1690,7 +1690,7 @@ static int __init ic_proto_name(char *name) *v =0 ;if (kstrtou8 (client_id,0 , dhcp_client_identifier))pr_debug ("DHCP: Invalid client identifier type\n" ); -strncpy (dhcp_client_identifier +1 , v +1 ,251 ); +strscpy_pad (dhcp_client_identifier +1 , v +1 ,251 ); *v =',' ; }return 1 ;
Signature · 1 line
2.49.0
Quoted 6 lines · Pranav Tyagi
Replace the deprecated
strncpy()function withstrscpy_pad()as the destination buffer is NUL-terminated and requires trailing NUL-paddingSigned-off-by Pranav Tyagi <[email protected]>
There should be a Fixes tag here, and usually we put the 'net' tree indicator inside the tag, like this: [PATCH net]
Quoted 9 lines
--- net/ipv4/ipconfig.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)net/ipv4/ipconfig.c +0
-0
net/ipv4/ipconfig.c static int __init ic_proto_name(char *name) · line 1693
Quoted 5 lines
net/ipv4/ipconfig.c +1
-1@@ -1690,7 +1690,7 @@ static int __init ic_proto_name(char *name) *v =0 ;if (kstrtou8 (client_id,0 , dhcp_client_identifier))pr_debug ("DHCP: Invalid client identifier type\n" ); -strncpy (dhcp_client_identifier +1 , v +1 ,251 ); +strscpy_pad (dhcp_client_identifier +1 , v +1 ,251 );
The strncpy() action, as well as the memcpy() into dhcp_client_identifier elsewhere, are not padding to the end, so I think this only needs to be null-terminated, not fully padded. If full padding is needed, please let us know why.
sln
Quoted 7 lines
net/ipv4/ipconfig.c +0
-1*v =',' ; }return 1 ; --2.49.0
Quoted 33 lines · Shannon
Quoted 6 lines · Pranav Tyagi
Replace the deprecated
strncpy()function withstrscpy_pad()as the destination buffer is NUL-terminated and requires trailing NUL-paddingSigned-off-by Pranav Tyagi <[email protected]>There should be a Fixes tag here, and usually we put the 'net' tree indicator inside the tag, like this: [PATCH net]
Quoted 9 lines
--- net/ipv4/ipconfig.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)net/ipv4/ipconfig.c +0
-0net/ipv4/ipconfig.c static int __init ic_proto_name(char *name) · line 1693
Quoted 5 lines
net/ipv4/ipconfig.c +1
-1@@ -1690,7 +1690,7 @@ static int __init ic_proto_name(char *name) *v =0 ;if (kstrtou8 (client_id,0 , dhcp_client_identifier))pr_debug ("DHCP: Invalid client identifier type\n" ); -strncpy (dhcp_client_identifier +1 , v +1 ,251 ); +strscpy_pad (dhcp_client_identifier +1 , v +1 ,251 );The
strncpy()action, as well as thememcpy()intodhcp_client_identifierelsewhere, are not padding to the end, so I think this only needs to be null-terminated, not fully padded. If full padding is needed, please let us know why.
Quoted 10 lines
sln
Quoted 7 lines
net/ipv4/ipconfig.c +0
-1*v =',' ; }return 1 ; --2.49.0
My initial assumption was on the fact that dhcp_client_identifier is directly used in DHCP packet construction
and may be parsed byte-wise. But on going through the code again I see that it does not require to be fully padded. Would strscpy() suffice? as it ensures null-termination and does not fully pad the buffer.
Regards
Pranav Tyagi
Quoted 46 lines · Pranav Tyagi
Quoted 33 lines · Shannon
Quoted 6 lines · Pranav Tyagi
Replace the deprecated
strncpy()function withstrscpy_pad()as the destination buffer is NUL-terminated and requires trailing NUL-paddingSigned-off-by Pranav Tyagi <[email protected]>There should be a Fixes tag here, and usually we put the 'net' tree indicator inside the tag, like this: [PATCH net]
Quoted 9 lines
--- net/ipv4/ipconfig.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)net/ipv4/ipconfig.c +0
-0net/ipv4/ipconfig.c static int __init ic_proto_name(char *name) · line 1693
Quoted 5 lines
net/ipv4/ipconfig.c +1
-1@@ -1690,7 +1690,7 @@ static int __init ic_proto_name(char *name) *v =0 ;if (kstrtou8 (client_id,0 , dhcp_client_identifier))pr_debug ("DHCP: Invalid client identifier type\n" ); -strncpy (dhcp_client_identifier +1 , v +1 ,251 ); +strscpy_pad (dhcp_client_identifier +1 , v +1 ,251 );The
strncpy()action, as well as thememcpy()intodhcp_client_identifierelsewhere, are not padding to the end, so I think this only needs to be null-terminated, not fully padded. If full padding is needed, please let us know why.Quoted 10 lines
sln
Quoted 7 lines
net/ipv4/ipconfig.c +0
-1*v =',' ; }return 1 ; --2.49.0
Quoted 6 lines
My initial assumption was on the fact that
dhcp_client_identifieris directly used in DHCP packet construction
and may be parsed byte-wise. But on going through the code again I see that it does not require to be fully padded. Wouldstrscpy()suffice? as it ensures null-termination and does not fully pad the buffer.
Yes, strscpy() should work.
sln
Quoted 3 lines
Regards
Pranav Tyagi
Simon Horman
reviewerQuoted 10 lines · Shannon
Quoted 6 lines · Pranav Tyagi
Replace the deprecated
strncpy()function withstrscpy_pad()as the destination buffer is NUL-terminated and requires trailing NUL-paddingSigned-off-by Pranav Tyagi <[email protected]>There should be a Fixes tag here, and usually we put the 'net' tree indicator inside the tag, like this: [PATCH net]
FWIIW, this feels more line net-next material to me:
I'm not seeing a bug that is being fixed.
Quoted 32 lines
Quoted 11 lines
--- net/ipv4/ipconfig.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)net/ipv4/ipconfig.c +0
-0net/ipv4/ipconfig.c static int __init ic_proto_name(char *name) · line 1693
Quoted 5 lines
net/ipv4/ipconfig.c +1
-1@@ -1690,7 +1690,7 @@ static int __init ic_proto_name(char *name) *v =0 ;if (kstrtou8 (client_id,0 , dhcp_client_identifier))pr_debug ("DHCP: Invalid client identifier type\n" ); -strncpy (dhcp_client_identifier +1 , v +1 ,251 ); +strscpy_pad (dhcp_client_identifier +1 , v +1 ,251 );The
strncpy()action, as well as thememcpy()intodhcp_client_identifierelsewhere, are not padding to the end, so I think this only needs to be null-terminated, not fully padded. If full padding is needed, please let us know why.sln
Quoted 7 lines
net/ipv4/ipconfig.c +0
-1*v =',' ; }return 1 ; --2.49.0