linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] unicode: replace strncpy() by strscpy()
@ 2019-05-27 17:47 Gustavo A. R. Silva
  2019-05-28 17:47 ` Gabriel Krisman Bertazi
  0 siblings, 1 reply; 2+ messages in thread
From: Gustavo A. R. Silva @ 2019-05-27 17:47 UTC (permalink / raw)
  To: Gabriel Krisman Bertazi; +Cc: linux-fsdevel, linux-kernel, Gustavo A. R. Silva

The strncpy() function is being deprecated. Replace it by the safer
strscpy() and fix the following Coverity warning:

"Calling strncpy with a maximum size argument of 12 bytes on destination
array version_string of size 12 bytes might leave the destination string
unterminated."

Notice that, unlike strncpy(), strscpy() always null-terminates the
destination string.

Addresses-Coverity-ID: 1445547 ("Buffer not null terminated")
Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
---
 fs/unicode/utf8-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/unicode/utf8-core.c b/fs/unicode/utf8-core.c
index 6afab4fdce90..a367041468cf 100644
--- a/fs/unicode/utf8-core.c
+++ b/fs/unicode/utf8-core.c
@@ -131,7 +131,7 @@ static int utf8_parse_version(const char *version, unsigned int *maj,
 		{0, NULL}
 	};
 
-	strncpy(version_string, version, sizeof(version_string));
+	strscpy(version_string, version, sizeof(version_string));
 
 	if (match_token(version_string, token, args) != 1)
 		return -EINVAL;
-- 
2.21.0


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

* Re: [PATCH] unicode: replace strncpy() by strscpy()
  2019-05-27 17:47 [PATCH] unicode: replace strncpy() by strscpy() Gustavo A. R. Silva
@ 2019-05-28 17:47 ` Gabriel Krisman Bertazi
  0 siblings, 0 replies; 2+ messages in thread
From: Gabriel Krisman Bertazi @ 2019-05-28 17:47 UTC (permalink / raw)
  To: Gustavo A. R. Silva; +Cc: linux-fsdevel, linux-kernel

"Gustavo A. R. Silva" <gustavo@embeddedor.com> writes:

> The strncpy() function is being deprecated. Replace it by the safer
> strscpy() and fix the following Coverity warning:
>
> "Calling strncpy with a maximum size argument of 12 bytes on destination
> array version_string of size 12 bytes might leave the destination string
> unterminated."
>
> Notice that, unlike strncpy(), strscpy() always null-terminates the
> destination string.
>

Thanks, I'll get this queued up.

-- 
Gabriel Krisman Bertazi

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

end of thread, other threads:[~2019-05-28 17:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-27 17:47 [PATCH] unicode: replace strncpy() by strscpy() Gustavo A. R. Silva
2019-05-28 17:47 ` Gabriel Krisman Bertazi

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