diff options
author | 2020-08-08 07:18:08 +0000 | |
---|---|---|
committer | 2020-08-08 07:18:08 +0000 | |
commit | 27b4df320243160b10e31e089e51b1a3bd58b391 (patch) | |
tree | bb3d33a72c8ee975003224891be74d64d0e3cff3 | |
parent | Document UTF-8 support in snmp. (diff) | |
download | wireguard-openbsd-27b4df320243160b10e31e089e51b1a3bd58b391.tar.xz wireguard-openbsd-27b4df320243160b10e31e089e51b1a3bd58b391.zip |
Somewhere during working on UTF-8 support I thought it was a good idea to
use sysContact as a testcase, because it's readily available in snmpd, but
forgetting it's actual textual convention as time went by, which is
DisplayString (which is ASCII).
Add support for the DisplayString textual convention, which is similar to
having no textual convention, except that invalid bytes (value 128 and up)
are printed as UTF-8 replacement characters, or question mark, depending on
LC_CTYPE.
Feedback and OK schwarze@
-rw-r--r-- | usr.bin/snmp/mib.h | 5 | ||||
-rw-r--r-- | usr.bin/snmp/smi.c | 26 |
2 files changed, 16 insertions, 15 deletions
diff --git a/usr.bin/snmp/mib.h b/usr.bin/snmp/mib.h index f9921f4ab9b..ea68d8a63ee 100644 --- a/usr.bin/snmp/mib.h +++ b/usr.bin/snmp/mib.h @@ -1,4 +1,4 @@ -/* $OpenBSD: mib.h,v 1.2 2020/08/03 14:45:54 martijn Exp $ */ +/* $OpenBSD: mib.h,v 1.3 2020/08/08 07:18:08 martijn Exp $ */ /* * Copyright (c) 2007, 2008 Reyk Floeter <reyk@openbsd.org> @@ -751,7 +751,7 @@ { MIBDECL(sysDescr) }, \ { MIBDECL(sysOID) }, \ { MIBDECL(sysUpTime) }, \ - { MIBDECL(sysContact), "SnmpAdminString" }, \ + { MIBDECL(sysContact), "DisplayString" }, \ { MIBDECL(sysName) }, \ { MIBDECL(sysLocation) }, \ { MIBDECL(sysServices) }, \ @@ -1349,6 +1349,7 @@ #define TEXTCONV_TREE { \ { "SnmpAdminString", "255t", BER_TYPE_OCTETSTRING }, \ + { "DisplayString", "255a", BER_TYPE_OCTETSTRING }, \ { NULL, NULL } \ } diff --git a/usr.bin/snmp/smi.c b/usr.bin/snmp/smi.c index f4392b85420..70f5448f011 100644 --- a/usr.bin/snmp/smi.c +++ b/usr.bin/snmp/smi.c @@ -1,4 +1,4 @@ -/* $OpenBSD: smi.c,v 1.10 2020/08/03 14:45:54 martijn Exp $ */ +/* $OpenBSD: smi.c,v 1.11 2020/08/08 07:18:08 martijn Exp $ */ /* * Copyright (c) 2019 Martijn van Duren <martijn@openbsd.org> @@ -642,12 +642,17 @@ smi_displayhint_os(struct textconv *tc, int print_hint, const char *src, size_t srclen, int utf8) { size_t octetlength, i = 0, j = 0; + size_t prefixlen; unsigned long ulval; int clen; char *displayformat; + const char *prefix; char *rbuf, *dst; wchar_t wc; + prefix = print_hint ? "STRING: " : ""; + prefixlen = strlen(prefix); + errno = 0; ulval = strtoul(tc->tc_display_hint, &displayformat, 10); octetlength = ulval; @@ -658,20 +663,15 @@ smi_displayhint_os(struct textconv *tc, int print_hint, const char *src, return NULL; } - if (displayformat[0] == 't') { - if (print_hint) { - rbuf = malloc(octetlength + sizeof("STRING: ")); - if (rbuf == NULL) - return NULL; - memcpy(rbuf, "STRING: ", sizeof("STRING: ") - 1); - dst = rbuf + sizeof("STRING: ") - 1; - } else { - dst = rbuf = malloc(octetlength + 1); - if (rbuf == NULL) - return NULL; - } + if (displayformat[0] == 't' || displayformat[0] == 'a') { + if ((rbuf = malloc(prefixlen + octetlength + 1)) == NULL) + return NULL; + (void)strlcpy(rbuf, prefix, prefixlen + octetlength + 1); + dst = rbuf + prefixlen; while (j < octetlength && i < srclen) { clen = mbtowc(&wc, &(src[i]), srclen - i); + if (displayformat[0] == 'a' && clen > 1) + clen = -1; switch (clen) { case 0: dst[j++] = '.'; |