Fossil SCM

Make the "fossil git export" command more restrictive about characters that it allows in tag names.

drh 2020-06-08 03:32 trunk
Commit c9a592dde7fe493f16b110b4e87f57441a8b2825d597d2ec2a1c5e9abeff90e9
1 file changed +29 -3
+29 -3
--- src/export.c
+++ src/export.c
@@ -882,15 +882,15 @@
882882
static void gitmirror_sanitize_name(char *z){
883883
static unsigned char aSafe[] = {
884884
/* x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xA xB xC xD xE xF */
885885
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x */
886886
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 1x */
887
- 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 2x */
888
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, /* 3x */
887
+ 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, /* 2x */
888
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, /* 3x */
889889
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 4x */
890890
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, /* 5x */
891
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 6x */
891
+ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 6x */
892892
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, /* 7x */
893893
};
894894
unsigned char *zu = (unsigned char*)z;
895895
int i;
896896
for(i=0; zu[i]; i++){
@@ -902,10 +902,36 @@
902902
|| (i>0 && zu[i-1]=='.')) ){
903903
zu[i] = '_';
904904
}
905905
}
906906
}
907
+
908
+/*
909
+** COMMAND: test-sanitize-name
910
+**
911
+** Usage: %fossil ARG...
912
+**
913
+** This sanitizes each argument and make it part of an "echo" command
914
+** run by the shell.
915
+*/
916
+void test_sanitize_name_cmd(void){
917
+ sqlite3_str *pStr;
918
+ int i;
919
+ char *zCmd;
920
+ pStr = sqlite3_str_new(0);
921
+ sqlite3_str_appendall(pStr, "echo");
922
+ for(i=2; i<g.argc; i++){
923
+ char *z = fossil_strdup(g.argv[i]);
924
+ gitmirror_sanitize_name(z);
925
+ sqlite3_str_appendf(pStr, " \"%s\"", z);
926
+ fossil_free(z);
927
+ }
928
+ zCmd = sqlite3_str_finish(pStr);
929
+ fossil_print("Command: %s\n", zCmd);
930
+ fossil_system(zCmd);
931
+ sqlite3_free(zCmd);
932
+}
907933
908934
/*
909935
** Quote a filename as a C-style string using \\ and \" if necessary.
910936
** If quoting is not necessary, just return a copy of the input string.
911937
**
912938
--- src/export.c
+++ src/export.c
@@ -882,15 +882,15 @@
882 static void gitmirror_sanitize_name(char *z){
883 static unsigned char aSafe[] = {
884 /* x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xA xB xC xD xE xF */
885 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x */
886 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 1x */
887 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 2x */
888 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, /* 3x */
889 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 4x */
890 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, /* 5x */
891 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 6x */
892 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, /* 7x */
893 };
894 unsigned char *zu = (unsigned char*)z;
895 int i;
896 for(i=0; zu[i]; i++){
@@ -902,10 +902,36 @@
902 || (i>0 && zu[i-1]=='.')) ){
903 zu[i] = '_';
904 }
905 }
906 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
907
908 /*
909 ** Quote a filename as a C-style string using \\ and \" if necessary.
910 ** If quoting is not necessary, just return a copy of the input string.
911 **
912
--- src/export.c
+++ src/export.c
@@ -882,15 +882,15 @@
882 static void gitmirror_sanitize_name(char *z){
883 static unsigned char aSafe[] = {
884 /* x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xA xB xC xD xE xF */
885 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x */
886 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 1x */
887 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, /* 2x */
888 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, /* 3x */
889 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 4x */
890 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, /* 5x */
891 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 6x */
892 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, /* 7x */
893 };
894 unsigned char *zu = (unsigned char*)z;
895 int i;
896 for(i=0; zu[i]; i++){
@@ -902,10 +902,36 @@
902 || (i>0 && zu[i-1]=='.')) ){
903 zu[i] = '_';
904 }
905 }
906 }
907
908 /*
909 ** COMMAND: test-sanitize-name
910 **
911 ** Usage: %fossil ARG...
912 **
913 ** This sanitizes each argument and make it part of an "echo" command
914 ** run by the shell.
915 */
916 void test_sanitize_name_cmd(void){
917 sqlite3_str *pStr;
918 int i;
919 char *zCmd;
920 pStr = sqlite3_str_new(0);
921 sqlite3_str_appendall(pStr, "echo");
922 for(i=2; i<g.argc; i++){
923 char *z = fossil_strdup(g.argv[i]);
924 gitmirror_sanitize_name(z);
925 sqlite3_str_appendf(pStr, " \"%s\"", z);
926 fossil_free(z);
927 }
928 zCmd = sqlite3_str_finish(pStr);
929 fossil_print("Command: %s\n", zCmd);
930 fossil_system(zCmd);
931 sqlite3_free(zCmd);
932 }
933
934 /*
935 ** Quote a filename as a C-style string using \\ and \" if necessary.
936 ** If quoting is not necessary, just return a copy of the input string.
937 **
938

Keyboard Shortcuts

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