Fossil SCM
Add the optimized file_is_simple_pathname_nonstrict() as an alternative to file_is_simple_pathname() when parsing manifests.
Commit
b4aadf2cea1a4a082044a9ce11fd676517a7224900ac817e0cfe07d13cbc33b2
Parent
0aaefeaba1bbca5…
2 files changed
+17
+3
-3
+17
| --- src/file.c | ||
| +++ src/file.c | ||
| @@ -875,10 +875,27 @@ | ||
| 875 | 875 | } |
| 876 | 876 | } |
| 877 | 877 | } |
| 878 | 878 | if( z[i-1]=='/' ) return 0; |
| 879 | 879 | return 1; |
| 880 | +} | |
| 881 | +int file_is_simple_pathname_nonstrict(const char *z){ | |
| 882 | + unsigned char c = (unsigned char) z[0]; | |
| 883 | + if( c=='/' || c==0 ) return 0; | |
| 884 | + if( c=='.' ){ | |
| 885 | + if( z[1]=='/' || z[1]==0 ) return 0; | |
| 886 | + if( z[1]=='.' && (z[2]=='/' || z[2]==0) ) return 0; | |
| 887 | + } | |
| 888 | + while( (z = strchr(z+1, '/'))!=0 ){ | |
| 889 | + if( z[1]=='/' ) return 0; | |
| 890 | + if( z[1]==0 ) return 0; | |
| 891 | + if( z[1]=='.' ){ | |
| 892 | + if( z[2]=='/' || z[2]==0 ) return 0; | |
| 893 | + if( z[2]=='.' && (z[3]=='/' || z[3]==0) ) return 0; | |
| 894 | + } | |
| 895 | + } | |
| 896 | + return 1; | |
| 880 | 897 | } |
| 881 | 898 | |
| 882 | 899 | /* |
| 883 | 900 | ** If the last component of the pathname in z[0]..z[j-1] is something |
| 884 | 901 | ** other than ".." then back it out and return true. If the last |
| 885 | 902 |
| --- src/file.c | |
| +++ src/file.c | |
| @@ -875,10 +875,27 @@ | |
| 875 | } |
| 876 | } |
| 877 | } |
| 878 | if( z[i-1]=='/' ) return 0; |
| 879 | return 1; |
| 880 | } |
| 881 | |
| 882 | /* |
| 883 | ** If the last component of the pathname in z[0]..z[j-1] is something |
| 884 | ** other than ".." then back it out and return true. If the last |
| 885 |
| --- src/file.c | |
| +++ src/file.c | |
| @@ -875,10 +875,27 @@ | |
| 875 | } |
| 876 | } |
| 877 | } |
| 878 | if( z[i-1]=='/' ) return 0; |
| 879 | return 1; |
| 880 | } |
| 881 | int file_is_simple_pathname_nonstrict(const char *z){ |
| 882 | unsigned char c = (unsigned char) z[0]; |
| 883 | if( c=='/' || c==0 ) return 0; |
| 884 | if( c=='.' ){ |
| 885 | if( z[1]=='/' || z[1]==0 ) return 0; |
| 886 | if( z[1]=='.' && (z[2]=='/' || z[2]==0) ) return 0; |
| 887 | } |
| 888 | while( (z = strchr(z+1, '/'))!=0 ){ |
| 889 | if( z[1]=='/' ) return 0; |
| 890 | if( z[1]==0 ) return 0; |
| 891 | if( z[1]=='.' ){ |
| 892 | if( z[2]=='/' || z[2]==0 ) return 0; |
| 893 | if( z[2]=='.' && (z[3]=='/' || z[3]==0) ) return 0; |
| 894 | } |
| 895 | } |
| 896 | return 1; |
| 897 | } |
| 898 | |
| 899 | /* |
| 900 | ** If the last component of the pathname in z[0]..z[j-1] is something |
| 901 | ** other than ".." then back it out and return true. If the last |
| 902 |
+3
-3
| --- src/manifest.c | ||
| +++ src/manifest.c | ||
| @@ -508,11 +508,11 @@ | ||
| 508 | 508 | zTarget = next_token(&x, &nTarget); |
| 509 | 509 | zSrc = next_token(&x, &nSrc); |
| 510 | 510 | if( zName==0 || zTarget==0 ) goto manifest_syntax_error; |
| 511 | 511 | if( p->zAttachName!=0 ) goto manifest_syntax_error; |
| 512 | 512 | defossilize(zName); |
| 513 | - if( !file_is_simple_pathname(zName, 0) ){ | |
| 513 | + if( !file_is_simple_pathname_nonstrict(zName) ){ | |
| 514 | 514 | SYNTAX("invalid filename on A-card"); |
| 515 | 515 | } |
| 516 | 516 | defossilize(zTarget); |
| 517 | 517 | if( !hname_validate(zTarget,nTarget) |
| 518 | 518 | && !wiki_name_is_wellformed((const unsigned char *)zTarget) ){ |
| @@ -606,11 +606,11 @@ | ||
| 606 | 606 | case 'F': { |
| 607 | 607 | char *zName, *zPerm, *zPriorName; |
| 608 | 608 | zName = next_token(&x,0); |
| 609 | 609 | if( zName==0 ) SYNTAX("missing filename on F-card"); |
| 610 | 610 | defossilize(zName); |
| 611 | - if( !file_is_simple_pathname(zName, 0) ){ | |
| 611 | + if( !file_is_simple_pathname_nonstrict(zName) ){ | |
| 612 | 612 | SYNTAX("F-card filename is not a simple path"); |
| 613 | 613 | } |
| 614 | 614 | zUuid = next_token(&x, &sz); |
| 615 | 615 | if( p->zBaseline==0 || zUuid!=0 ){ |
| 616 | 616 | if( !hname_validate(zUuid,sz) ){ |
| @@ -619,11 +619,11 @@ | ||
| 619 | 619 | } |
| 620 | 620 | zPerm = next_token(&x,0); |
| 621 | 621 | zPriorName = next_token(&x,0); |
| 622 | 622 | if( zPriorName ){ |
| 623 | 623 | defossilize(zPriorName); |
| 624 | - if( !file_is_simple_pathname(zPriorName, 0) ){ | |
| 624 | + if( !file_is_simple_pathname_nonstrict(zPriorName) ){ | |
| 625 | 625 | SYNTAX("F-card old filename is not a simple path"); |
| 626 | 626 | } |
| 627 | 627 | } |
| 628 | 628 | if( p->nFile>=p->nFileAlloc ){ |
| 629 | 629 | p->nFileAlloc = p->nFileAlloc*2 + 10; |
| 630 | 630 |
| --- src/manifest.c | |
| +++ src/manifest.c | |
| @@ -508,11 +508,11 @@ | |
| 508 | zTarget = next_token(&x, &nTarget); |
| 509 | zSrc = next_token(&x, &nSrc); |
| 510 | if( zName==0 || zTarget==0 ) goto manifest_syntax_error; |
| 511 | if( p->zAttachName!=0 ) goto manifest_syntax_error; |
| 512 | defossilize(zName); |
| 513 | if( !file_is_simple_pathname(zName, 0) ){ |
| 514 | SYNTAX("invalid filename on A-card"); |
| 515 | } |
| 516 | defossilize(zTarget); |
| 517 | if( !hname_validate(zTarget,nTarget) |
| 518 | && !wiki_name_is_wellformed((const unsigned char *)zTarget) ){ |
| @@ -606,11 +606,11 @@ | |
| 606 | case 'F': { |
| 607 | char *zName, *zPerm, *zPriorName; |
| 608 | zName = next_token(&x,0); |
| 609 | if( zName==0 ) SYNTAX("missing filename on F-card"); |
| 610 | defossilize(zName); |
| 611 | if( !file_is_simple_pathname(zName, 0) ){ |
| 612 | SYNTAX("F-card filename is not a simple path"); |
| 613 | } |
| 614 | zUuid = next_token(&x, &sz); |
| 615 | if( p->zBaseline==0 || zUuid!=0 ){ |
| 616 | if( !hname_validate(zUuid,sz) ){ |
| @@ -619,11 +619,11 @@ | |
| 619 | } |
| 620 | zPerm = next_token(&x,0); |
| 621 | zPriorName = next_token(&x,0); |
| 622 | if( zPriorName ){ |
| 623 | defossilize(zPriorName); |
| 624 | if( !file_is_simple_pathname(zPriorName, 0) ){ |
| 625 | SYNTAX("F-card old filename is not a simple path"); |
| 626 | } |
| 627 | } |
| 628 | if( p->nFile>=p->nFileAlloc ){ |
| 629 | p->nFileAlloc = p->nFileAlloc*2 + 10; |
| 630 |
| --- src/manifest.c | |
| +++ src/manifest.c | |
| @@ -508,11 +508,11 @@ | |
| 508 | zTarget = next_token(&x, &nTarget); |
| 509 | zSrc = next_token(&x, &nSrc); |
| 510 | if( zName==0 || zTarget==0 ) goto manifest_syntax_error; |
| 511 | if( p->zAttachName!=0 ) goto manifest_syntax_error; |
| 512 | defossilize(zName); |
| 513 | if( !file_is_simple_pathname_nonstrict(zName) ){ |
| 514 | SYNTAX("invalid filename on A-card"); |
| 515 | } |
| 516 | defossilize(zTarget); |
| 517 | if( !hname_validate(zTarget,nTarget) |
| 518 | && !wiki_name_is_wellformed((const unsigned char *)zTarget) ){ |
| @@ -606,11 +606,11 @@ | |
| 606 | case 'F': { |
| 607 | char *zName, *zPerm, *zPriorName; |
| 608 | zName = next_token(&x,0); |
| 609 | if( zName==0 ) SYNTAX("missing filename on F-card"); |
| 610 | defossilize(zName); |
| 611 | if( !file_is_simple_pathname_nonstrict(zName) ){ |
| 612 | SYNTAX("F-card filename is not a simple path"); |
| 613 | } |
| 614 | zUuid = next_token(&x, &sz); |
| 615 | if( p->zBaseline==0 || zUuid!=0 ){ |
| 616 | if( !hname_validate(zUuid,sz) ){ |
| @@ -619,11 +619,11 @@ | |
| 619 | } |
| 620 | zPerm = next_token(&x,0); |
| 621 | zPriorName = next_token(&x,0); |
| 622 | if( zPriorName ){ |
| 623 | defossilize(zPriorName); |
| 624 | if( !file_is_simple_pathname_nonstrict(zPriorName) ){ |
| 625 | SYNTAX("F-card old filename is not a simple path"); |
| 626 | } |
| 627 | } |
| 628 | if( p->nFile>=p->nFileAlloc ){ |
| 629 | p->nFileAlloc = p->nFileAlloc*2 + 10; |
| 630 |