netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] cxgb4: do conversion after string check
@ 2023-03-30 15:47 Denis Plotnikov
  2023-03-30 19:52 ` Simon Horman
  0 siblings, 1 reply; 2+ messages in thread
From: Denis Plotnikov @ 2023-03-30 15:47 UTC (permalink / raw)
  To: netdev; +Cc: linux-kernel, rajur, davem, edumazet, kuba, pabeni, den-plotnikov

Static code analyzer complains to uncheck return value.
Indeed, the return value of kstrtouint "must be checked"
as the comment says.
Moreover, it looks like the string conversion  should be
after "end of string" or "new line" check.
This patch fixes these issues.

Signed-off-by: Denis Plotnikov <den-plotnikov@yandex-team.ru>
---
 drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.c
index 14e0d989c3ba5..a8d3616630cc6 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.c
+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.c
@@ -1576,9 +1576,11 @@ inval:				count = -EINVAL;
 		}
 		if (*word == '@') {
 			end = (char *)word + 1;
-			ret = kstrtouint(end, 10, &j);
 			if (*end && *end != '\n')
 				goto inval;
+			ret = kstrtouint(end, 10, &j);
+			if (ret)
+				goto inval;
 			if (j & 7)          /* doesn't start at multiple of 8 */
 				goto inval;
 			j /= 8;
-- 
2.25.1


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

* Re: [PATCH] cxgb4: do conversion after string check
  2023-03-30 15:47 [PATCH] cxgb4: do conversion after string check Denis Plotnikov
@ 2023-03-30 19:52 ` Simon Horman
  0 siblings, 0 replies; 2+ messages in thread
From: Simon Horman @ 2023-03-30 19:52 UTC (permalink / raw)
  To: Denis Plotnikov
  Cc: netdev, linux-kernel, rajur, davem, edumazet, kuba, pabeni

On Thu, Mar 30, 2023 at 06:47:03PM +0300, Denis Plotnikov wrote:
> Static code analyzer complains to uncheck return value.
> Indeed, the return value of kstrtouint "must be checked"
> as the comment says.
> Moreover, it looks like the string conversion  should be
> after "end of string" or "new line" check.
> This patch fixes these issues.
> 
> Signed-off-by: Denis Plotnikov <den-plotnikov@yandex-team.ru>
> ---
>  drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.c
> index 14e0d989c3ba5..a8d3616630cc6 100644
> --- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.c
> +++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.c
> @@ -1576,9 +1576,11 @@ inval:				count = -EINVAL;
>  		}
>  		if (*word == '@') {
>  			end = (char *)word + 1;
> -			ret = kstrtouint(end, 10, &j);
>  			if (*end && *end != '\n')
>  				goto inval;

I feel that I must be missing something very obvious.

My reading is that the code only gets to this line
if *end is either '\0' or '\n'. Which would not be the case
if end points to the string representation of number.
So I am confused about this code, both with and without your patch.

Perhaps the check is assuming that end is pointing
to the end of the string representation of the number.
Something like the endptr after a call to libc's strtoul(3).
But by my reading it is pointing to the beginning.

> +			ret = kstrtouint(end, 10, &j);
> +			if (ret)
> +				goto inval;
>  			if (j & 7)          /* doesn't start at multiple of 8 */
>  				goto inval;
>  			j /= 8;
> -- 
> 2.25.1
> 

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

end of thread, other threads:[~2023-03-30 19:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-30 15:47 [PATCH] cxgb4: do conversion after string check Denis Plotnikov
2023-03-30 19:52 ` Simon Horman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).