[PATCH net-next] rds: debug: fix null check on static array

Subsystems: networking [general], rds - reliable datagram sockets, the rest

STALE3235d

3 messages, 3 authors, 2017-12-06 · open the first message on its own page

[PATCH net-next] rds: debug: fix null check on static array

From: Prashant Bhole <hidden>
Date: 2017-12-06 01:50:00

t_name cannot be NULL since it is an array field of a struct.
Replacing null check on static array with string length check using
strnlen()

Signed-off-by: Prashant Bhole <redacted>
---
 net/rds/connection.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/net/rds/connection.c b/net/rds/connection.c
index 9efc82c665b5..6492c0b608a4 100644
--- a/net/rds/connection.c
+++ b/net/rds/connection.c
@@ -230,8 +230,8 @@ static struct rds_connection *__rds_conn_create(struct net *net,
 
 	rdsdebug("allocated conn %p for %pI4 -> %pI4 over %s %s\n",
 	  conn, &laddr, &faddr,
-	  trans->t_name ? trans->t_name : "[unknown]",
-	  is_outgoing ? "(outgoing)" : "");
+	  strnlen(trans->t_name, sizeof(trans->t_name)) ? trans->t_name :
+	  "[unknown]", is_outgoing ? "(outgoing)" : "");
 
 	/*
 	 * Since we ran without holding the conn lock, someone could
-- 
2.13.6

Re: [PATCH net-next] rds: debug: fix null check on static array

From: Sowmini Varadhan <hidden>
Date: 2017-12-06 11:32:25

On (12/06/17 10:47), Prashant Bhole wrote:
t_name cannot be NULL since it is an array field of a struct.
Replacing null check on static array with string length check using
strnlen()
t_name is always initialized for all rds transports today,  and would
be all zeros unless someone stomped over that memory (in which case
there could be more serious issues than a busted debug string) but
it's good  to be safe and check I suppose.

Acked-by: Sowmini Varadhan <redacted>

--Sowmini

Re: [PATCH net-next] rds: debug: fix null check on static array

From: Santosh Shilimkar <hidden>
Date: 2017-12-06 16:35:27

On 12/6/2017 3:32 AM, Sowmini Varadhan wrote:
On (12/06/17 10:47), Prashant Bhole wrote:
quoted
t_name cannot be NULL since it is an array field of a struct.
Replacing null check on static array with string length check using
strnlen()
t_name is always initialized for all rds transports today,  and would
be all zeros unless someone stomped over that memory (in which case
there could be more serious issues than a busted debug string) but
it's good  to be safe and check I suppose.
Thanks Sowmini !!

Acked-by: Santosh Shilimkar <redacted>
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help