summaryrefslogtreecommitdiff
path: root/ufilter.c
diff options
context:
space:
mode:
authorStefan Esser2014-05-15 14:08:57 +0200
committerStefan Esser2014-05-15 14:08:57 +0200
commit9ec6eb401c5c9dec126826f22ab1a71322758ad0 (patch)
tree645c0cc594dbc91e90ddb9b02aae81b37f3880b6 /ufilter.c
parent355696b80f1787d2fe3768a5b29853288b92e3fa (diff)
Better handling of non existing/non executable fileupload verification scripts
Diffstat (limited to 'ufilter.c')
-rw-r--r--ufilter.c36
1 files changed, 32 insertions, 4 deletions
diff --git a/ufilter.c b/ufilter.c
index 67bb114..5a85b54 100644
--- a/ufilter.c
+++ b/ufilter.c
@@ -292,6 +292,7 @@ int suhosin_rfc1867_filter(unsigned int event, void *event_data, void **extra TS
292 char cmd[8192]; 292 char cmd[8192];
293 FILE *in; 293 FILE *in;
294 int first=1; 294 int first=1;
295 struct stat st;
295 char *sname = SUHOSIN_G(upload_verification_script); 296 char *sname = SUHOSIN_G(upload_verification_script);
296 297
297 /* ignore files that will get deleted anyway */ 298 /* ignore files that will get deleted anyway */
@@ -305,8 +306,25 @@ int suhosin_rfc1867_filter(unsigned int event, void *event_data, void **extra TS
305 SUHOSIN_G(num_uploads)++; 306 SUHOSIN_G(num_uploads)++;
306 break; 307 break;
307 } 308 }
308 309
309 ap_php_snprintf(cmd, sizeof(cmd), "%s %s", sname, mefe->temp_filename); 310 if (VCWD_STAT(sname, &st) < 0) {
311 suhosin_log(S_FILES, "unable to find fileupload verification script %s - file dropped", sname);
312 if (!SUHOSIN_G(simulation)) {
313 goto continue_with_failure;
314 } else {
315 goto continue_with_next;
316 }
317 }
318 if (access(sname, X_OK|R_OK) < 0) {
319 suhosin_log(S_FILES, "fileupload verification script %s is not executable - file dropped", sname);
320 if (!SUHOSIN_G(simulation)) {
321 goto continue_with_failure;
322 } else {
323 goto continue_with_next;
324 }
325 }
326
327 ap_php_snprintf(cmd, sizeof(cmd), "%s %s 2>&1", sname, mefe->temp_filename);
310 328
311 if ((in=VCWD_POPEN(cmd, "r"))==NULL) { 329 if ((in=VCWD_POPEN(cmd, "r"))==NULL) {
312 suhosin_log(S_FILES, "unable to execute fileupload verification script %s - file dropped", sname); 330 suhosin_log(S_FILES, "unable to execute fileupload verification script %s - file dropped", sname);
@@ -326,8 +344,18 @@ int suhosin_rfc1867_filter(unsigned int event, void *event_data, void **extra TS
326 break; 344 break;
327 } 345 }
328 if (first) { 346 if (first) {
329 retval = atoi(cmd) == 1 ? SUCCESS : FAILURE; 347 if (strncmp(cmd, "sh: ", 4) == 0) {
330 first = 0; 348 /* assume this is an error */
349 suhosin_log(S_FILES, "error while executing fileupload verification script %s - file dropped", sname);
350 if (!SUHOSIN_G(simulation)) {
351 goto continue_with_failure;
352 } else {
353 goto continue_with_next;
354 }
355 } else {
356 retval = atoi(cmd) == 1 ? SUCCESS : FAILURE;
357 first = 0;
358 }
331 } 359 }
332 } 360 }
333 pclose(in); 361 pclose(in);