Skip to content

Commit 51fb4c8

Browse files
committed
Update processing of LimitRequestBody, MaxLogSize, and MaxRequestSize to support full range of file sizes (Issue #1540)
1 parent e9ddf7b commit 51fb4c8

File tree

3 files changed

+58
-29
lines changed

3 files changed

+58
-29
lines changed

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ Changes in CUPS v2.4.17 (YYYY-MM-DD)
3939
- Fixed a bug in cgiCheckVariables.
4040
- Fixed a debug printf bug on Windows (Issue #1529)
4141
- Fixed a recursion issue with encoding of nested collections (Issue #1539)
42+
- Fixed parsing of the `LimitRequestBody`, `MaxLogSize`, and `MaxRequestSize`
43+
directives in "cupsd.conf" (Issue #1540)
4244

4345

4446
Changes in CUPS v2.4.16 (2025-12-04)

scheduler/conf.c

Lines changed: 52 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
typedef enum
4747
{
4848
CUPSD_VARTYPE_INTEGER, /* Integer option */
49+
CUPSD_VARTYPE_SIZE, /* Size option */
4950
CUPSD_VARTYPE_TIME, /* Time interval option */
5051
CUPSD_VARTYPE_NULLSTRING, /* String option or NULL/empty string */
5152
CUPSD_VARTYPE_STRING, /* String option */
@@ -101,7 +102,7 @@ static const cupsd_var_t cupsd_vars[] =
101102
#ifdef HAVE_LAUNCHD
102103
{ "LaunchdTimeout", &IdleExitTimeout, CUPSD_VARTYPE_TIME },
103104
#endif /* HAVE_LAUNCHD */
104-
{ "LimitRequestBody", &MaxRequestSize, CUPSD_VARTYPE_INTEGER },
105+
{ "LimitRequestBody", &MaxRequestSize, CUPSD_VARTYPE_SIZE },
105106
{ "LogDebugHistory", &LogDebugHistory, CUPSD_VARTYPE_INTEGER },
106107
{ "MaxActiveJobs", &MaxActiveJobs, CUPSD_VARTYPE_INTEGER },
107108
{ "MaxClients", &MaxClients, CUPSD_VARTYPE_INTEGER },
@@ -114,8 +115,8 @@ static const cupsd_var_t cupsd_vars[] =
114115
{ "MaxJobsPerUser", &MaxJobsPerUser, CUPSD_VARTYPE_INTEGER },
115116
{ "MaxJobTime", &MaxJobTime, CUPSD_VARTYPE_TIME },
116117
{ "MaxLeaseDuration", &MaxLeaseDuration, CUPSD_VARTYPE_TIME },
117-
{ "MaxLogSize", &MaxLogSize, CUPSD_VARTYPE_INTEGER },
118-
{ "MaxRequestSize", &MaxRequestSize, CUPSD_VARTYPE_INTEGER },
118+
{ "MaxLogSize", &MaxLogSize, CUPSD_VARTYPE_SIZE },
119+
{ "MaxRequestSize", &MaxRequestSize, CUPSD_VARTYPE_SIZE },
119120
{ "MaxSubscriptions", &MaxSubscriptions, CUPSD_VARTYPE_INTEGER },
120121
{ "MaxSubscriptionsPerJob", &MaxSubscriptionsPerJob, CUPSD_VARTYPE_INTEGER },
121122
{ "MaxSubscriptionsPerPrinter",&MaxSubscriptionsPerPrinter, CUPSD_VARTYPE_INTEGER },
@@ -2725,54 +2726,80 @@ parse_variable(
27252726
case CUPSD_VARTYPE_INTEGER :
27262727
if (!value)
27272728
{
2728-
cupsdLogMessage(CUPSD_LOG_ERROR,
2729-
"Missing integer value for %s on line %d of %s.",
2730-
line, linenum, filename);
2729+
cupsdLogMessage(CUPSD_LOG_ERROR, "Missing integer value for %s on line %d of %s.", line, linenum, filename);
27312730
return (0);
27322731
}
27332732
else if (!isdigit(*value & 255))
27342733
{
2735-
cupsdLogMessage(CUPSD_LOG_ERROR,
2736-
"Bad integer value for %s on line %d of %s.",
2737-
line, linenum, filename);
2734+
cupsdLogMessage(CUPSD_LOG_ERROR, "Bad integer value for %s on line %d of %s.", line, linenum, filename);
2735+
return (0);
2736+
}
2737+
else
2738+
{
2739+
long n; /* Number */
2740+
char *ptr; /* Remaining text */
2741+
2742+
n = strtol(value, &ptr, 0);
2743+
2744+
if (n < 0 || n > INT_MAX || (ptr && *ptr))
2745+
{
2746+
cupsdLogMessage(CUPSD_LOG_ERROR, "Bad integer value for %s on line %d of %s.", line, linenum, filename);
2747+
return (0);
2748+
}
2749+
else
2750+
{
2751+
*((int *)var->ptr) = (int)n;
2752+
}
2753+
}
2754+
break;
2755+
2756+
case CUPSD_VARTYPE_SIZE :
2757+
if (!value)
2758+
{
2759+
cupsdLogMessage(CUPSD_LOG_ERROR, "Missing size value for %s on line %d of %s.", line, linenum, filename);
2760+
return (0);
2761+
}
2762+
else if (!isdigit(*value & 255))
2763+
{
2764+
cupsdLogMessage(CUPSD_LOG_ERROR, "Bad size value for %s on line %d of %s.", line, linenum, filename);
27382765
return (0);
27392766
}
27402767
else
27412768
{
2742-
int n; /* Number */
2743-
char *units; /* Units */
2769+
double n; /* Number */
2770+
char *units; /* Units */
27442771

2745-
n = (int)strtol(value, &units, 0);
2772+
n = _cupsStrScand(value, &units, localeconv());
27462773

27472774
if (units && *units)
27482775
{
27492776
if (tolower(units[0] & 255) == 'g')
2750-
n *= 1024 * 1024 * 1024;
2777+
{
2778+
n *= 1024.0 * 1024.0 * 1024.0;
2779+
}
27512780
else if (tolower(units[0] & 255) == 'm')
2752-
n *= 1024 * 1024;
2781+
{
2782+
n *= 1024.0 * 1024.0;
2783+
}
27532784
else if (tolower(units[0] & 255) == 'k')
2754-
n *= 1024;
2755-
else if (tolower(units[0] & 255) == 't')
2756-
n *= 262144;
2785+
{
2786+
n *= 1024.0;
2787+
}
27572788
else
27582789
{
2759-
cupsdLogMessage(CUPSD_LOG_ERROR,
2760-
"Unknown integer value for %s on line %d of %s.",
2761-
line, linenum, filename);
2790+
cupsdLogMessage(CUPSD_LOG_ERROR, "Unknown size units for %s on line %d of %s.", line, linenum, filename);
27622791
return (0);
27632792
}
27642793
}
27652794

2766-
if (n < 0)
2795+
if (n < 0 || n > (double)OFF_MAX)
27672796
{
2768-
cupsdLogMessage(CUPSD_LOG_ERROR,
2769-
"Bad negative integer value for %s on line %d of "
2770-
"%s.", line, linenum, filename);
2797+
cupsdLogMessage(CUPSD_LOG_ERROR, "Bad size value for %s on line %d of %s.", line, linenum, filename);
27712798
return (0);
27722799
}
27732800
else
27742801
{
2775-
*((int *)var->ptr) = n;
2802+
*((off_t *)var->ptr) = (off_t)n;
27762803
}
27772804
}
27782805
break;

scheduler/conf.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,13 +190,13 @@ VAR int MaxClients VALUE(100),
190190
/* Maximum number of clients */
191191
MaxClientsPerHost VALUE(0),
192192
/* Maximum number of clients per host */
193-
MaxCopies VALUE(CUPS_DEFAULT_MAX_COPIES),
193+
MaxCopies VALUE(CUPS_DEFAULT_MAX_COPIES);
194194
/* Maximum number of copies per job */
195-
MaxLogSize VALUE(1024 * 1024),
195+
VAR off_t MaxLogSize VALUE(1024 * 1024),
196196
/* Maximum size of log files */
197-
MaxRequestSize VALUE(0),
197+
MaxRequestSize VALUE(0);
198198
/* Maximum size of IPP requests */
199-
HostNameLookups VALUE(FALSE),
199+
VAR int HostNameLookups VALUE(FALSE),
200200
/* Do we do reverse lookups? */
201201
Timeout VALUE(DEFAULT_TIMEOUT),
202202
/* Timeout during requests */

0 commit comments

Comments
 (0)