summaryrefslogtreecommitdiff
path: root/usr.sbin/ospf6d
diff options
context:
space:
mode:
authorEric Faurot <eric@cvs.openbsd.org>2009-06-07 00:40:47 +0000
committerEric Faurot <eric@cvs.openbsd.org>2009-06-07 00:40:47 +0000
commit48a4c3e0f435992a493206f7aec2aa9e1d87c1cf (patch)
tree2285683d3172095dd9bdcb62aaefa3c867629a2d /usr.sbin/ospf6d
parent280187fee5cc89cfa6891138ee383f9619ae336b (diff)
Make the imsg protocol network-safe.
ok pyr@
Diffstat (limited to 'usr.sbin/ospf6d')
-rw-r--r--usr.sbin/ospf6d/imsg.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/usr.sbin/ospf6d/imsg.c b/usr.sbin/ospf6d/imsg.c
index 9a550c1cfe0..88e022c6bfc 100644
--- a/usr.sbin/ospf6d/imsg.c
+++ b/usr.sbin/ospf6d/imsg.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: imsg.c,v 1.3 2009/06/06 22:11:25 eric Exp $ */
+/* $OpenBSD: imsg.c,v 1.4 2009/06/07 00:40:46 eric Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -105,8 +105,12 @@ imsg_get(struct imsgbuf *ibuf, struct imsg *imsg)
errno = ERANGE;
return (-1);
}
- if (imsg->hdr.len > av)
+ if ((imsg->hdr.len = ntohs(imsg->hdr.len)) > av)
return (0);
+ imsg->hdr.type = ntohl(imsg->hdr.type);
+ imsg->hdr.flags = ntohs(imsg->hdr.flags);
+ imsg->hdr.peerid = ntohl(imsg->hdr.peerid);
+ imsg->hdr.pid = ntohl(imsg->hdr.pid);
datalen = imsg->hdr.len - IMSG_HEADER_SIZE;
ibuf->r.rptr = ibuf->r.buf + IMSG_HEADER_SIZE;
if ((imsg->data = malloc(datalen)) == NULL) {
@@ -212,7 +216,11 @@ imsg_close(struct imsgbuf *ibuf, struct buf *msg)
struct imsg_hdr *hdr;
hdr = (struct imsg_hdr *)msg->buf;
- hdr->len = (u_int16_t)msg->wpos;
+ hdr->type = htonl(hdr->type);
+ hdr->len = htons(msg->wpos);
+ hdr->flags = htons(hdr->flags);
+ hdr->peerid = htonl(hdr->peerid);
+ hdr->pid = htonl(hdr->pid);
buf_close(&ibuf->w, msg);
}