summaryrefslogtreecommitdiff
path: root/usr.sbin/ntpd/imsg.c
diff options
context:
space:
mode:
authorHenning Brauer <henning@cvs.openbsd.org>2004-09-15 19:21:26 +0000
committerHenning Brauer <henning@cvs.openbsd.org>2004-09-15 19:21:26 +0000
commit078fd8953f1ccce51c0026d3be83e90002feeb5c (patch)
tree6b611c60bb46d4bd21902e3ebd7ccce87d0486b8 /usr.sbin/ntpd/imsg.c
parentcd4ff5e43c31c11a0c2f117b61c9560e773ac5d1 (diff)
imsg framework cleanup:
-kill the _pid flavors of imsg_create and imsg_compose, and just add pid as argument to those -use imsg_create in imsg_compose instead of duplicating code -check for datalen overflow
Diffstat (limited to 'usr.sbin/ntpd/imsg.c')
-rw-r--r--usr.sbin/ntpd/imsg.c70
1 files changed, 16 insertions, 54 deletions
diff --git a/usr.sbin/ntpd/imsg.c b/usr.sbin/ntpd/imsg.c
index 8dfaa893dc4..ef3fd58e906 100644
--- a/usr.sbin/ntpd/imsg.c
+++ b/usr.sbin/ntpd/imsg.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: imsg.c,v 1.1 2004/05/31 13:46:16 henning Exp $ */
+/* $OpenBSD: imsg.c,v 1.2 2004/09/15 19:21:25 henning Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -25,11 +25,6 @@
#include "ntpd.h"
-int imsg_compose_core(struct imsgbuf *, int, u_int32_t, void *,
- u_int16_t, pid_t);
-struct buf *imsg_create_core(struct imsgbuf *, int, u_int32_t, u_int16_t,
- pid_t);
-
void
imsg_init(struct imsgbuf *ibuf, int fd)
{
@@ -97,47 +92,19 @@ imsg_get(struct imsgbuf *ibuf, struct imsg *imsg)
}
int
-imsg_compose(struct imsgbuf *ibuf, int type, u_int32_t peerid, void *data,
- u_int16_t dlen)
-{
- return (imsg_compose_core(ibuf, type, peerid, data, dlen, ibuf->pid));
-}
-
-int
-imsg_compose_pid(struct imsgbuf *ibuf, int type, pid_t pid, void *data,
- u_int16_t datalen)
-{
- return (imsg_compose_core(ibuf, type, 0, data, datalen, pid));
-}
-
-int
-imsg_compose_core(struct imsgbuf *ibuf, int type, u_int32_t peerid, void *data,
- u_int16_t datalen, pid_t pid)
+imsg_compose(struct imsgbuf *ibuf, int type, u_int32_t peerid, pid_t pid,
+ void *data, u_int16_t datalen)
{
struct buf *wbuf;
- struct imsg_hdr hdr;
int n;
- hdr.len = datalen + IMSG_HEADER_SIZE;
- hdr.type = type;
- hdr.peerid = peerid;
- hdr.pid = pid;
- wbuf = buf_open(hdr.len);
- if (wbuf == NULL) {
- log_warn("imsg_compose: buf_open");
+ if ((wbuf = imsg_create(ibuf, type, peerid, datalen, pid)) == NULL)
return (-1);
- }
- if (buf_add(wbuf, &hdr, sizeof(hdr)) == -1) {
- log_warnx("imsg_compose: buf_add error");
- buf_free(wbuf);
+
+ if (imsg_add(wbuf, data, datalen) == -1) {
+ free(wbuf);
return (-1);
}
- if (datalen)
- if (buf_add(wbuf, data, datalen) == -1) {
- log_warnx("imsg_compose: buf_add error");
- buf_free(wbuf);
- return (-1);
- }
if ((n = buf_close(&ibuf->w, wbuf)) < 0) {
log_warnx("imsg_compose: buf_add error");
@@ -148,24 +115,19 @@ imsg_compose_core(struct imsgbuf *ibuf, int type, u_int32_t peerid, void *data,
}
struct buf *
-imsg_create(struct imsgbuf *ibuf, int type, u_int32_t peerid, u_int16_t dlen)
-{
- return (imsg_create_core(ibuf, type, peerid, dlen, ibuf->pid));
-}
-
-struct buf *
-imsg_create_pid(struct imsgbuf *ibuf, int type, pid_t pid, u_int16_t datalen)
-{
- return (imsg_create_core(ibuf, type, 0, datalen, pid));
-}
-
-struct buf *
-imsg_create_core(struct imsgbuf *ibuf, int type, u_int32_t peerid,
- u_int16_t datalen, pid_t pid)
+imsg_create(struct imsgbuf *ibuf, int type, u_int32_t peerid,
+ pid_t pid, u_int16_t datalen)
{
struct buf *wbuf;
struct imsg_hdr hdr;
+ if (datalen > MAX_IMSGSIZE - IMSG_HEADER_SIZE) {
+ log_warnx("imsg_create: len %u > MAX_IMSGSIZE; "
+ "type %u peerid %lu", datalen + IMSG_HEADER_SIZE,
+ type, peerid);
+ return (NULL);
+ }
+
hdr.len = datalen + IMSG_HEADER_SIZE;
hdr.type = type;
hdr.peerid = peerid;