Message ID | 20191121111559.27066-3-phil@nwl.cc |
---|---|
State | Accepted |
Delegated to: | Pablo Neira |
Headers | show |
Series | Some minor fixes | expand |
On Thu, Nov 21, 2019 at 12:15:58PM +0100, Phil Sutter wrote: > Gcc complains about the size being equal to destination size, despite > the nul character being explicitly set in following line. > > Reduce size by one to make gcc happy. While being at it, drop the > explicit nul character assignment - it is not needed as the buffer was > allocated by calloc(). > > Fixes: 8f586939999e0 ("fix potential buffer overflows reported by static analysis") > Signed-off-by: Phil Sutter <phil@nwl.cc> Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
diff --git a/arptables.c b/arptables.c index 09c9ca25217d0..2b6618c2511ef 100644 --- a/arptables.c +++ b/arptables.c @@ -2065,8 +2065,7 @@ int do_command(int argc, char *argv[], char **table, arptc_handle_t *handle) target->t = fw_calloc(1, size); target->t->u.target_size = size; - strncpy(target->t->u.user.name, jumpto, sizeof(target->t->u.user.name)); - target->t->u.user.name[sizeof(target->t->u.user.name)-1] = '\0'; + strncpy(target->t->u.user.name, jumpto, sizeof(target->t->u.user.name) - 1); target->t->u.user.revision = target->revision; /* target->init(target->t, &fw.nfcache);
Gcc complains about the size being equal to destination size, despite the nul character being explicitly set in following line. Reduce size by one to make gcc happy. While being at it, drop the explicit nul character assignment - it is not needed as the buffer was allocated by calloc(). Fixes: 8f586939999e0 ("fix potential buffer overflows reported by static analysis") Signed-off-by: Phil Sutter <phil@nwl.cc> --- arptables.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)