Fossil SCM

Fix some cases in wikiformat.c where it was assuming that a hash name would be UUID_SIZE or fewer characters, when in fact the size could be as many as HNAME_MAX characters. This is a change that we missed in the SHA3 cut-over.

drh 2017-06-11 04:37 trunk
Commit e0757d270c3c10d46a8aabe1865ec384d878af089d0c917764838452ed2f7b56
1 file changed +6 -6
--- src/wikiformat.c
+++ src/wikiformat.c
@@ -1065,26 +1065,26 @@
10651065
10661066
/*
10671067
** If the input string corresponds to an existing baseline,
10681068
** return true.
10691069
*/
1070
-static int is_valid_uuid(const char *z){
1070
+static int is_valid_hname(const char *z){
10711071
int n = strlen(z);
10721072
if( n<4 || n>HNAME_MAX ) return 0;
10731073
if( !validate16(z, n) ) return 0;
10741074
return 1;
10751075
}
10761076
10771077
/*
1078
-** Return TRUE if a UUID corresponds to an artifact in this
1078
+** Return TRUE if a hash name corresponds to an artifact in this
10791079
** repository.
10801080
*/
10811081
static int in_this_repo(const char *zUuid){
10821082
static Stmt q;
10831083
int rc;
10841084
int n;
1085
- char zU2[UUID_SIZE+1];
1085
+ char zU2[HNAME_MAX+1];
10861086
db_static_prepare(&q,
10871087
"SELECT 1 FROM blob WHERE uuid>=:u AND uuid<:u2"
10881088
);
10891089
db_bind_text(&q, ":u", zUuid);
10901090
n = (int)strlen(zUuid);
@@ -1216,13 +1216,13 @@
12161216
&& (zTarget[1]=='/' || (zTarget[1]=='.' && zTarget[2]=='/'))
12171217
&& (p->state & WIKI_LINKSONLY)==0 ){
12181218
blob_appendf(p->pOut, "<a href=\"%h\">", zTarget);
12191219
}else if( zTarget[0]=='#' ){
12201220
blob_appendf(p->pOut, "<a href=\"%h\">", zTarget);
1221
- }else if( is_valid_uuid(zTarget) ){
1221
+ }else if( is_valid_hname(zTarget) ){
12221222
int isClosed = 0;
1223
- if( is_ticket(zTarget, &isClosed) ){
1223
+ if( strlen(zTarget)<=UUID_SIZE && is_ticket(zTarget, &isClosed) ){
12241224
/* Special display processing for tickets. Display the hyperlink
12251225
** as crossed out if the ticket is closed.
12261226
*/
12271227
if( isClosed ){
12281228
if( g.perm.Hyperlink ){
@@ -1839,11 +1839,11 @@
18391839
zTarget = &z[1];
18401840
for(i=0; zTarget[i] && zTarget[i]!='|' && zTarget[i]!=']'; i++){}
18411841
while(i>1 && zTarget[i-1]==' '){ i--; }
18421842
c = zTarget[i];
18431843
zTarget[i] = 0;
1844
- if( is_valid_uuid(zTarget) ){
1844
+ if( is_valid_hname(zTarget) ){
18451845
memcpy(zLink, zTarget, i+1);
18461846
canonical16(zLink, i);
18471847
db_multi_exec(
18481848
"REPLACE INTO backlink(target,srctype,srcid,mtime)"
18491849
"VALUES(%Q,%d,%d,%g)", zLink, srctype, srcid, mtime
18501850
--- src/wikiformat.c
+++ src/wikiformat.c
@@ -1065,26 +1065,26 @@
1065
1066 /*
1067 ** If the input string corresponds to an existing baseline,
1068 ** return true.
1069 */
1070 static int is_valid_uuid(const char *z){
1071 int n = strlen(z);
1072 if( n<4 || n>HNAME_MAX ) return 0;
1073 if( !validate16(z, n) ) return 0;
1074 return 1;
1075 }
1076
1077 /*
1078 ** Return TRUE if a UUID corresponds to an artifact in this
1079 ** repository.
1080 */
1081 static int in_this_repo(const char *zUuid){
1082 static Stmt q;
1083 int rc;
1084 int n;
1085 char zU2[UUID_SIZE+1];
1086 db_static_prepare(&q,
1087 "SELECT 1 FROM blob WHERE uuid>=:u AND uuid<:u2"
1088 );
1089 db_bind_text(&q, ":u", zUuid);
1090 n = (int)strlen(zUuid);
@@ -1216,13 +1216,13 @@
1216 && (zTarget[1]=='/' || (zTarget[1]=='.' && zTarget[2]=='/'))
1217 && (p->state & WIKI_LINKSONLY)==0 ){
1218 blob_appendf(p->pOut, "<a href=\"%h\">", zTarget);
1219 }else if( zTarget[0]=='#' ){
1220 blob_appendf(p->pOut, "<a href=\"%h\">", zTarget);
1221 }else if( is_valid_uuid(zTarget) ){
1222 int isClosed = 0;
1223 if( is_ticket(zTarget, &isClosed) ){
1224 /* Special display processing for tickets. Display the hyperlink
1225 ** as crossed out if the ticket is closed.
1226 */
1227 if( isClosed ){
1228 if( g.perm.Hyperlink ){
@@ -1839,11 +1839,11 @@
1839 zTarget = &z[1];
1840 for(i=0; zTarget[i] && zTarget[i]!='|' && zTarget[i]!=']'; i++){}
1841 while(i>1 && zTarget[i-1]==' '){ i--; }
1842 c = zTarget[i];
1843 zTarget[i] = 0;
1844 if( is_valid_uuid(zTarget) ){
1845 memcpy(zLink, zTarget, i+1);
1846 canonical16(zLink, i);
1847 db_multi_exec(
1848 "REPLACE INTO backlink(target,srctype,srcid,mtime)"
1849 "VALUES(%Q,%d,%d,%g)", zLink, srctype, srcid, mtime
1850
--- src/wikiformat.c
+++ src/wikiformat.c
@@ -1065,26 +1065,26 @@
1065
1066 /*
1067 ** If the input string corresponds to an existing baseline,
1068 ** return true.
1069 */
1070 static int is_valid_hname(const char *z){
1071 int n = strlen(z);
1072 if( n<4 || n>HNAME_MAX ) return 0;
1073 if( !validate16(z, n) ) return 0;
1074 return 1;
1075 }
1076
1077 /*
1078 ** Return TRUE if a hash name corresponds to an artifact in this
1079 ** repository.
1080 */
1081 static int in_this_repo(const char *zUuid){
1082 static Stmt q;
1083 int rc;
1084 int n;
1085 char zU2[HNAME_MAX+1];
1086 db_static_prepare(&q,
1087 "SELECT 1 FROM blob WHERE uuid>=:u AND uuid<:u2"
1088 );
1089 db_bind_text(&q, ":u", zUuid);
1090 n = (int)strlen(zUuid);
@@ -1216,13 +1216,13 @@
1216 && (zTarget[1]=='/' || (zTarget[1]=='.' && zTarget[2]=='/'))
1217 && (p->state & WIKI_LINKSONLY)==0 ){
1218 blob_appendf(p->pOut, "<a href=\"%h\">", zTarget);
1219 }else if( zTarget[0]=='#' ){
1220 blob_appendf(p->pOut, "<a href=\"%h\">", zTarget);
1221 }else if( is_valid_hname(zTarget) ){
1222 int isClosed = 0;
1223 if( strlen(zTarget)<=UUID_SIZE && is_ticket(zTarget, &isClosed) ){
1224 /* Special display processing for tickets. Display the hyperlink
1225 ** as crossed out if the ticket is closed.
1226 */
1227 if( isClosed ){
1228 if( g.perm.Hyperlink ){
@@ -1839,11 +1839,11 @@
1839 zTarget = &z[1];
1840 for(i=0; zTarget[i] && zTarget[i]!='|' && zTarget[i]!=']'; i++){}
1841 while(i>1 && zTarget[i-1]==' '){ i--; }
1842 c = zTarget[i];
1843 zTarget[i] = 0;
1844 if( is_valid_hname(zTarget) ){
1845 memcpy(zLink, zTarget, i+1);
1846 canonical16(zLink, i);
1847 db_multi_exec(
1848 "REPLACE INTO backlink(target,srctype,srcid,mtime)"
1849 "VALUES(%Q,%d,%d,%g)", zLink, srctype, srcid, mtime
1850

Keyboard Shortcuts

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