From: Florian Westphal Date: Sun, 20 May 2018 21:56:32 +0000 (+0200) Subject: xtables-compat: ebtables: prefer snprintf to strncpy X-Git-Tag: v1.8.0~50 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=14ec9984811a1c5d39010ebbd3ff171fd8f51652;p=thirdparty%2Fiptables.git xtables-compat: ebtables: prefer snprintf to strncpy gcc emits these warnings: xtables-eb-translate.c:185:2: warning: ‘strncpy’ specified bound 29 equals destination size [-Wstringop-truncation] strncpy(target->t->u.user.name, jumpto, sizeof(target->t->u.user.name)); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Signed-off-by: Florian Westphal --- diff --git a/iptables/xtables-eb-translate.c b/iptables/xtables-eb-translate.c index e54415a2..d274151a 100644 --- a/iptables/xtables-eb-translate.c +++ b/iptables/xtables-eb-translate.c @@ -182,7 +182,8 @@ static struct xtables_target *command_jump(struct iptables_command_state *cs, target->t = xtables_calloc(1, size); target->t->u.target_size = size; - strncpy(target->t->u.user.name, jumpto, sizeof(target->t->u.user.name)); + snprintf(target->t->u.user.name, + sizeof(target->t->u.user.name), "%s", jumpto); target->t->u.user.name[sizeof(target->t->u.user.name)-1] = '\0'; target->t->u.user.revision = target->revision; diff --git a/iptables/xtables-eb.c b/iptables/xtables-eb.c index ba26aca1..8708bea3 100644 --- a/iptables/xtables-eb.c +++ b/iptables/xtables-eb.c @@ -397,7 +397,8 @@ static struct xtables_target *command_jump(struct iptables_command_state *cs, target->t = xtables_calloc(1, size); target->t->u.target_size = size; - strncpy(target->t->u.user.name, jumpto, sizeof(target->t->u.user.name)); + snprintf(target->t->u.user.name, + sizeof(target->t->u.user.name), "%s", jumpto); target->t->u.user.name[sizeof(target->t->u.user.name)-1] = '\0'; target->t->u.user.revision = target->revision; @@ -637,8 +638,8 @@ static void __ebt_load_watcher(const char *name, const char *typename) watcher->t = xtables_calloc(1, size); watcher->t->u.target_size = size; - strncpy(watcher->t->u.user.name, name, - sizeof(watcher->t->u.user.name)); + snprintf(watcher->t->u.user.name, + sizeof(watcher->t->u.user.name), "%s", name); watcher->t->u.user.name[sizeof(watcher->t->u.user.name)-1] = '\0'; watcher->t->u.user.revision = watcher->revision;