netfilter: xtables: refactor deprecated strncpy
authorJustin Stitt <justinstitt@google.com>
Wed, 9 Aug 2023 01:06:10 +0000 (01:06 +0000)
committerFlorian Westphal <fw@strlen.de>
Tue, 22 Aug 2023 13:13:21 +0000 (15:13 +0200)
Prefer `strscpy_pad` as it's a more robust interface whilst maintaing
zero-padding behavior.

There may have existed a bug here due to both `tbl->repl.name` and
`info->name` having a size of 32 as defined below:
|  #define XT_TABLE_MAXNAMELEN 32

This may lead to buffer overreads in some situations -- `strscpy` solves
this by guaranteeing NUL-termination of the dest buffer.

Signed-off-by: Justin Stitt <justinstitt@google.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
net/netfilter/xt_repldata.h

index 68ccbe5..5d1fb70 100644 (file)
@@ -29,7 +29,7 @@
        if (tbl == NULL) \
                return NULL; \
        term = (struct type##_error *)&(((char *)tbl)[term_offset]); \
-       strncpy(tbl->repl.name, info->name, sizeof(tbl->repl.name)); \
+       strscpy_pad(tbl->repl.name, info->name, sizeof(tbl->repl.name)); \
        *term = (struct type##_error)typ2##_ERROR_INIT;  \
        tbl->repl.valid_hooks = hook_mask; \
        tbl->repl.num_entries = nhooks + 1; \