linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* strscpy() vs strlcpy() and WARN_ONCE()
@ 2018-12-13 12:37 Hans Petter Selasky
  2019-01-25 13:01 ` [PATCH] strscpy() returns a negative value on failure unlike strlcpy() Hans Petter Selasky
  0 siblings, 1 reply; 2+ messages in thread
From: Hans Petter Selasky @ 2018-12-13 12:37 UTC (permalink / raw)
  To: linux-media, Mauro Carvalho Chehab

> commit c0decac19da3906d9b66291e57b7759489e1170f
> Author: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
> Date:   Mon Sep 10 08:19:14 2018 -0400
> 
>     media: use strscpy() instead of strlcpy()
>     
>     The implementation of strscpy() is more robust and safer.
>     
>     That's now the recommended way to copy NUL terminated strings.
>     
>     Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
>     Reviewed-by: Kees Cook <keescook@chromium.org>
>     Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
>     Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>

Hi Mauro,

The following piece of the commit above I believe is wrong:

>         if (descr)
> -               WARN_ON(strlcpy(fmt->description, descr, sz) >= sz);
> +               WARN_ON(strscpy(fmt->description, descr, sz) >= sz);
>         fmt->flags = flags;

It should be:
		WARN_ON(strscpy(fmt->description, descr, sz) < 0);

I don't have time to make a full patch for this so please handle this 
issue for me. Thank you!

--HPS

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

* [PATCH] strscpy() returns a negative value on failure unlike strlcpy().
  2018-12-13 12:37 strscpy() vs strlcpy() and WARN_ONCE() Hans Petter Selasky
@ 2019-01-25 13:01 ` Hans Petter Selasky
  0 siblings, 0 replies; 2+ messages in thread
From: Hans Petter Selasky @ 2019-01-25 13:01 UTC (permalink / raw)
  To: linux-media, Mauro Carvalho Chehab

[-- Attachment #1: Type: text/plain, Size: 6 bytes --]

--HPS

[-- Attachment #2: 0001-strscpy-returns-a-negative-value-on-failure-unlike-s.patch --]
[-- Type: text/x-patch, Size: 846 bytes --]

From dbdd6c5833103880337e23d56d08f44741589a19 Mon Sep 17 00:00:00 2001
From: Hans Petter Selasky <hps@selasky.org>
Date: Fri, 25 Jan 2019 13:59:01 +0100
Subject: [PATCH] strscpy() returns a negative value on failure unlike
 strlcpy().

Signed-off-by: Hans Petter Selasky <hps@selasky.org>
---
 drivers/media/v4l2-core/v4l2-ioctl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
index c63746968fa3..5cf2d5d91999 100644
--- a/drivers/media/v4l2-core/v4l2-ioctl.c
+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
@@ -1354,7 +1354,7 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)
 	}
 
 	if (descr)
-		WARN_ON(strscpy(fmt->description, descr, sz) >= sz);
+		WARN_ON(strscpy(fmt->description, descr, sz) < 0);
 	fmt->flags = flags;
 }
 
-- 
2.20.1


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

end of thread, other threads:[~2019-01-25 13:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-13 12:37 strscpy() vs strlcpy() and WARN_ONCE() Hans Petter Selasky
2019-01-25 13:01 ` [PATCH] strscpy() returns a negative value on failure unlike strlcpy() Hans Petter Selasky

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).