diff options
author | Claudio Jeker <claudio@cvs.openbsd.org> | 2005-02-09 14:39:57 +0000 |
---|---|---|
committer | Claudio Jeker <claudio@cvs.openbsd.org> | 2005-02-09 14:39:57 +0000 |
commit | c00e19926dc4090180b78588335af1b8433aead4 (patch) | |
tree | 41cb651db11969c8d570b10a4578bc5095f54f4f /usr.sbin/ospfd | |
parent | 8b5afed2325e826f9df13061f49c84349c0f7b8f (diff) |
Add buf_seek() as buf_reserve() fails if a buf_add()/buf_reserve() is
called afterwards as it may realloc() the buffer and so the returned
pointer is bogus. Needed by the upcomming originate LSA code.
OK henning@
Diffstat (limited to 'usr.sbin/ospfd')
-rw-r--r-- | usr.sbin/ospfd/buffer.c | 12 | ||||
-rw-r--r-- | usr.sbin/ospfd/ospfd.h | 3 |
2 files changed, 13 insertions, 2 deletions
diff --git a/usr.sbin/ospfd/buffer.c b/usr.sbin/ospfd/buffer.c index 42d160499ed..41693565a10 100644 --- a/usr.sbin/ospfd/buffer.c +++ b/usr.sbin/ospfd/buffer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: buffer.c,v 1.2 2005/02/01 21:25:18 claudio Exp $ */ +/* $OpenBSD: buffer.c,v 1.3 2005/02/09 14:39:56 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -111,6 +111,16 @@ buf_reserve(struct buf *buf, size_t len) return (b); } +void * +buf_seek(struct buf *buf, size_t pos, size_t len) +{ + /* only allowed to seek in already written parts */ + if (pos + len > buf->wpos) + return (NULL); + + return (buf->buf + pos); +} + int buf_close(struct msgbuf *msgbuf, struct buf *buf) { diff --git a/usr.sbin/ospfd/ospfd.h b/usr.sbin/ospfd/ospfd.h index 6d954ad2442..78e114c50ab 100644 --- a/usr.sbin/ospfd/ospfd.h +++ b/usr.sbin/ospfd/ospfd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ospfd.h,v 1.5 2005/02/07 05:51:00 david Exp $ */ +/* $OpenBSD: ospfd.h,v 1.6 2005/02/09 14:39:56 claudio Exp $ */ /* * Copyright (c) 2004 Esben Norby <norby@openbsd.org> @@ -367,6 +367,7 @@ struct buf *buf_open(size_t); struct buf *buf_dynamic(size_t, size_t); int buf_add(struct buf *, void *, size_t); void *buf_reserve(struct buf *, size_t); +void *buf_seek(struct buf *, size_t, size_t); int buf_close(struct msgbuf *, struct buf *); int buf_write(int, struct buf *); void buf_free(struct buf *); |