|
1 | 1 | /* |
2 | 2 | * RSS notifier for CUPS. |
3 | 3 | * |
4 | | - * Copyright © 2020-2024 by OpenPrinting. |
5 | | - * Copyright 2007-2015 by Apple Inc. |
6 | | - * Copyright 2007 by Easy Software Products. |
| 4 | + * Copyright © 2020-2026 by OpenPrinting. |
| 5 | + * Copyright © 2007-2015 by Apple Inc. |
| 6 | + * Copyright © 2007 by Easy Software Products. |
7 | 7 | * |
8 | | - * Licensed under Apache License v2.0. See the file "LICENSE" for more information. |
| 8 | + * Licensed under Apache License v2.0. See the file "LICENSE" for more |
| 9 | + * information. |
9 | 10 | */ |
10 | 11 |
|
11 | 12 | /* |
@@ -80,6 +81,7 @@ main(int argc, /* I - Number of command-line arguments */ |
80 | 81 | http_status_t status; /* HTTP GET/PUT status code */ |
81 | 82 | char filename[1024], /* Local filename */ |
82 | 83 | newname[1024]; /* filename.N */ |
| 84 | + struct stat fileinfo; /* Local file information */ |
83 | 85 | cups_lang_t *language; /* Language information */ |
84 | 86 | ipp_attribute_t *printer_up_time, /* Timestamp on event */ |
85 | 87 | *notify_sequence_number,/* Sequence number */ |
@@ -111,9 +113,9 @@ main(int argc, /* I - Number of command-line arguments */ |
111 | 113 |
|
112 | 114 | if (httpSeparateURI(HTTP_URI_CODING_ALL, argv[1], scheme, sizeof(scheme), |
113 | 115 | username, sizeof(username), host, sizeof(host), &port, |
114 | | - resource, sizeof(resource)) < HTTP_URI_OK) |
| 116 | + resource, sizeof(resource)) < HTTP_URI_OK || strstr(resource, "../") != NULL) |
115 | 117 | { |
116 | | - fprintf(stderr, "ERROR: Bad RSS URI \"%s\"!\n", argv[1]); |
| 118 | + fprintf(stderr, "ERROR: Bad RSS URI \"%s\".\n", argv[1]); |
117 | 119 | return (1); |
118 | 120 | } |
119 | 121 |
|
@@ -209,6 +211,12 @@ main(int argc, /* I - Number of command-line arguments */ |
209 | 211 | snprintf(filename, sizeof(filename), "%s/rss%s", cachedir, resource); |
210 | 212 | snprintf(newname, sizeof(newname), "%s.N", filename); |
211 | 213 |
|
| 214 | + if (!lstat(filename, &fileinfo) && !S_ISREG(fileinfo.st_mode)) |
| 215 | + { |
| 216 | + fprintf(stderr, "ERROR: Local RSS path \"%s\" is not a file.\n", filename); |
| 217 | + return (1); |
| 218 | + } |
| 219 | + |
212 | 220 | httpAssembleURIf(HTTP_URI_CODING_ALL, baseurl, sizeof(baseurl), "http", |
213 | 221 | NULL, server_name, atoi(server_port), "/rss%s", resource); |
214 | 222 | } |
|
0 commit comments