Fossil SCM

Add the optimized file_is_simple_pathname_nonstrict() as an alternative to file_is_simple_pathname() when parsing manifests.

drh 2019-09-12 17:51 trunk
Commit b4aadf2cea1a4a082044a9ce11fd676517a7224900ac817e0cfe07d13cbc33b2
2 files changed +17 +3 -3
+17
--- src/file.c
+++ src/file.c
@@ -875,10 +875,27 @@
875875
}
876876
}
877877
}
878878
if( z[i-1]=='/' ) return 0;
879879
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;
880897
}
881898
882899
/*
883900
** If the last component of the pathname in z[0]..z[j-1] is something
884901
** other than ".." then back it out and return true. If the last
885902
--- 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 @@
508508
zTarget = next_token(&x, &nTarget);
509509
zSrc = next_token(&x, &nSrc);
510510
if( zName==0 || zTarget==0 ) goto manifest_syntax_error;
511511
if( p->zAttachName!=0 ) goto manifest_syntax_error;
512512
defossilize(zName);
513
- if( !file_is_simple_pathname(zName, 0) ){
513
+ if( !file_is_simple_pathname_nonstrict(zName) ){
514514
SYNTAX("invalid filename on A-card");
515515
}
516516
defossilize(zTarget);
517517
if( !hname_validate(zTarget,nTarget)
518518
&& !wiki_name_is_wellformed((const unsigned char *)zTarget) ){
@@ -606,11 +606,11 @@
606606
case 'F': {
607607
char *zName, *zPerm, *zPriorName;
608608
zName = next_token(&x,0);
609609
if( zName==0 ) SYNTAX("missing filename on F-card");
610610
defossilize(zName);
611
- if( !file_is_simple_pathname(zName, 0) ){
611
+ if( !file_is_simple_pathname_nonstrict(zName) ){
612612
SYNTAX("F-card filename is not a simple path");
613613
}
614614
zUuid = next_token(&x, &sz);
615615
if( p->zBaseline==0 || zUuid!=0 ){
616616
if( !hname_validate(zUuid,sz) ){
@@ -619,11 +619,11 @@
619619
}
620620
zPerm = next_token(&x,0);
621621
zPriorName = next_token(&x,0);
622622
if( zPriorName ){
623623
defossilize(zPriorName);
624
- if( !file_is_simple_pathname(zPriorName, 0) ){
624
+ if( !file_is_simple_pathname_nonstrict(zPriorName) ){
625625
SYNTAX("F-card old filename is not a simple path");
626626
}
627627
}
628628
if( p->nFile>=p->nFileAlloc ){
629629
p->nFileAlloc = p->nFileAlloc*2 + 10;
630630
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button