Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions cups/sidechannel.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,8 @@ cupsSideChannelSNMPGet(
{
cups_sc_status_t status; /* Status of command */
cups_sc_command_t rcommand; /* Response command */
char *real_data; /* Real data buffer for response */
char *real_data, /* Real data buffer for response */
*real_oidend; /* End of returned OID string */
int real_datalen, /* Real length of data buffer */
real_oidlen; /* Length of returned OID string */

Expand Down Expand Up @@ -319,7 +320,13 @@ cupsSideChannelSNMPGet(
* Parse the response of the form "oid\0value"...
*/

real_oidlen = (int)strlen(real_data) + 1;
if ((real_oidend = memchr(real_data, '\0', (size_t)real_datalen)) == NULL)
{
_cupsBufferRelease(real_data);
return (CUPS_SC_STATUS_BAD_MESSAGE);
}

real_oidlen = (int)(real_oidend - real_data) + 1;
real_datalen -= real_oidlen;

if ((real_datalen + 1) > *datalen)
Expand Down Expand Up @@ -377,7 +384,8 @@ cupsSideChannelSNMPWalk(
{
cups_sc_status_t status; /* Status of command */
cups_sc_command_t rcommand; /* Response command */
char *real_data; /* Real data buffer for response */
char *real_data, /* Real data buffer for response */
*real_oidend; /* End of returned OID string */
int real_datalen; /* Real length of data buffer */
size_t real_oidlen, /* Length of returned OID string */
oidlen; /* Length of first OID */
Expand Down Expand Up @@ -438,8 +446,16 @@ cupsSideChannelSNMPWalk(
* Parse the response of the form "oid\0value"...
*/

if (strncmp(real_data, oid, oidlen) || real_data[oidlen] != '.' ||
!strcmp(real_data, last_oid))
if ((real_oidend = memchr(real_data, '\0', (size_t)real_datalen)) == NULL)
{
_cupsBufferRelease(real_data);
return (CUPS_SC_STATUS_BAD_MESSAGE);
}

real_oidlen = (size_t)(real_oidend - real_data) + 1;

if (real_oidlen <= oidlen || strncmp(real_data, oid, oidlen) ||
real_data[oidlen] != '.' || !strcmp(real_data, last_oid))
{
/*
* Done with this set of OIDs...
Expand All @@ -449,10 +465,6 @@ cupsSideChannelSNMPWalk(
return (CUPS_SC_STATUS_OK);
}

if ((size_t)real_datalen < sizeof(real_data))
real_data[real_datalen] = '\0';

real_oidlen = strlen(real_data) + 1;
real_datalen -= (int)real_oidlen;

/*
Expand Down