Skip to content

Commit d7fe0f5

Browse files
committed
Limit num_bytes for SNMP string values.
1 parent 4ac17a8 commit d7fe0f5

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
//
@@ -55,9 +55,9 @@ typedef enum cups_asn1_e cups_asn1_t; // ASN1 request/object types
5555

5656
typedef struct cups_snmp_string_s // String value
5757
{
58-
unsigned char bytes[CUPS_SNMP_MAX_STRING];
59-
// Bytes in string
6058
unsigned num_bytes; // Number of bytes
59+
unsigned char bytes[CUPS_SNMP_MAX_STRING + 1];
60+
// Bytes in string
6161
} cups_snmp_string_t;
6262

6363
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
*
@@ -1014,10 +1014,14 @@ asn1_decode_snmp(unsigned char *buffer, /* I - Buffer */
10141014
case CUPS_ASN1_OCTET_STRING :
10151015
case CUPS_ASN1_BIT_STRING :
10161016
case CUPS_ASN1_HEX_STRING :
1017-
packet->object_value.string.num_bytes = length;
10181017
asn1_get_string(&bufptr, bufend, length,
10191018
(char *)packet->object_value.string.bytes,
10201019
sizeof(packet->object_value.string.bytes));
1020+
1021+
if (length >= sizeof(packet->object_value.string.bytes))
1022+
packet->object_value.string.num_bytes = sizeof(packet->object_value.string.bytes) - 1;
1023+
else
1024+
packet->object_value.string.num_bytes = length;
10211025
break;
10221026

10231027
case CUPS_ASN1_OID :

0 commit comments

Comments
 (0)