Fossil SCM
Make the "fossil git export" command more restrictive about characters that it allows in tag names.
Commit
c9a592dde7fe493f16b110b4e87f57441a8b2825d597d2ec2a1c5e9abeff90e9
Parent
81960e1faab71bf…
1 file changed
+29
-3
+29
-3
| --- src/export.c | ||
| +++ src/export.c | ||
| @@ -882,15 +882,15 @@ | ||
| 882 | 882 | static void gitmirror_sanitize_name(char *z){ |
| 883 | 883 | static unsigned char aSafe[] = { |
| 884 | 884 | /* x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xA xB xC xD xE xF */ |
| 885 | 885 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x */ |
| 886 | 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 */ | |
| 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 | 889 | 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 4x */ |
| 890 | 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 */ | |
| 891 | + 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 6x */ | |
| 892 | 892 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, /* 7x */ |
| 893 | 893 | }; |
| 894 | 894 | unsigned char *zu = (unsigned char*)z; |
| 895 | 895 | int i; |
| 896 | 896 | for(i=0; zu[i]; i++){ |
| @@ -902,10 +902,36 @@ | ||
| 902 | 902 | || (i>0 && zu[i-1]=='.')) ){ |
| 903 | 903 | zu[i] = '_'; |
| 904 | 904 | } |
| 905 | 905 | } |
| 906 | 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 | +} | |
| 907 | 933 | |
| 908 | 934 | /* |
| 909 | 935 | ** Quote a filename as a C-style string using \\ and \" if necessary. |
| 910 | 936 | ** If quoting is not necessary, just return a copy of the input string. |
| 911 | 937 | ** |
| 912 | 938 |
| --- 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 |