diff options
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/ospfd/auth.c | 12 | ||||
-rw-r--r-- | usr.sbin/ospfd/buffer.c | 12 | ||||
-rw-r--r-- | usr.sbin/ospfd/imsg.c | 14 | ||||
-rw-r--r-- | usr.sbin/ospfd/ospfd.h | 5 | ||||
-rw-r--r-- | usr.sbin/ospfd/ospfe.c | 14 |
5 files changed, 35 insertions, 22 deletions
diff --git a/usr.sbin/ospfd/auth.c b/usr.sbin/ospfd/auth.c index cbb439ea43b..4e92a50b029 100644 --- a/usr.sbin/ospfd/auth.c +++ b/usr.sbin/ospfd/auth.c @@ -1,4 +1,4 @@ -/* $OpenBSD: auth.c,v 1.14 2008/07/24 18:46:59 claudio Exp $ */ +/* $OpenBSD: auth.c,v 1.15 2009/03/04 12:51:01 claudio Exp $ */ /* * Copyright (c) 2004, 2005 Esben Norby <norby@openbsd.org> @@ -148,18 +148,18 @@ auth_gen(struct buf *buf, struct iface *iface) fatalx("auth_gen: buf_seek failed"); /* update length */ - if (buf->wpos > USHRT_MAX) + if (buf_size(buf) > USHRT_MAX) fatalx("auth_gen: resulting ospf packet too big"); - ospf_hdr->len = htons((u_int16_t)buf->wpos); + ospf_hdr->len = htons(buf_size(buf)); /* clear auth_key field */ bzero(ospf_hdr->auth_key.simple, sizeof(ospf_hdr->auth_key.simple)); switch (iface->auth_type) { case AUTH_NONE: - ospf_hdr->chksum = in_cksum(buf->buf, buf->wpos); + ospf_hdr->chksum = in_cksum(buf->buf, buf_size(buf)); break; case AUTH_SIMPLE: - ospf_hdr->chksum = in_cksum(buf->buf, buf->wpos); + ospf_hdr->chksum = in_cksum(buf->buf, buf_size(buf)); strncpy(ospf_hdr->auth_key.simple, iface->auth_key, sizeof(ospf_hdr->auth_key.simple)); @@ -184,7 +184,7 @@ auth_gen(struct buf *buf, struct iface *iface) /* calculate MD5 digest */ MD5Init(&hash); - MD5Update(&hash, buf->buf, buf->wpos); + MD5Update(&hash, buf->buf, buf_size(buf)); MD5Update(&hash, digest, MD5_DIGEST_LENGTH); MD5Final(digest, &hash); diff --git a/usr.sbin/ospfd/buffer.c b/usr.sbin/ospfd/buffer.c index 87890529185..c6e6aff7459 100644 --- a/usr.sbin/ospfd/buffer.c +++ b/usr.sbin/ospfd/buffer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: buffer.c,v 1.10 2009/01/31 11:44:49 claudio Exp $ */ +/* $OpenBSD: buffer.c,v 1.11 2009/03/04 12:51:01 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -86,7 +86,7 @@ buf_realloc(struct buf *buf, size_t len) } int -buf_add(struct buf *buf, void *data, size_t len) +buf_add(struct buf *buf, const void *data, size_t len) { if (buf->wpos + len > buf->size) if (buf_realloc(buf, len) == -1) @@ -122,6 +122,12 @@ buf_seek(struct buf *buf, size_t pos, size_t len) } size_t +buf_size(struct buf *buf) +{ + return (buf->wpos); +} + +size_t buf_left(struct buf *buf) { return (buf->max - buf->wpos); @@ -130,6 +136,8 @@ buf_left(struct buf *buf) int buf_close(struct msgbuf *msgbuf, struct buf *buf) { + /* truncate buffer to the correct length before queuing */ + buf->size = buf->wpos; buf_enqueue(msgbuf, buf); return (1); } diff --git a/usr.sbin/ospfd/imsg.c b/usr.sbin/ospfd/imsg.c index 9bd6cabd33f..ef14fb8d088 100644 --- a/usr.sbin/ospfd/imsg.c +++ b/usr.sbin/ospfd/imsg.c @@ -1,4 +1,4 @@ -/* $OpenBSD: imsg.c,v 1.9 2007/07/24 16:46:09 pyr Exp $ */ +/* $OpenBSD: imsg.c,v 1.10 2009/03/04 12:51:01 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -159,19 +159,23 @@ imsg_add(struct buf *msg, void *data, u_int16_t datalen) int imsg_close(struct imsgbuf *ibuf, struct buf *msg) { - int n; struct imsg_hdr *hdr; hdr = (struct imsg_hdr *)msg->buf; - hdr->len = (u_int16_t)msg->wpos; - if ((n = buf_close(&ibuf->w, msg)) < 0) { + if (msg->size != msg->wpos) { + log_warnx("imsg_close: buffer is not correctly filled"); + buf_free(msg); + return (-1); + } + hdr->len = (u_int16_t)msg->size; + if (buf_close(&ibuf->w, msg) < 0) { log_warnx("imsg_close: buf_close error"); buf_free(msg); return (-1); } imsg_event_add(ibuf); - return (n); + return (0); } void diff --git a/usr.sbin/ospfd/ospfd.h b/usr.sbin/ospfd/ospfd.h index b164d1d674f..397c94a76b0 100644 --- a/usr.sbin/ospfd/ospfd.h +++ b/usr.sbin/ospfd/ospfd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ospfd.h,v 1.75 2009/01/31 11:44:49 claudio Exp $ */ +/* $OpenBSD: ospfd.h,v 1.76 2009/03/04 12:51:01 claudio Exp $ */ /* * Copyright (c) 2004 Esben Norby <norby@openbsd.org> @@ -558,9 +558,10 @@ u_int8_t area_ospf_options(struct area *); /* buffer.c */ struct buf *buf_open(size_t); struct buf *buf_dynamic(size_t, size_t); -int buf_add(struct buf *, void *, size_t); +int buf_add(struct buf *, const void *, size_t); void *buf_reserve(struct buf *, size_t); void *buf_seek(struct buf *, size_t, size_t); +size_t buf_size(struct buf *); size_t buf_left(struct buf *); int buf_close(struct msgbuf *, struct buf *); void buf_free(struct buf *); diff --git a/usr.sbin/ospfd/ospfe.c b/usr.sbin/ospfd/ospfe.c index 05ce44f2679..80e37e6ba42 100644 --- a/usr.sbin/ospfd/ospfe.c +++ b/usr.sbin/ospfd/ospfe.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ospfe.c,v 1.62 2009/01/07 21:16:36 claudio Exp $ */ +/* $OpenBSD: ospfe.c,v 1.63 2009/03/04 12:51:01 claudio Exp $ */ /* * Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org> @@ -955,17 +955,17 @@ orig_rtr_lsa(struct area *area) lsa_hdr.ls_id = oeconf->rtr_id.s_addr; lsa_hdr.adv_rtr = oeconf->rtr_id.s_addr; lsa_hdr.seq_num = htonl(INIT_SEQ_NUM); - lsa_hdr.len = htons(buf->wpos); + lsa_hdr.len = htons(buf_size(buf)); lsa_hdr.ls_chksum = 0; /* updated later */ memcpy(buf_seek(buf, 0, sizeof(lsa_hdr)), &lsa_hdr, sizeof(lsa_hdr)); - chksum = htons(iso_cksum(buf->buf, buf->wpos, LS_CKSUM_OFFSET)); + chksum = htons(iso_cksum(buf->buf, buf_size(buf), LS_CKSUM_OFFSET)); memcpy(buf_seek(buf, LS_CKSUM_OFFSET, sizeof(chksum)), &chksum, sizeof(chksum)); if (self) imsg_compose(ibuf_rde, IMSG_LS_UPD, self->peerid, 0, - buf->buf, buf->wpos); + buf->buf, buf_size(buf)); else log_warnx("orig_rtr_lsa: empty area %s", inet_ntoa(area->id)); @@ -1019,16 +1019,16 @@ orig_net_lsa(struct iface *iface) lsa_hdr.ls_id = iface->addr.s_addr; lsa_hdr.adv_rtr = oeconf->rtr_id.s_addr; lsa_hdr.seq_num = htonl(INIT_SEQ_NUM); - lsa_hdr.len = htons(buf->wpos); + lsa_hdr.len = htons(buf_size(buf)); lsa_hdr.ls_chksum = 0; /* updated later */ memcpy(buf_seek(buf, 0, sizeof(lsa_hdr)), &lsa_hdr, sizeof(lsa_hdr)); - chksum = htons(iso_cksum(buf->buf, buf->wpos, LS_CKSUM_OFFSET)); + chksum = htons(iso_cksum(buf->buf, buf_size(buf), LS_CKSUM_OFFSET)); memcpy(buf_seek(buf, LS_CKSUM_OFFSET, sizeof(chksum)), &chksum, sizeof(chksum)); imsg_compose(ibuf_rde, IMSG_LS_UPD, iface->self->peerid, 0, - buf->buf, buf->wpos); + buf->buf, buf_size(buf)); buf_free(buf); } |