@@ -1369,8 +1369,11 @@ static int php_plain_files_mkdir(php_stream_wrapper *wrapper, const char *dir, i
1369
1369
return 0 ;
1370
1370
}
1371
1371
1372
+ if (php_check_open_basedir (buf )) {
1373
+ return 0 ;
1374
+ }
1375
+
1372
1376
/* we look for directory separator from the end of string, thus hopefully reducing our work load */
1373
- int ret ;
1374
1377
char * p ;
1375
1378
zend_stat_t sb ;
1376
1379
size_t dir_len = strlen (dir ), offset = 0 ;
@@ -1406,32 +1409,32 @@ static int php_plain_files_mkdir(php_stream_wrapper *wrapper, const char *dir, i
1406
1409
}
1407
1410
}
1408
1411
1409
- if (p == buf ) {
1410
- ret = php_mkdir (dir , mode );
1411
- } else if (!(ret = php_mkdir (buf , mode ))) {
1412
- if (!p ) {
1413
- p = buf ;
1412
+ if (!p ) {
1413
+ p = buf ;
1414
+ }
1415
+ while (true) {
1416
+ int ret = VCWD_MKDIR (buf , (mode_t ) mode );
1417
+ if (ret < 0 ) {
1418
+ if (options & REPORT_ERRORS ) {
1419
+ php_error_docref (NULL , E_WARNING , "%s" , strerror (errno ));
1420
+ }
1421
+ return 0 ;
1414
1422
}
1415
- /* create any needed directories if the creation of the 1st directory worked */
1423
+
1424
+ bool replaced_slash = false;
1416
1425
while (++ p != e ) {
1417
1426
if (* p == '\0' ) {
1427
+ replaced_slash = true;
1418
1428
* p = DEFAULT_SLASH ;
1419
- if ((* (p + 1 ) != '\0' ) &&
1420
- (ret = VCWD_MKDIR (buf , (mode_t )mode )) < 0 ) {
1421
- if (options & REPORT_ERRORS ) {
1422
- php_error_docref (NULL , E_WARNING , "%s" , strerror (errno ));
1423
- }
1429
+ if (* (p + 1 ) != '\0' ) {
1424
1430
break ;
1425
1431
}
1426
1432
}
1427
1433
}
1428
- }
1429
- if (ret < 0 ) {
1430
- /* Failure */
1431
- return 0 ;
1432
- } else {
1433
- /* Success */
1434
- return 1 ;
1434
+ if (p == e || !replaced_slash ) {
1435
+ /* No more directories to create */
1436
+ return 1 ;
1437
+ }
1435
1438
}
1436
1439
}
1437
1440
0 commit comments