Skip to content

Commit 2940113

Browse files
committed
scheduler: Sanitize values for FilterNice directive
We allow only values 0-19 for `nice()` in cupsd, but when reading the configuration this fact was not applied.
1 parent 7dc51ee commit 2940113

2 files changed

Lines changed: 36 additions & 3 deletions

File tree

CHANGES.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,10 @@ v2.5b1 - YYYY-MM-DD
161161
(Issue #1201)
162162
- Fixed job cleanup after daemon restart (Issue #1315)
163163
- Fixed unreachable block in IPP backend (Issue #1351)
164-
- Fixed memory leak in _cupsConvertOptions (Issue #1354)
164+
- Fixed memory leak in `_cupsConvertOptions()` (Issue #1354)
165165
- Fixed missing write check in `cupsFileOpen/Fd` (Issue #1360)
166166
- Fixed error recovery when scanning for PPDs in `cups-driverd` (Issue #1416)
167+
- Fixed allowed values for directive `FilterNice`
167168
- Removed hash support for SHA2-512-224 and SHA2-512-256.
168169
- Removed `mantohtml` script for generating html pages (use
169170
`https://www.msweet.org/mantohtml/`)

scheduler/conf.c

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ typedef enum
4848
CUPSD_VARTYPE_STRING, /* String option */
4949
CUPSD_VARTYPE_BOOLEAN, /* Boolean option */
5050
CUPSD_VARTYPE_PATHNAME, /* File/directory name option */
51-
CUPSD_VARTYPE_PERM /* File/directory permissions */
51+
CUPSD_VARTYPE_PERM, /* File/directory permissions */
52+
CUPSD_VARTYPE_NICE /* Values for nice() - 0 to 19 */
5253
} cupsd_vartype_t;
5354

5455
typedef struct
@@ -81,7 +82,7 @@ static const cupsd_var_t cupsd_vars[] =
8182
{ "DNSSDHostName", &DNSSDHostName, CUPSD_VARTYPE_STRING },
8283
{ "ErrorPolicy", &ErrorPolicy, CUPSD_VARTYPE_STRING },
8384
{ "FilterLimit", &FilterLimit, CUPSD_VARTYPE_INTEGER },
84-
{ "FilterNice", &FilterNice, CUPSD_VARTYPE_INTEGER },
85+
{ "FilterNice", &FilterNice, CUPSD_VARTYPE_NICE},
8586
#ifdef HAVE_GSSAPI
8687
{ "GSSServiceName", &GSSServiceName, CUPSD_VARTYPE_STRING },
8788
#endif /* HAVE_GSSAPI */
@@ -3017,6 +3018,37 @@ parse_variable(
30173018

30183019
cupsdSetString((char **)var->ptr, value);
30193020
break;
3021+
3022+
case CUPSD_VARTYPE_NICE :
3023+
if (!value)
3024+
{
3025+
cupsdLogMessage(CUPSD_LOG_ERROR, "Missing value for %s on line %d of %s.", line, linenum, filename);
3026+
return (0);
3027+
}
3028+
3029+
while (*value)
3030+
{
3031+
if (!isdigit(*value++))
3032+
{
3033+
cupsdLogMessage(CUPSD_LOG_ERROR,
3034+
"Bad integer value for %s on line %d of %s.",
3035+
line, linenum, filename);
3036+
return (0);
3037+
}
3038+
}
3039+
3040+
int n = (int)strtol(value, NULL, 10);
3041+
3042+
if (n < 0 || n > 19)
3043+
{
3044+
cupsdLogMessage(CUPSD_LOG_ERROR, "Bad integer value for %s on line %d of %s. Supported values are 0-19.",
3045+
line, linenum, filename);
3046+
return (0);
3047+
}
3048+
3049+
*((int *)var->ptr) = n;
3050+
3051+
break;
30203052
}
30213053

30223054
return (1);

0 commit comments

Comments
 (0)