]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
xtables-compat: ebtables: prefer snprintf to strncpy
authorFlorian Westphal <fw@strlen.de>
Sun, 20 May 2018 21:56:32 +0000 (23:56 +0200)
committerFlorian Westphal <fw@strlen.de>
Sun, 20 May 2018 21:56:32 +0000 (23:56 +0200)
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 <fw@strlen.de>
iptables/xtables-eb-translate.c
iptables/xtables-eb.c

index e54415a2f1ed10d0681d9d285a2420356d016d33..d274151a0c64ff9ffd3d2242411233517cbef867 100644 (file)
@@ -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;
 
index ba26aca1018285856ae9846a43a239dc97f5244f..8708bea37306a53abfab777d9e6ca7da08f8a16e 100644 (file)
@@ -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;