Browse Source

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 <hauke@hauke-m.de>
Acked-by: Jo-Philipp Wich <jo@mein.io>
Hauke Mehrtens 5 years ago
parent
commit
6ba9105f88
2 changed files with 2 additions and 2 deletions
  1. 1 1
      options.c
  2. 1 1
      redirects.c

+ 1 - 1
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;

+ 1 - 1
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;