/*
- * "$Id$"
- *
* SNMP functions for CUPS.
*
- * Copyright 2007-2014 by Apple Inc.
- * Copyright 2006-2007 by Easy Software Products, all rights reserved.
- *
- * These coded instructions, statements, and computer programs are the
- * property of Apple Inc. and are protected by Federal copyright
- * law. Distribution and use rights are outlined in the file "LICENSE.txt"
- * "LICENSE" which should have been included with this file. If this
- * file is missing or damaged, see the license at "http://www.cups.org/".
+ * Copyright © 2007-2019 by Apple Inc.
+ * Copyright © 2006-2007 by Easy Software Products, all rights reserved.
*
- * This file is subject to the Apple OS-Developed Software exception.
+ * Licensed under Apache License v2.0. See the file "LICENSE" for more
+ * information.
*/
/*
#include "cups-private.h"
#include "snmp-private.h"
+#include "debug-internal.h"
#ifdef HAVE_POLL
# include <poll.h>
#endif /* HAVE_POLL */
{
linenum = 0;
while (cupsFileGetConf(fp, line, sizeof(line), &value, &linenum))
- if (!_cups_strcasecmp(line, "Community") && value)
+ if (!_cups_strcasecmp(line, "Community"))
{
- strlcpy(cg->snmp_community, value, sizeof(cg->snmp_community));
+ if (value)
+ strlcpy(cg->snmp_community, value, sizeof(cg->snmp_community));
+ else
+ cg->snmp_community[0] = '\0';
+
break;
}
ready = select(fd + 1, &input_set, NULL, NULL, &stimeout);
}
-# ifdef WIN32
+# ifdef _WIN32
while (ready < 0 && WSAGetLastError() == WSAEINTR);
# else
while (ready < 0 && (errno == EINTR || errno == EAGAIN));
-# endif /* WIN32 */
+# endif /* _WIN32 */
#endif /* HAVE_POLL */
/*
_cups_globals_t *cg = _cupsGlobals(); /* Global data */
+#ifdef __clang_analyzer__ /* Suppress bogus clang error */
+ memset(string, 0, sizeof(string));
+#endif /* __clang_analyzer__ */
+
if (cg->snmp_debug <= 0)
return;
memcpy(bufptr, packet->community, commlen);
bufptr += commlen;
- *bufptr++ = packet->request_type; /* Get-Request-PDU/Get-Next-Request-PDU */
+ *bufptr++ = (unsigned char)packet->request_type; /* Get-Request-PDU/Get-Next-Request-PDU */
asn1_set_length(&bufptr, reqlen);
asn1_set_integer(&bufptr, (int)packet->request_id);
int value; /* Integer value */
+ if (*buffer >= bufend)
+ return (0);
+
if (length > sizeof(int))
{
(*buffer) += length;
return (0);
}
- for (value = (**buffer & 0x80) ? -1 : 0;
+ for (value = (**buffer & 0x80) ? ~0 : 0;
length > 0 && *buffer < bufend;
length --, (*buffer) ++)
- value = (value << 8) | **buffer;
+ value = ((value & 0xffffff) << 8) | **buffer;
return (value);
}
unsigned length; /* Length */
+ if (*buffer >= bufend)
+ return (0);
+
length = **buffer;
(*buffer) ++;
int number; /* OID number */
+ if (*buffer >= bufend)
+ return (0);
+
valend = *buffer + length;
oidptr = oid;
oidend = oid + oidsize - 1;
int value; /* Value */
+ if (*buffer >= bufend)
+ return (0);
+
value = 0;
- while ((**buffer & 128) && *buffer < bufend)
+ while (*buffer < bufend && (**buffer & 128))
{
value = (value << 7) | (**buffer & 127);
(*buffer) ++;
char *string, /* I - String buffer */
size_t strsize) /* I - String buffer size */
{
+ if (*buffer >= bufend)
+ return (NULL);
+
if (length > (unsigned)(bufend - *buffer))
length = (unsigned)(bufend - *buffer);
int type; /* Type */
+ if (*buffer >= bufend)
+ return (0);
+
type = **buffer;
(*buffer) ++;
/*
- * 'asn1_size_oid()' - Figure out the numebr of bytes needed for an
+ * 'asn1_size_oid()' - Figure out the number of bytes needed for an
* OID value.
*/
packet->error = _cupsLangString(cg->lang_default, message);
}
-
-
-/*
- * End of "$Id$".
- */