diff mbox series

[iptables,9/9] extensions: libxt_string: Avoid buffer size warning for strncpy()

Message ID 20210602152403.5689-10-phil@nwl.cc
State Accepted
Delegated to: Pablo Neira
Headers show
Series Fix a bunch of static analyzer warnings | expand

Commit Message

Phil Sutter June 2, 2021, 3:24 p.m. UTC
If the target buffer does not need to be null-terminated, one may simply
use memcpy() and thereby avoid any compiler warnings.

Signed-off-by: Phil Sutter <phil@nwl.cc>
---
 extensions/libxt_string.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/extensions/libxt_string.c b/extensions/libxt_string.c
index 7c6366cbbf1b3..739a8e7fd66b6 100644
--- a/extensions/libxt_string.c
+++ b/extensions/libxt_string.c
@@ -81,7 +81,7 @@  parse_string(const char *s, struct xt_string_info *info)
 {	
 	/* xt_string does not need \0 at the end of the pattern */
 	if (strlen(s) <= XT_STRING_MAX_PATTERN_SIZE) {
-		strncpy(info->pattern, s, XT_STRING_MAX_PATTERN_SIZE);
+		memcpy(info->pattern, s, XT_STRING_MAX_PATTERN_SIZE);
 		info->patlen = strnlen(s, XT_STRING_MAX_PATTERN_SIZE);
 		return;
 	}