Skip to contentSkip to conversation

unicode: replace strncpy() by strscpy()

PATCH In review Gustavo A. R. Silva 2 participants 2 messages May 27, 2019 – May 28, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 unicode: replace strncpy() by strscpy()

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

---
 fs/unicode/utf8-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/unicode/utf8-core.c +1 -1
index 6afab4fdce90..a367041468cf 100644
@@ -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;
Signature · 1 line
2.21.0
#1 lore raw
Quoted 10 lines · 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.

Thanks, I'll get this queued up.

Signature · 1 line
Gabriel Krisman Bertazi