Skip to content

Commit

Permalink
snmp-ups: Fix detection and display of hex strings
Browse files Browse the repository at this point in the history
Signed-off-by: Arnaud Quette <[email protected]>
  • Loading branch information
aquette committed Jan 17, 2019
1 parent 36db37d commit ce3103f
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions drivers/snmp-ups.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* Copyright (C)
* 2002 - 2014 Arnaud Quette <[email protected]>
* 2015 - 2018 Eaton (author: Arnaud Quette <[email protected]>)
* 2015 - 2019 Eaton (author: Arnaud Quette <[email protected]>)
* 2017 Eaton (author: Jim Klimov <[email protected]>)
* 2002 - 2006 Dmitry Frolov <[email protected]>
* J.W. Hoogervorst <[email protected]>
Expand Down Expand Up @@ -126,7 +126,7 @@ const char *mibname;
const char *mibvers;

#define DRIVER_NAME "Generic SNMP UPS driver"
#define DRIVER_VERSION "1.05"
#define DRIVER_VERSION "1.06"

/* driver description structure */
upsdrv_info_t upsdrv_info = {
Expand Down Expand Up @@ -774,15 +774,20 @@ static bool_t decode_str(struct snmp_pdu *pdu, char *buf, size_t buf_len, info_l
case ASN_OPAQUE:
len = pdu->variables->val_len > buf_len - 1 ?
buf_len - 1 : pdu->variables->val_len;
if (len > 0) {
/* Test for hexadecimal values */
if (!isprint(pdu->variables->val.string[0]))
snprint_hexstring(buf, buf_len, pdu->variables->val.string, pdu->variables->val_len);
else {
memcpy(buf, pdu->variables->val.string, len);
buf[len] = '\0';
/* Test for hexadecimal values */
int hex = 0, x;
char *cp;
for(cp = pdu->variables->val.string, x = 0; x < (int)pdu->variables->val_len; x++, cp++) {
if (!(isprint(*cp) || isspace(*cp))) {
hex = 1;
}
}
if (hex)
snprint_hexstring(buf, buf_len, pdu->variables->val.string, pdu->variables->val_len);
else {
memcpy(buf, pdu->variables->val.string, len);
buf[len] = '\0';
}
break;
case ASN_INTEGER:
case ASN_COUNTER:
Expand Down

0 comments on commit ce3103f

Please sign in to comment.