@@ -1006,9 +1006,8 @@ static size_t tsrm_realpath_r(char *path, size_t start, size_t len, int *ll, tim
1006
1006
1007
1007
/* Resolve path relatively to state and put the real path into state */
1008
1008
/* returns 0 for ok, 1 for error, -1 if (path_length >= MAXPATHLEN-1) */
1009
- CWD_API int virtual_file_ex (cwd_state * state , const char * path , verify_path_func verify_path , int use_realpath ) /* {{{ */
1009
+ CWD_API int virtual_file_ex (cwd_state * state , const char * path , size_t path_length , verify_path_func verify_path , int use_realpath ) /* {{{ */
1010
1010
{
1011
- size_t path_length = strlen (path );
1012
1011
char resolved_path [MAXPATHLEN ];
1013
1012
size_t start = 1 ;
1014
1013
int ll = 0 ;
@@ -1204,7 +1203,8 @@ CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func
1204
1203
1205
1204
CWD_API zend_result virtual_chdir (const char * path ) /* {{{ */
1206
1205
{
1207
- return virtual_file_ex (& CWDG (cwd ), path , php_is_dir_ok , CWD_REALPATH ) ? FAILURE : SUCCESS ;
1206
+ size_t path_length = strlen (path );
1207
+ return virtual_file_ex (& CWDG (cwd ), path , path_length , php_is_dir_ok , CWD_REALPATH ) ? FAILURE : SUCCESS ;
1208
1208
}
1209
1209
/* }}} */
1210
1210
@@ -1248,24 +1248,26 @@ CWD_API char *virtual_realpath(const char *path, char *real_path) /* {{{ */
1248
1248
cwd_state new_state ;
1249
1249
char * retval ;
1250
1250
char cwd [MAXPATHLEN ];
1251
+ size_t path_length = strlen (path );
1251
1252
1252
1253
/* realpath("") returns CWD */
1253
- if (! * path ) {
1254
+ if (path_length == 0 ) {
1254
1255
new_state .cwd = (char * )emalloc (1 );
1255
1256
new_state .cwd [0 ] = '\0' ;
1256
1257
new_state .cwd_length = 0 ;
1257
1258
if (VCWD_GETCWD (cwd , MAXPATHLEN )) {
1258
1259
path = cwd ;
1260
+ path_length = strlen (cwd );
1259
1261
}
1260
- } else if (!IS_ABSOLUTE_PATH (path , strlen ( path ) )) {
1262
+ } else if (!IS_ABSOLUTE_PATH (path , path_length )) {
1261
1263
CWD_STATE_COPY (& new_state , & CWDG (cwd ));
1262
1264
} else {
1263
1265
new_state .cwd = (char * )emalloc (1 );
1264
1266
new_state .cwd [0 ] = '\0' ;
1265
1267
new_state .cwd_length = 0 ;
1266
1268
}
1267
1269
1268
- if (virtual_file_ex (& new_state , path , NULL , CWD_REALPATH )== 0 ) {
1270
+ if (virtual_file_ex (& new_state , path , path_length , NULL , CWD_REALPATH )== 0 ) {
1269
1271
size_t len = new_state .cwd_length > MAXPATHLEN - 1 ?MAXPATHLEN - 1 :new_state .cwd_length ;
1270
1272
1271
1273
memcpy (real_path , new_state .cwd , len );
@@ -1284,10 +1286,11 @@ CWD_API char *virtual_realpath(const char *path, char *real_path) /* {{{ */
1284
1286
CWD_API int virtual_filepath_ex (const char * path , char * * filepath , verify_path_func verify_path ) /* {{{ */
1285
1287
{
1286
1288
cwd_state new_state ;
1289
+ size_t path_length = strlen (path );
1287
1290
int retval ;
1288
1291
1289
1292
CWD_STATE_COPY (& new_state , & CWDG (cwd ));
1290
- retval = virtual_file_ex (& new_state , path , verify_path , CWD_FILEPATH );
1293
+ retval = virtual_file_ex (& new_state , path , path_length , verify_path , CWD_FILEPATH );
1291
1294
1292
1295
* filepath = new_state .cwd ;
1293
1296
@@ -1306,14 +1309,15 @@ CWD_API int virtual_filepath(const char *path, char **filepath) /* {{{ */
1306
1309
CWD_API FILE * virtual_fopen (const char * path , const char * mode ) /* {{{ */
1307
1310
{
1308
1311
cwd_state new_state ;
1312
+ size_t path_length = strlen (path );
1309
1313
FILE * f ;
1310
1314
1311
1315
if (path [0 ] == '\0' ) { /* Fail to open empty path */
1312
1316
return NULL ;
1313
1317
}
1314
1318
1315
1319
CWD_STATE_COPY (& new_state , & CWDG (cwd ));
1316
- if (virtual_file_ex (& new_state , path , NULL , CWD_EXPAND )) {
1320
+ if (virtual_file_ex (& new_state , path , path_length , NULL , CWD_EXPAND )) {
1317
1321
CWD_STATE_FREE_ERR (& new_state );
1318
1322
return NULL ;
1319
1323
}
@@ -1333,10 +1337,11 @@ CWD_API FILE *virtual_fopen(const char *path, const char *mode) /* {{{ */
1333
1337
CWD_API int virtual_access (const char * pathname , int mode ) /* {{{ */
1334
1338
{
1335
1339
cwd_state new_state ;
1340
+ size_t path_length = strlen (pathname );
1336
1341
int ret ;
1337
1342
1338
1343
CWD_STATE_COPY (& new_state , & CWDG (cwd ));
1339
- if (virtual_file_ex (& new_state , pathname , NULL , CWD_REALPATH )) {
1344
+ if (virtual_file_ex (& new_state , pathname , path_length , NULL , CWD_REALPATH )) {
1340
1345
CWD_STATE_FREE_ERR (& new_state );
1341
1346
return -1 ;
1342
1347
}
@@ -1357,10 +1362,11 @@ CWD_API int virtual_access(const char *pathname, int mode) /* {{{ */
1357
1362
CWD_API int virtual_utime (const char * filename , struct utimbuf * buf ) /* {{{ */
1358
1363
{
1359
1364
cwd_state new_state ;
1365
+ size_t filename_length = strlen (filename );
1360
1366
int ret ;
1361
1367
1362
1368
CWD_STATE_COPY (& new_state , & CWDG (cwd ));
1363
- if (virtual_file_ex (& new_state , filename , NULL , CWD_REALPATH )) {
1369
+ if (virtual_file_ex (& new_state , filename , filename_length , NULL , CWD_REALPATH )) {
1364
1370
CWD_STATE_FREE_ERR (& new_state );
1365
1371
return -1 ;
1366
1372
}
@@ -1380,10 +1386,11 @@ CWD_API int virtual_utime(const char *filename, struct utimbuf *buf) /* {{{ */
1380
1386
CWD_API int virtual_chmod (const char * filename , mode_t mode ) /* {{{ */
1381
1387
{
1382
1388
cwd_state new_state ;
1389
+ size_t filename_length = strlen (filename );
1383
1390
int ret ;
1384
1391
1385
1392
CWD_STATE_COPY (& new_state , & CWDG (cwd ));
1386
- if (virtual_file_ex (& new_state , filename , NULL , CWD_REALPATH )) {
1393
+ if (virtual_file_ex (& new_state , filename , filename_length , NULL , CWD_REALPATH )) {
1387
1394
CWD_STATE_FREE_ERR (& new_state );
1388
1395
return -1 ;
1389
1396
}
@@ -1415,10 +1422,11 @@ CWD_API int virtual_chmod(const char *filename, mode_t mode) /* {{{ */
1415
1422
CWD_API int virtual_chown (const char * filename , uid_t owner , gid_t group , int link ) /* {{{ */
1416
1423
{
1417
1424
cwd_state new_state ;
1425
+ size_t filename_length = strlen (filename );
1418
1426
int ret ;
1419
1427
1420
1428
CWD_STATE_COPY (& new_state , & CWDG (cwd ));
1421
- if (virtual_file_ex (& new_state , filename , NULL , CWD_REALPATH )) {
1429
+ if (virtual_file_ex (& new_state , filename , filename_length , NULL , CWD_REALPATH )) {
1422
1430
CWD_STATE_FREE_ERR (& new_state );
1423
1431
return -1 ;
1424
1432
}
@@ -1442,10 +1450,11 @@ CWD_API int virtual_chown(const char *filename, uid_t owner, gid_t group, int li
1442
1450
CWD_API int virtual_open (const char * path , int flags , ...) /* {{{ */
1443
1451
{
1444
1452
cwd_state new_state ;
1453
+ size_t path_length = strlen (path );
1445
1454
int f ;
1446
1455
1447
1456
CWD_STATE_COPY (& new_state , & CWDG (cwd ));
1448
- if (virtual_file_ex (& new_state , path , NULL , CWD_FILEPATH )) {
1457
+ if (virtual_file_ex (& new_state , path , path_length , NULL , CWD_FILEPATH )) {
1449
1458
CWD_STATE_FREE_ERR (& new_state );
1450
1459
return -1 ;
1451
1460
}
@@ -1478,10 +1487,11 @@ CWD_API int virtual_open(const char *path, int flags, ...) /* {{{ */
1478
1487
CWD_API int virtual_creat (const char * path , mode_t mode ) /* {{{ */
1479
1488
{
1480
1489
cwd_state new_state ;
1490
+ size_t path_length = strlen (path );
1481
1491
int f ;
1482
1492
1483
1493
CWD_STATE_COPY (& new_state , & CWDG (cwd ));
1484
- if (virtual_file_ex (& new_state , path , NULL , CWD_FILEPATH )) {
1494
+ if (virtual_file_ex (& new_state , path , path_length , NULL , CWD_FILEPATH )) {
1485
1495
CWD_STATE_FREE_ERR (& new_state );
1486
1496
return -1 ;
1487
1497
}
@@ -1497,17 +1507,19 @@ CWD_API int virtual_rename(const char *oldname, const char *newname) /* {{{ */
1497
1507
{
1498
1508
cwd_state old_state ;
1499
1509
cwd_state new_state ;
1510
+ size_t old_name_length = strlen (oldname );
1511
+ size_t new_name_length = strlen (newname );
1500
1512
int retval ;
1501
1513
1502
1514
CWD_STATE_COPY (& old_state , & CWDG (cwd ));
1503
- if (virtual_file_ex (& old_state , oldname , NULL , CWD_EXPAND )) {
1515
+ if (virtual_file_ex (& old_state , oldname , old_name_length , NULL , CWD_EXPAND )) {
1504
1516
CWD_STATE_FREE_ERR (& old_state );
1505
1517
return -1 ;
1506
1518
}
1507
1519
oldname = old_state .cwd ;
1508
1520
1509
1521
CWD_STATE_COPY (& new_state , & CWDG (cwd ));
1510
- if (virtual_file_ex (& new_state , newname , NULL , CWD_EXPAND )) {
1522
+ if (virtual_file_ex (& new_state , newname , new_name_length , NULL , CWD_EXPAND )) {
1511
1523
CWD_STATE_FREE_ERR (& old_state );
1512
1524
CWD_STATE_FREE_ERR (& new_state );
1513
1525
return -1 ;
@@ -1534,9 +1546,10 @@ CWD_API int virtual_stat(const char *path, zend_stat_t *buf) /* {{{ */
1534
1546
{
1535
1547
cwd_state new_state ;
1536
1548
int retval ;
1549
+ size_t path_length = strlen (path );
1537
1550
1538
1551
CWD_STATE_COPY (& new_state , & CWDG (cwd ));
1539
- if (virtual_file_ex (& new_state , path , NULL , CWD_REALPATH )) {
1552
+ if (virtual_file_ex (& new_state , path , path_length , NULL , CWD_REALPATH )) {
1540
1553
CWD_STATE_FREE_ERR (& new_state );
1541
1554
return -1 ;
1542
1555
}
@@ -1552,9 +1565,10 @@ CWD_API int virtual_lstat(const char *path, zend_stat_t *buf) /* {{{ */
1552
1565
{
1553
1566
cwd_state new_state ;
1554
1567
int retval ;
1568
+ size_t path_length = strlen (path );
1555
1569
1556
1570
CWD_STATE_COPY (& new_state , & CWDG (cwd ));
1557
- if (virtual_file_ex (& new_state , path , NULL , CWD_EXPAND )) {
1571
+ if (virtual_file_ex (& new_state , path , path_length , NULL , CWD_EXPAND )) {
1558
1572
CWD_STATE_FREE_ERR (& new_state );
1559
1573
return -1 ;
1560
1574
}
@@ -1570,9 +1584,10 @@ CWD_API int virtual_unlink(const char *path) /* {{{ */
1570
1584
{
1571
1585
cwd_state new_state ;
1572
1586
int retval ;
1587
+ size_t path_length = strlen (path );
1573
1588
1574
1589
CWD_STATE_COPY (& new_state , & CWDG (cwd ));
1575
- if (virtual_file_ex (& new_state , path , NULL , CWD_EXPAND )) {
1590
+ if (virtual_file_ex (& new_state , path , path_length , NULL , CWD_EXPAND )) {
1576
1591
CWD_STATE_FREE_ERR (& new_state );
1577
1592
return -1 ;
1578
1593
}
@@ -1592,9 +1607,10 @@ CWD_API int virtual_mkdir(const char *pathname, mode_t mode) /* {{{ */
1592
1607
{
1593
1608
cwd_state new_state ;
1594
1609
int retval ;
1610
+ size_t path_length = strlen (pathname );
1595
1611
1596
1612
CWD_STATE_COPY (& new_state , & CWDG (cwd ));
1597
- if (virtual_file_ex (& new_state , pathname , NULL , CWD_FILEPATH )) {
1613
+ if (virtual_file_ex (& new_state , pathname , path_length , NULL , CWD_FILEPATH )) {
1598
1614
CWD_STATE_FREE_ERR (& new_state );
1599
1615
return -1 ;
1600
1616
}
@@ -1613,9 +1629,10 @@ CWD_API int virtual_rmdir(const char *pathname) /* {{{ */
1613
1629
{
1614
1630
cwd_state new_state ;
1615
1631
int retval ;
1632
+ size_t path_length = strlen (pathname );
1616
1633
1617
1634
CWD_STATE_COPY (& new_state , & CWDG (cwd ));
1618
- if (virtual_file_ex (& new_state , pathname , NULL , CWD_EXPAND )) {
1635
+ if (virtual_file_ex (& new_state , pathname , path_length , NULL , CWD_EXPAND )) {
1619
1636
CWD_STATE_FREE_ERR (& new_state );
1620
1637
return -1 ;
1621
1638
}
@@ -1638,9 +1655,10 @@ CWD_API DIR *virtual_opendir(const char *pathname) /* {{{ */
1638
1655
{
1639
1656
cwd_state new_state ;
1640
1657
DIR * retval ;
1658
+ size_t path_length = strlen (pathname );
1641
1659
1642
1660
CWD_STATE_COPY (& new_state , & CWDG (cwd ));
1643
- if (virtual_file_ex (& new_state , pathname , NULL , CWD_REALPATH )) {
1661
+ if (virtual_file_ex (& new_state , pathname , path_length , NULL , CWD_REALPATH )) {
1644
1662
CWD_STATE_FREE_ERR (& new_state );
1645
1663
return NULL ;
1646
1664
}
@@ -1719,16 +1737,18 @@ CWD_API char *tsrm_realpath(const char *path, char *real_path) /* {{{ */
1719
1737
{
1720
1738
cwd_state new_state ;
1721
1739
char cwd [MAXPATHLEN ];
1740
+ size_t path_length = strlen (path );
1722
1741
1723
1742
/* realpath("") returns CWD */
1724
- if (! * path ) {
1743
+ if (path_length == 0 ) {
1725
1744
new_state .cwd = (char * )emalloc (1 );
1726
1745
new_state .cwd [0 ] = '\0' ;
1727
1746
new_state .cwd_length = 0 ;
1728
1747
if (VCWD_GETCWD (cwd , MAXPATHLEN )) {
1729
1748
path = cwd ;
1749
+ path_length = strlen (cwd );
1730
1750
}
1731
- } else if (!IS_ABSOLUTE_PATH (path , strlen ( path ) ) &&
1751
+ } else if (!IS_ABSOLUTE_PATH (path , path_length ) &&
1732
1752
VCWD_GETCWD (cwd , MAXPATHLEN )) {
1733
1753
new_state .cwd = estrdup (cwd );
1734
1754
new_state .cwd_length = strlen (cwd );
@@ -1738,7 +1758,7 @@ CWD_API char *tsrm_realpath(const char *path, char *real_path) /* {{{ */
1738
1758
new_state .cwd_length = 0 ;
1739
1759
}
1740
1760
1741
- if (virtual_file_ex (& new_state , path , NULL , CWD_REALPATH )) {
1761
+ if (virtual_file_ex (& new_state , path , path_length , NULL , CWD_REALPATH )) {
1742
1762
efree (new_state .cwd );
1743
1763
return NULL ;
1744
1764
}
0 commit comments