Date: Wed, 16 Jan 2013 08:22:45 +0000 (UTC) From: Lawrence Stewart <lstewart@FreeBSD.org> To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r245501 - projects/diffused_head/sbin/ipfw/diffuse_collector Message-ID: <201301160822.r0G8Mj0n048132@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: lstewart Date: Wed Jan 16 08:22:45 2013 New Revision: 245501 URL: http://svnweb.freebsd.org/changeset/base/245501 Log: Mitigate against possible unaligned accesses when parsing data off the wire. More work to remove other possible unaligned accesses still to come. Reported by: clang Modified: projects/diffused_head/sbin/ipfw/diffuse_collector/diffuse_collector.c Modified: projects/diffused_head/sbin/ipfw/diffuse_collector/diffuse_collector.c ============================================================================== --- projects/diffused_head/sbin/ipfw/diffuse_collector/diffuse_collector.c Wed Jan 16 08:04:55 2013 (r245500) +++ projects/diffused_head/sbin/ipfw/diffuse_collector/diffuse_collector.c Wed Jan 16 08:22:45 2013 (r245501) @@ -889,8 +889,7 @@ parse_rule(struct class_node *cnode, str c->cname[DI_MAX_NAME_STR_LEN - 1] = '\0'; offs += strlen(c->cname) + 1; - c->class = - ntohs(*((uint16_t *)(rb + offs))); + c->class = be16toh(be16dec(rb + offs)); offs += sizeof(uint16_t); SLIST_INSERT_HEAD(&n->flow_classes, c, next); @@ -903,33 +902,33 @@ parse_rule(struct class_node *cnode, str } else { switch(t->fields[i].id) { case DIP_IE_SRC_IPV4: - n->id.src_ip = *((uint32_t *)(rb + offs)); + n->id.src_ip = be32dec(rb + offs); n->id.addr_type = 4; break; case DIP_IE_DST_IPV4: - n->id.dst_ip = *((uint32_t *)(rb + offs)); + n->id.dst_ip = be32dec(rb + offs); n->id.addr_type = 4; break; case DIP_IE_SRC_PORT: - n->id.src_port = ntohs(*((uint16_t *)(rb + offs))); + n->id.src_port = be16toh(be16dec(rb + offs)); break; case DIP_IE_DST_PORT: - n->id.dst_port = ntohs(*((uint16_t *)(rb + offs))); + n->id.dst_port = be16toh(be16dec(rb + offs)); break; case DIP_IE_PROTO: - n->id.proto = *((uint8_t *)(rb + offs)); + n->id.proto = *(rb + offs); break; case DIP_IE_TIMEOUT_TYPE: - n->expire_type = *((uint8_t *)(rb + offs)); + n->expire_type = *(rb + offs); break; case DIP_IE_TIMEOUT: - n->expire = ntohs(*((uint16_t *)(rb + offs))); + n->expire = be16toh(be16dec(rb + offs)); break; case DIP_IE_EXPORT_NAME: @@ -945,7 +944,7 @@ parse_rule(struct class_node *cnode, str break; case DIP_IE_ACTION_FLAGS: - n->rtype = ntohs(*((uint16_t *)(rb + offs))); + n->rtype = be16toh(be16dec(rb + offs)); break; case DIP_IE_ACTION_PARAMS: @@ -955,7 +954,7 @@ parse_rule(struct class_node *cnode, str break; case DIP_IE_MSG_TYPE: - type = *((uint8_t *)(rb + offs)); + type = *(rb + offs); break; } @@ -1081,8 +1080,8 @@ parse_msg(struct class_node *cnode, char while (offs - toffs < ntohs(shdr->set_len) - sizeof(struct dip_set_header) - sizeof(struct dip_templ_header)) { - r->fields[r->fcnt].id = ntohs( - *((uint16_t *)(buf + offs))); + r->fields[r->fcnt].id = + be16toh(be16dec(buf + offs)); offs += sizeof(uint16_t); info = diffuse_proto_get_info( r->fields[r->fcnt].id); @@ -1090,8 +1089,7 @@ parse_msg(struct class_node *cnode, char r->fields[r->fcnt].len = info.len; if (r->fields[r->fcnt].len == 0) { r->fields[r->fcnt].len = - ntohs(*((uint16_t *)(buf + - offs))); + be16toh(be16dec(buf + offs)); offs += sizeof(uint16_t); } r->fcnt++;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201301160822.r0G8Mj0n048132>