diff options
author | Claudio Jeker <claudio@cvs.openbsd.org> | 2009-03-04 12:51:02 +0000 |
---|---|---|
committer | Claudio Jeker <claudio@cvs.openbsd.org> | 2009-03-04 12:51:02 +0000 |
commit | 808ab77c4d1ef4ffe604bbeff6bf30fd5d916f1d (patch) | |
tree | 3cc80ba3370922e37cfebd86527d7e1b4bdec08b /usr.sbin/ospfd/imsg.c | |
parent | d090ded1bfaa31f95eceb0f8322a68ff29694131 (diff) |
Introduce and use buf_size(buf) instead of buf->wpos -- at least in the non
buf/imsg specific code. buf_close() will no force a truncation of the buffer
to the wpos but actually add code in imsg.c to detect and report such silly
behaviour. Makes the buf API a bit more sane.
Diffstat (limited to 'usr.sbin/ospfd/imsg.c')
-rw-r--r-- | usr.sbin/ospfd/imsg.c | 14 |
1 files changed, 9 insertions, 5 deletions
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 |