Skip to content

Commit 8477ca1

Browse files
committed
Fix a potential buffer overflow in cupsFormEncode.
1 parent 2fc21e2 commit 8477ca1

2 files changed

Lines changed: 19 additions & 4 deletions

File tree

CHANGES.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
Changes in libcups
22
==================
33

4+
v3.0.3 - YYYY-MM-DD
5+
-------------------
6+
7+
- Fixed a potential buffer overflow in `cupsFormEncode`.
8+
9+
410
v3.0.2 - 2026-06-05
511
-------------------
612

cups/form.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// Form API functions for CUPS.
33
//
4-
// Copyright © 2023-2025 by OpenPrinting.
4+
// Copyright © 2023-2026 by OpenPrinting.
55
// Copyright © 2017-2022 by Michael R Sweet
66
//
77
// Licensed under Apache License v2.0. See the file "LICENSE" for more
@@ -297,12 +297,18 @@ encode_string(const char *s, // I - String to encode
297297
if (*s == ' ')
298298
{
299299
// Space is encoded as '+'
300-
*bufptr++ = '+';
300+
if (bufptr < bufend)
301+
*bufptr++ = '+';
302+
else
303+
bufptr ++;
301304
}
302305
else if (*s == '\n')
303306
{
304307
// Newline is encoded as percent-encoded CR & LF
305-
*bufptr++ = '%';
308+
if (bufptr < bufend)
309+
*bufptr++ = '%';
310+
else
311+
bufptr ++;
306312
if (bufptr < bufend)
307313
*bufptr++ = '0';
308314
else
@@ -327,7 +333,10 @@ encode_string(const char *s, // I - String to encode
327333
else if (!isalnum(*s & 255))
328334
{
329335
// Characters other than letters and numbers get percent-encoded
330-
*bufptr++ = '%';
336+
if (bufptr < bufend)
337+
*bufptr++ = '%';
338+
else
339+
bufptr ++;
331340
if (bufptr < bufend)
332341
*bufptr++ = hex[(*s >> 4) & 15];
333342
else

0 commit comments

Comments
 (0)