Skip to content

Commit 4651f36

Browse files
committed
Don't allow form data to try setting environment variables, and duplicate environment variable values as needed (Issue #1547)
1 parent 50c6be1 commit 4651f36

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ v2.5b1 - YYYY-MM-DD
168168
- Fixed an allocation bug in the `rastertoepson` filter (Issue #1537)
169169
- Fixed a range check when loading cached SNMP supply information (Issue #1538)
170170
- Fixed A4 support in the `ippevepcl` program (Issue #1544)
171+
- Fixed issues with the environment variable support of CGI programs
172+
(Issue #1547)
171173
- Removed hash support for SHA2-512-224 and SHA2-512-256.
172174
- Removed `mantohtml` script for generating html pages (use
173175
`https://www.msweet.org/mantohtml/`)

cgi-bin/var.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,11 @@ cgiGetArray(const char *name, /* I - Name of array variable */
162162

163163

164164
if (!_cups_strncasecmp(name, "ENV:", 4))
165-
return (getenv(name + 4));
165+
{
166+
const char *val = getenv(name + 4);
167+
168+
return (val ? strdup(val) : NULL);
169+
}
166170

167171
if ((var = cgi_find_variable(name)) == NULL)
168172
return (NULL);
@@ -1170,10 +1174,12 @@ cgi_initialize_string(const char *data) /* I - Form data string */
11701174
*/
11711175

11721176
for (s = name; *data != '\0'; data ++)
1177+
{
11731178
if (*data == '=')
11741179
break;
11751180
else if (*data >= ' ' && s < (name + sizeof(name) - 1))
11761181
*s++ = *data;
1182+
}
11771183

11781184
*s = '\0';
11791185
if (*data == '=')
@@ -1186,6 +1192,7 @@ cgi_initialize_string(const char *data) /* I - Form data string */
11861192
*/
11871193

11881194
for (s = value, done = 0; !done && *data != '\0'; data ++)
1195+
{
11891196
switch (*data)
11901197
{
11911198
case '&' : /* End of data... */
@@ -1228,6 +1235,7 @@ cgi_initialize_string(const char *data) /* I - Form data string */
12281235
*s++ = *data;
12291236
break;
12301237
}
1238+
}
12311239

12321240
*s = '\0'; /* nul terminate the string */
12331241

@@ -1247,6 +1255,9 @@ cgi_initialize_string(const char *data) /* I - Form data string */
12471255

12481256
fprintf(stderr, "DEBUG2: cgi_initialize_string: name=\"%s\", value=\"%s\"\n", name, value);
12491257

1258+
if (!_cups_strncasecmp(name, "ENV:", 4))
1259+
continue; // Don't allow environment vars to be set
1260+
12501261
if ((s = strrchr(name, '-')) != NULL && isdigit(s[1] & 255))
12511262
{
12521263
*s++ = '\0';

0 commit comments

Comments
 (0)