Skip to content

Commit ff8d096

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

File tree

2 files changed

+56
-29
lines changed

2 files changed

+56
-29
lines changed

scheduler/conf.c

Lines changed: 52 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
typedef enum
4444
{
4545
CUPSD_VARTYPE_INTEGER, /* Integer option */
46+
CUPSD_VARTYPE_SIZE, /* Size option */
4647
CUPSD_VARTYPE_TIME, /* Time interval option */
4748
CUPSD_VARTYPE_NULLSTRING, /* String option or NULL/empty string */
4849
CUPSD_VARTYPE_STRING, /* String option */
@@ -94,7 +95,7 @@ static const cupsd_var_t cupsd_vars[] =
9495
#ifdef HAVE_LAUNCHD
9596
{ "LaunchdTimeout", &IdleExitTimeout, CUPSD_VARTYPE_TIME },
9697
#endif /* HAVE_LAUNCHD */
97-
{ "LimitRequestBody", &MaxRequestSize, CUPSD_VARTYPE_INTEGER },
98+
{ "LimitRequestBody", &MaxRequestSize, CUPSD_VARTYPE_SIZE },
9899
{ "LogDebugHistory", &LogDebugHistory, CUPSD_VARTYPE_INTEGER },
99100
{ "MaxActiveJobs", &MaxActiveJobs, CUPSD_VARTYPE_INTEGER },
100101
{ "MaxClients", &MaxClients, CUPSD_VARTYPE_INTEGER },
@@ -107,8 +108,8 @@ static const cupsd_var_t cupsd_vars[] =
107108
{ "MaxJobsPerUser", &MaxJobsPerUser, CUPSD_VARTYPE_INTEGER },
108109
{ "MaxJobTime", &MaxJobTime, CUPSD_VARTYPE_TIME },
109110
{ "MaxLeaseDuration", &MaxLeaseDuration, CUPSD_VARTYPE_TIME },
110-
{ "MaxLogSize", &MaxLogSize, CUPSD_VARTYPE_INTEGER },
111-
{ "MaxRequestSize", &MaxRequestSize, CUPSD_VARTYPE_INTEGER },
111+
{ "MaxLogSize", &MaxLogSize, CUPSD_VARTYPE_SIZE },
112+
{ "MaxRequestSize", &MaxRequestSize, CUPSD_VARTYPE_SIZE },
112113
{ "MaxSubscriptions", &MaxSubscriptions, CUPSD_VARTYPE_INTEGER },
113114
{ "MaxSubscriptionsPerJob", &MaxSubscriptionsPerJob, CUPSD_VARTYPE_INTEGER },
114115
{ "MaxSubscriptionsPerPrinter",&MaxSubscriptionsPerPrinter, CUPSD_VARTYPE_INTEGER },
@@ -2806,54 +2807,80 @@ parse_variable(
28062807
case CUPSD_VARTYPE_INTEGER :
28072808
if (!value)
28082809
{
2809-
cupsdLogMessage(CUPSD_LOG_ERROR,
2810-
"Missing integer value for %s on line %d of %s.",
2811-
line, linenum, filename);
2810+
cupsdLogMessage(CUPSD_LOG_ERROR, "Missing integer value for %s on line %d of %s.", line, linenum, filename);
28122811
return (0);
28132812
}
28142813
else if (!isdigit(*value & 255))
28152814
{
2816-
cupsdLogMessage(CUPSD_LOG_ERROR,
2817-
"Bad integer value for %s on line %d of %s.",
2818-
line, linenum, filename);
2815+
cupsdLogMessage(CUPSD_LOG_ERROR, "Bad integer value for %s on line %d of %s.", line, linenum, filename);
2816+
return (0);
2817+
}
2818+
else
2819+
{
2820+
long n; /* Number */
2821+
char *ptr; /* Remaining text */
2822+
2823+
n = strtol(value, &ptr, 0);
2824+
2825+
if (n < 0 || n > INT_MAX || (ptr && *ptr))
2826+
{
2827+
cupsdLogMessage(CUPSD_LOG_ERROR, "Bad integer value for %s on line %d of %s.", line, linenum, filename);
2828+
return (0);
2829+
}
2830+
else
2831+
{
2832+
*((int *)var->ptr) = (int)n;
2833+
}
2834+
}
2835+
break;
2836+
2837+
case CUPSD_VARTYPE_SIZE :
2838+
if (!value)
2839+
{
2840+
cupsdLogMessage(CUPSD_LOG_ERROR, "Missing size value for %s on line %d of %s.", line, linenum, filename);
2841+
return (0);
2842+
}
2843+
else if (!isdigit(*value & 255))
2844+
{
2845+
cupsdLogMessage(CUPSD_LOG_ERROR, "Bad size value for %s on line %d of %s.", line, linenum, filename);
28192846
return (0);
28202847
}
28212848
else
28222849
{
2823-
int n; /* Number */
2824-
char *units; /* Units */
2850+
double n; /* Number */
2851+
char *units; /* Units */
28252852

2826-
n = (int)strtol(value, &units, 0);
2853+
n = _cupsStrScand(value, &units, localeconv());
28272854

28282855
if (units && *units)
28292856
{
28302857
if (tolower(units[0] & 255) == 'g')
2831-
n *= 1024 * 1024 * 1024;
2858+
{
2859+
n *= 1024.0 * 1024.0 * 1024.0;
2860+
}
28322861
else if (tolower(units[0] & 255) == 'm')
2833-
n *= 1024 * 1024;
2862+
{
2863+
n *= 1024.0 * 1024.0;
2864+
}
28342865
else if (tolower(units[0] & 255) == 'k')
2835-
n *= 1024;
2836-
else if (tolower(units[0] & 255) == 't')
2837-
n *= 262144;
2866+
{
2867+
n *= 1024.0;
2868+
}
28382869
else
28392870
{
2840-
cupsdLogMessage(CUPSD_LOG_ERROR,
2841-
"Unknown integer value for %s on line %d of %s.",
2842-
line, linenum, filename);
2871+
cupsdLogMessage(CUPSD_LOG_ERROR, "Unknown size units for %s on line %d of %s.", line, linenum, filename);
28432872
return (0);
28442873
}
28452874
}
28462875

2847-
if (n < 0)
2876+
if (n < 0 || n > (double)OFF_MAX)
28482877
{
2849-
cupsdLogMessage(CUPSD_LOG_ERROR,
2850-
"Bad negative integer value for %s on line %d of "
2851-
"%s.", line, linenum, filename);
2878+
cupsdLogMessage(CUPSD_LOG_ERROR, "Bad size value for %s on line %d of %s.", line, linenum, filename);
28522879
return (0);
28532880
}
28542881
else
28552882
{
2856-
*((int *)var->ptr) = n;
2883+
*((off_t *)var->ptr) = (off_t)n;
28572884
}
28582885
}
28592886
break;

scheduler/conf.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,13 +193,13 @@ VAR int MaxClients VALUE(100),
193193
/* Maximum number of clients */
194194
MaxClientsPerHost VALUE(0),
195195
/* Maximum number of clients per host */
196-
MaxCopies VALUE(CUPS_DEFAULT_MAX_COPIES),
196+
MaxCopies VALUE(CUPS_DEFAULT_MAX_COPIES);
197197
/* Maximum number of copies per job */
198-
MaxLogSize VALUE(1024 * 1024),
198+
VAR off_t MaxLogSize VALUE(1024 * 1024),
199199
/* Maximum size of log files */
200-
MaxRequestSize VALUE(0),
200+
MaxRequestSize VALUE(0);
201201
/* Maximum size of IPP requests */
202-
HostNameLookups VALUE(FALSE),
202+
VAR int HostNameLookups VALUE(FALSE),
203203
/* Do we do reverse lookups? */
204204
Timeout VALUE(DEFAULT_TIMEOUT),
205205
/* Timeout during requests */

0 commit comments

Comments
 (0)