Fossil SCM
If the 'allow-symlinks' option is enabled (or the '--no-dir-symlinks' flag is specified), do not traverse into symlinked directories.
Commit
3e949e17614a79e72a51e40af130ef0ec711d166
Parent
ffd261abfb84855…
2 files changed
+7
-2
+4
-4
M
src/db.c
+7
-2
| --- src/db.c | ||
| +++ src/db.c | ||
| @@ -1436,12 +1436,17 @@ | ||
| 1436 | 1436 | } |
| 1437 | 1437 | |
| 1438 | 1438 | /* |
| 1439 | 1439 | ** Returns non-zero if support for symlinks is currently enabled. |
| 1440 | 1440 | */ |
| 1441 | -int db_allow_symlinks(void){ | |
| 1442 | - return g.allowSymlinks; | |
| 1441 | +int db_allow_symlinks(int traversal){ | |
| 1442 | + if( traversal ){ | |
| 1443 | + if( g.allowSymlinks ) return 1; | |
| 1444 | + return g.fNoDirSymlinks; | |
| 1445 | + }else{ | |
| 1446 | + return g.allowSymlinks; | |
| 1447 | + } | |
| 1443 | 1448 | } |
| 1444 | 1449 | |
| 1445 | 1450 | /* |
| 1446 | 1451 | ** Open the repository database given by zDbName. If zDbName==NULL then |
| 1447 | 1452 | ** get the name from the already open local database. |
| 1448 | 1453 |
| --- src/db.c | |
| +++ src/db.c | |
| @@ -1436,12 +1436,17 @@ | |
| 1436 | } |
| 1437 | |
| 1438 | /* |
| 1439 | ** Returns non-zero if support for symlinks is currently enabled. |
| 1440 | */ |
| 1441 | int db_allow_symlinks(void){ |
| 1442 | return g.allowSymlinks; |
| 1443 | } |
| 1444 | |
| 1445 | /* |
| 1446 | ** Open the repository database given by zDbName. If zDbName==NULL then |
| 1447 | ** get the name from the already open local database. |
| 1448 |
| --- src/db.c | |
| +++ src/db.c | |
| @@ -1436,12 +1436,17 @@ | |
| 1436 | } |
| 1437 | |
| 1438 | /* |
| 1439 | ** Returns non-zero if support for symlinks is currently enabled. |
| 1440 | */ |
| 1441 | int db_allow_symlinks(int traversal){ |
| 1442 | if( traversal ){ |
| 1443 | if( g.allowSymlinks ) return 1; |
| 1444 | return g.fNoDirSymlinks; |
| 1445 | }else{ |
| 1446 | return g.allowSymlinks; |
| 1447 | } |
| 1448 | } |
| 1449 | |
| 1450 | /* |
| 1451 | ** Open the repository database given by zDbName. If zDbName==NULL then |
| 1452 | ** get the name from the already open local database. |
| 1453 |
+4
-4
| --- src/file.c | ||
| +++ src/file.c | ||
| @@ -89,11 +89,11 @@ | ||
| 89 | 89 | */ |
| 90 | 90 | static int fossil_stat(const char *zFilename, struct fossilStat *buf, int isWd){ |
| 91 | 91 | int rc; |
| 92 | 92 | void *zMbcs = fossil_utf8_to_path(zFilename, 0); |
| 93 | 93 | #if !defined(_WIN32) |
| 94 | - if( isWd && db_allow_symlinks() ){ | |
| 94 | + if( isWd && db_allow_symlinks(0) ){ | |
| 95 | 95 | rc = lstat(zMbcs, buf); |
| 96 | 96 | }else{ |
| 97 | 97 | rc = stat(zMbcs, buf); |
| 98 | 98 | } |
| 99 | 99 | #else |
| @@ -191,11 +191,11 @@ | ||
| 191 | 191 | ** |
| 192 | 192 | ** Arguments: target file (symlink will point to it), link file |
| 193 | 193 | **/ |
| 194 | 194 | void symlink_create(const char *zTargetFile, const char *zLinkFile){ |
| 195 | 195 | #if !defined(_WIN32) |
| 196 | - if( db_allow_symlinks() ){ | |
| 196 | + if( db_allow_symlinks(0) ){ | |
| 197 | 197 | int i, nName; |
| 198 | 198 | char *zName, zBuf[1000]; |
| 199 | 199 | |
| 200 | 200 | nName = strlen(zLinkFile); |
| 201 | 201 | if( nName>=sizeof(zBuf) ){ |
| @@ -248,11 +248,11 @@ | ||
| 248 | 248 | int file_wd_perm(const char *zFilename){ |
| 249 | 249 | #if !defined(_WIN32) |
| 250 | 250 | if( !getStat(zFilename, 1) ){ |
| 251 | 251 | if( S_ISREG(fileStat.st_mode) && ((S_IXUSR)&fileStat.st_mode)!=0 ) |
| 252 | 252 | return PERM_EXE; |
| 253 | - else if( db_allow_symlinks() && S_ISLNK(fileStat.st_mode) ) | |
| 253 | + else if( db_allow_symlinks(0) && S_ISLNK(fileStat.st_mode) ) | |
| 254 | 254 | return PERM_LNK; |
| 255 | 255 | } |
| 256 | 256 | #endif |
| 257 | 257 | return PERM_REG; |
| 258 | 258 | } |
| @@ -309,11 +309,11 @@ | ||
| 309 | 309 | rc = getStat(zFN, 1); |
| 310 | 310 | if( rc ){ |
| 311 | 311 | rc = 0; /* It does not exist at all. */ |
| 312 | 312 | }else if( S_ISDIR(fileStat.st_mode) ){ |
| 313 | 313 | rc = 1; /* It exists and is a real directory. */ |
| 314 | - }else if( !g.fNoDirSymlinks && S_ISLNK(fileStat.st_mode) ){ | |
| 314 | + }else if( !db_allow_symlinks(1) && S_ISLNK(fileStat.st_mode) ){ | |
| 315 | 315 | Blob content; |
| 316 | 316 | blob_read_link(&content, zFN); /* It exists and is a link. */ |
| 317 | 317 | rc = file_wd_isdir(blob_str(&content)); /* Points to directory? */ |
| 318 | 318 | blob_reset(&content); |
| 319 | 319 | }else{ |
| 320 | 320 |
| --- src/file.c | |
| +++ src/file.c | |
| @@ -89,11 +89,11 @@ | |
| 89 | */ |
| 90 | static int fossil_stat(const char *zFilename, struct fossilStat *buf, int isWd){ |
| 91 | int rc; |
| 92 | void *zMbcs = fossil_utf8_to_path(zFilename, 0); |
| 93 | #if !defined(_WIN32) |
| 94 | if( isWd && db_allow_symlinks() ){ |
| 95 | rc = lstat(zMbcs, buf); |
| 96 | }else{ |
| 97 | rc = stat(zMbcs, buf); |
| 98 | } |
| 99 | #else |
| @@ -191,11 +191,11 @@ | |
| 191 | ** |
| 192 | ** Arguments: target file (symlink will point to it), link file |
| 193 | **/ |
| 194 | void symlink_create(const char *zTargetFile, const char *zLinkFile){ |
| 195 | #if !defined(_WIN32) |
| 196 | if( db_allow_symlinks() ){ |
| 197 | int i, nName; |
| 198 | char *zName, zBuf[1000]; |
| 199 | |
| 200 | nName = strlen(zLinkFile); |
| 201 | if( nName>=sizeof(zBuf) ){ |
| @@ -248,11 +248,11 @@ | |
| 248 | int file_wd_perm(const char *zFilename){ |
| 249 | #if !defined(_WIN32) |
| 250 | if( !getStat(zFilename, 1) ){ |
| 251 | if( S_ISREG(fileStat.st_mode) && ((S_IXUSR)&fileStat.st_mode)!=0 ) |
| 252 | return PERM_EXE; |
| 253 | else if( db_allow_symlinks() && S_ISLNK(fileStat.st_mode) ) |
| 254 | return PERM_LNK; |
| 255 | } |
| 256 | #endif |
| 257 | return PERM_REG; |
| 258 | } |
| @@ -309,11 +309,11 @@ | |
| 309 | rc = getStat(zFN, 1); |
| 310 | if( rc ){ |
| 311 | rc = 0; /* It does not exist at all. */ |
| 312 | }else if( S_ISDIR(fileStat.st_mode) ){ |
| 313 | rc = 1; /* It exists and is a real directory. */ |
| 314 | }else if( !g.fNoDirSymlinks && S_ISLNK(fileStat.st_mode) ){ |
| 315 | Blob content; |
| 316 | blob_read_link(&content, zFN); /* It exists and is a link. */ |
| 317 | rc = file_wd_isdir(blob_str(&content)); /* Points to directory? */ |
| 318 | blob_reset(&content); |
| 319 | }else{ |
| 320 |
| --- src/file.c | |
| +++ src/file.c | |
| @@ -89,11 +89,11 @@ | |
| 89 | */ |
| 90 | static int fossil_stat(const char *zFilename, struct fossilStat *buf, int isWd){ |
| 91 | int rc; |
| 92 | void *zMbcs = fossil_utf8_to_path(zFilename, 0); |
| 93 | #if !defined(_WIN32) |
| 94 | if( isWd && db_allow_symlinks(0) ){ |
| 95 | rc = lstat(zMbcs, buf); |
| 96 | }else{ |
| 97 | rc = stat(zMbcs, buf); |
| 98 | } |
| 99 | #else |
| @@ -191,11 +191,11 @@ | |
| 191 | ** |
| 192 | ** Arguments: target file (symlink will point to it), link file |
| 193 | **/ |
| 194 | void symlink_create(const char *zTargetFile, const char *zLinkFile){ |
| 195 | #if !defined(_WIN32) |
| 196 | if( db_allow_symlinks(0) ){ |
| 197 | int i, nName; |
| 198 | char *zName, zBuf[1000]; |
| 199 | |
| 200 | nName = strlen(zLinkFile); |
| 201 | if( nName>=sizeof(zBuf) ){ |
| @@ -248,11 +248,11 @@ | |
| 248 | int file_wd_perm(const char *zFilename){ |
| 249 | #if !defined(_WIN32) |
| 250 | if( !getStat(zFilename, 1) ){ |
| 251 | if( S_ISREG(fileStat.st_mode) && ((S_IXUSR)&fileStat.st_mode)!=0 ) |
| 252 | return PERM_EXE; |
| 253 | else if( db_allow_symlinks(0) && S_ISLNK(fileStat.st_mode) ) |
| 254 | return PERM_LNK; |
| 255 | } |
| 256 | #endif |
| 257 | return PERM_REG; |
| 258 | } |
| @@ -309,11 +309,11 @@ | |
| 309 | rc = getStat(zFN, 1); |
| 310 | if( rc ){ |
| 311 | rc = 0; /* It does not exist at all. */ |
| 312 | }else if( S_ISDIR(fileStat.st_mode) ){ |
| 313 | rc = 1; /* It exists and is a real directory. */ |
| 314 | }else if( !db_allow_symlinks(1) && S_ISLNK(fileStat.st_mode) ){ |
| 315 | Blob content; |
| 316 | blob_read_link(&content, zFN); /* It exists and is a link. */ |
| 317 | rc = file_wd_isdir(blob_str(&content)); /* Points to directory? */ |
| 318 | blob_reset(&content); |
| 319 | }else{ |
| 320 |