diff options
author | 2018-06-17 18:19:59 +0000 | |
---|---|---|
committer | 2018-06-17 18:19:59 +0000 | |
commit | efeeff7b97b892cc5f525b50a59f30366989ada2 (patch) | |
tree | f3456ae7e097a85be1e3282173606b446512c48c | |
parent | fix memory leaks: freeaddrinfo() the data from getaddrinfo(). (diff) | |
download | wireguard-openbsd-efeeff7b97b892cc5f525b50a59f30366989ada2.tar.xz wireguard-openbsd-efeeff7b97b892cc5f525b50a59f30366989ada2.zip |
Bring snmpd agentx.c closer in line with relayd.
ok benno@, "sure" deraadt@
-rw-r--r-- | usr.sbin/snmpd/agentx.c | 31 | ||||
-rw-r--r-- | usr.sbin/snmpd/control.c | 4 | ||||
-rw-r--r-- | usr.sbin/snmpd/snmp.h | 3 |
3 files changed, 12 insertions, 26 deletions
diff --git a/usr.sbin/snmpd/agentx.c b/usr.sbin/snmpd/agentx.c index d5ca54c55de..a13dcdc3808 100644 --- a/usr.sbin/snmpd/agentx.c +++ b/usr.sbin/snmpd/agentx.c @@ -1,4 +1,4 @@ -/* $OpenBSD: agentx.c,v 1.12 2018/02/14 12:43:07 rob Exp $ */ +/* $OpenBSD: agentx.c,v 1.13 2018/06/17 18:19:59 rob Exp $ */ /* * Copyright (c) 2013,2014 Bret Stephen Lambert <blambert@openbsd.org> * @@ -18,12 +18,8 @@ #include <sys/types.h> #include <sys/socket.h> #include <sys/queue.h> -#include <sys/uio.h> #include <sys/un.h> -#include <arpa/inet.h> - -#include <err.h> #include <errno.h> #include <stdlib.h> #include <stdio.h> @@ -217,9 +213,14 @@ snmp_agentx_response(struct agentx_handle *h, struct agentx_pdu *pdu) { struct agentx_response_data resp; - if (snmp_agentx_read_response(pdu, &resp) == -1) + if (snmp_agentx_read_raw(pdu, &resp, sizeof(resp)) == -1) return (-1); + if (!snmp_agentx_byteorder_native(pdu->hdr)) { + resp.error = snmp_agentx_int16_byteswap(resp.error); + resp.index = snmp_agentx_int16_byteswap(resp.index); + } + h->error = resp.error; if (resp.error != AGENTX_ERR_NONE) return (-1); @@ -227,20 +228,6 @@ snmp_agentx_response(struct agentx_handle *h, struct agentx_pdu *pdu) return (0); } -int -snmp_agentx_read_response(struct agentx_pdu *pdu, struct agentx_response_data *resp) -{ - if (snmp_agentx_read_raw(pdu, resp, sizeof(*resp)) == -1) - return (-1); - - if (!snmp_agentx_byteorder_native(pdu->hdr)) { - resp->error = snmp_agentx_int16_byteswap(resp->error); - resp->index = snmp_agentx_int16_byteswap(resp->index); - } - - return (0); -} - /* * Read the response PDU for an open operation. */ @@ -341,7 +328,7 @@ snmp_agentx_recv(struct agentx_handle *h) if (h->r == NULL) { if ((h->r = snmp_agentx_pdu_alloc()) == NULL) return (NULL); - h->r->datalen = 0; /* XXX -- force this for receive buffers */ + h->r->datalen = 0; /* XXX force this for receive buffers */ } pdu = h->r; @@ -1038,7 +1025,7 @@ snmp_oid2string(struct snmp_oid *o, char *buf, size_t len) bzero(buf, len); for (i = 0; i < o->o_n; i++) { - snprintf(str, sizeof(str), "%d", o->o_id[i]); + snprintf(str, sizeof(str), "%u", o->o_id[i]); strlcat(buf, str, len); if (i < (o->o_n - 1)) strlcat(buf, ".", len); diff --git a/usr.sbin/snmpd/control.c b/usr.sbin/snmpd/control.c index d332bd1f82f..4cbc911ba36 100644 --- a/usr.sbin/snmpd/control.c +++ b/usr.sbin/snmpd/control.c @@ -1,4 +1,4 @@ -/* $OpenBSD: control.c,v 1.42 2017/04/21 13:50:23 jca Exp $ */ +/* $OpenBSD: control.c,v 1.43 2018/06/17 18:19:59 rob Exp $ */ /* * Copyright (c) 2010-2013 Reyk Floeter <reyk@openbsd.org> @@ -537,7 +537,7 @@ control_dispatch_agentx(int fd, short event, void *arg) struct agentx_varbind_hdr vbhdr; struct ber_element **elm, **iter; - if (snmp_agentx_read_response(pdu, &resp) == -1) { + if (snmp_agentx_read_raw(pdu, &resp, sizeof(resp)) == -1) { msg->sm_error = SNMP_ERROR_GENERR; goto dispatch; } diff --git a/usr.sbin/snmpd/snmp.h b/usr.sbin/snmpd/snmp.h index 7b513de8b1a..71261b4f5b5 100644 --- a/usr.sbin/snmpd/snmp.h +++ b/usr.sbin/snmpd/snmp.h @@ -1,4 +1,4 @@ -/* $OpenBSD: snmp.h,v 1.14 2015/06/11 18:49:09 reyk Exp $ */ +/* $OpenBSD: snmp.h,v 1.15 2018/06/17 18:19:59 rob Exp $ */ /* * Copyright (c) 2007, 2008, 2012 Reyk Floeter <reyk@openbsd.org> @@ -369,7 +369,6 @@ struct agentx_handle * struct agentx_handle * snmp_agentx_fdopen(int, char *, struct snmp_oid *); int snmp_agentx_response(struct agentx_handle *, struct agentx_pdu *); -int snmp_agentx_read_response(struct agentx_pdu *, struct agentx_response_data *); int snmp_agentx_open_response(struct agentx_handle *, struct agentx_pdu *); struct agentx_pdu * snmp_agentx_open_pdu(struct agentx_handle *, char *descr, |