From 960402d8a4c86e0690805d08a9234d62a335662e Mon Sep 17 00:00:00 2001 From: melifaro Date: Sat, 18 May 2013 04:49:00 +0000 Subject: Fix ipfw(8) sets of ipv6 addresses handling. Conditionally use stack buffer instead of calling strdup(). PR: bin/104921 MFC after: 2 weeks --- sbin/ipfw/ipfw2.c | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) (limited to 'sbin/ipfw') diff --git a/sbin/ipfw/ipfw2.c b/sbin/ipfw/ipfw2.c index 5b37995..577d644 100644 --- a/sbin/ipfw/ipfw2.c +++ b/sbin/ipfw/ipfw2.c @@ -2779,13 +2779,19 @@ static ipfw_insn * add_src(ipfw_insn *cmd, char *av, u_char proto, int cblen) { struct in6_addr a; - char *host, *ch; + char *host, *ch, buf[INET6_ADDRSTRLEN]; ipfw_insn *ret = NULL; - - if ((host = strdup(av)) == NULL) - return NULL; - if ((ch = strrchr(host, '/')) != NULL) - *ch = '\0'; + int len; + + /* Copy first address in set if needed */ + if ((ch = strpbrk(av, "/,")) != NULL) { + len = ch - av; + strlcpy(buf, av, sizeof(buf)); + if (len < sizeof(buf)) + buf[len] = '\0'; + host = buf; + } else + host = av; if (proto == IPPROTO_IPV6 || strcmp(av, "me6") == 0 || inet_pton(AF_INET6, host, &a) == 1) @@ -2797,7 +2803,6 @@ add_src(ipfw_insn *cmd, char *av, u_char proto, int cblen) if (ret == NULL && strcmp(av, "any") != 0) ret = cmd; - free(host); return ret; } @@ -2805,13 +2810,19 @@ static ipfw_insn * add_dst(ipfw_insn *cmd, char *av, u_char proto, int cblen) { struct in6_addr a; - char *host, *ch; + char *host, *ch, buf[INET6_ADDRSTRLEN]; ipfw_insn *ret = NULL; - - if ((host = strdup(av)) == NULL) - return NULL; - if ((ch = strrchr(host, '/')) != NULL) - *ch = '\0'; + int len; + + /* Copy first address in set if needed */ + if ((ch = strpbrk(av, "/,")) != NULL) { + len = ch - av; + strlcpy(buf, av, sizeof(buf)); + if (len < sizeof(buf)) + buf[len] = '\0'; + host = buf; + } else + host = av; if (proto == IPPROTO_IPV6 || strcmp(av, "me6") == 0 || inet_pton(AF_INET6, host, &a) == 1) @@ -2823,7 +2834,6 @@ add_dst(ipfw_insn *cmd, char *av, u_char proto, int cblen) if (ret == NULL && strcmp(av, "any") != 0) ret = cmd; - free(host); return ret; } -- cgit v1.1 From fd85b64785483b1b7165ece977583df11da022aa Mon Sep 17 00:00:00 2001 From: se Date: Wed, 24 Jul 2013 08:36:29 +0000 Subject: Remove duplicated parapgraph. MFC after: 3 days --- sbin/ipfw/ipfw.8 | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'sbin/ipfw') diff --git a/sbin/ipfw/ipfw.8 b/sbin/ipfw/ipfw.8 index 2047385..65fa334 100644 --- a/sbin/ipfw/ipfw.8 +++ b/sbin/ipfw/ipfw.8 @@ -3049,16 +3049,6 @@ option could be used to (re)mark user traffic, by adding the following to the appropriate place in ruleset: .Pp .Dl "ipfw add setdscp be ip from any to any dscp af11,af21" -.Pp -This rule drops all incoming packets that appear to be coming from another -directly connected system but on the wrong interface. -For example, a packet with a source address of -.Li 192.168.0.0/24 , -configured on -.Li fxp0 , -but coming in on -.Li fxp1 -would be dropped. .Ss DYNAMIC RULES In order to protect a site from flood attacks involving fake TCP packets, it is safer to use dynamic rules: -- cgit v1.1