From 6ba9105f880db5b69386fc6258e41641147fd313 Mon Sep 17 00:00:00 2001 From: Hauke Mehrtens Date: Wed, 19 Dec 2018 10:34:08 +0100 Subject: [PATCH] options: redirects: Fix possible buffer overflows This fixes two possible situations where strncpy() produces a not null terminated buffer. Coverity IDs: * 1412247 Buffer not null terminated * 1412279 Buffer not null terminated Signed-off-by: Hauke Mehrtens Acked-by: Jo-Philipp Wich --- options.c | 2 +- redirects.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/options.c b/options.c index 5184346..c763d9e 100644 --- a/options.c +++ b/options.c @@ -939,7 +939,7 @@ fw3_parse_setmatch(void *ptr, const char *val, bool is_list) return false; } - strncpy(m->name, p, sizeof(m->name)); + strncpy(m->name, p, sizeof(m->name) - 1); for (i = 0, p = strtok(NULL, " \t,"); i < 3 && p != NULL; diff --git a/redirects.c b/redirects.c index ab95395..97529ee 100644 --- a/redirects.c +++ b/redirects.c @@ -154,7 +154,7 @@ resolve_dest(struct uci_element *e, struct fw3_redirect *redir, if (!compare_addr(addr, &redir->ip_redir)) continue; - strncpy(redir->dest.name, zone->name, sizeof(redir->dest.name)); + strncpy(redir->dest.name, zone->name, sizeof(redir->dest.name) - 1); redir->dest.set = true; redir->_dest = zone; -- 2.25.1