Skip to content

Commit b7c2525

Browse files
committed
Limit num_bytes for SNMP string values.
1 parent c05d32b commit b7c2525

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

cups/snmp-private.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* Private SNMP definitions for CUPS.
33
*
4-
* Copyright © 2020-2024 by OpenPrinting.
4+
* Copyright © 2020-2026 by OpenPrinting.
55
* Copyright © 2007-2014 by Apple Inc.
66
* Copyright © 2006-2007 by Easy Software Products, all rights reserved.
77
*
@@ -58,9 +58,9 @@ typedef enum cups_asn1_e cups_asn1_t; /**** ASN1 request/object types ****/
5858

5959
typedef struct cups_snmp_string_s /**** String value ****/
6060
{
61-
unsigned char bytes[CUPS_SNMP_MAX_STRING];
62-
/* Bytes in string */
6361
unsigned num_bytes; /* Number of bytes */
62+
unsigned char bytes[CUPS_SNMP_MAX_STRING + 1];
63+
/* Bytes in string */
6464
} cups_snmp_string_t;
6565

6666
union cups_snmp_value_u /**** Object value ****/

cups/snmp.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* SNMP functions for CUPS.
33
*
4-
* Copyright © 2020-2024 by OpenPrinting.
4+
* Copyright © 2020-2026 by OpenPrinting.
55
* Copyright © 2007-2019 by Apple Inc.
66
* Copyright © 2006-2007 by Easy Software Products, all rights reserved.
77
*
@@ -1042,10 +1042,14 @@ asn1_decode_snmp(unsigned char *buffer, /* I - Buffer */
10421042
case CUPS_ASN1_OCTET_STRING :
10431043
case CUPS_ASN1_BIT_STRING :
10441044
case CUPS_ASN1_HEX_STRING :
1045-
packet->object_value.string.num_bytes = length;
10461045
asn1_get_string(&bufptr, bufend, length,
10471046
(char *)packet->object_value.string.bytes,
10481047
sizeof(packet->object_value.string.bytes));
1048+
1049+
if (length >= sizeof(packet->object_value.string.bytes))
1050+
packet->object_value.string.num_bytes = sizeof(packet->object_value.string.bytes) - 1;
1051+
else
1052+
packet->object_value.string.num_bytes = length;
10491053
break;
10501054

10511055
case CUPS_ASN1_OID :

0 commit comments

Comments
 (0)