Fossil SCM

Make sure the TH1 interp is available before trying to use it.

mistachkin 2019-02-17 07:47 dynamicCsp
Commit 600accbec3aeff10fee269a0957cf68c8f81e19f6fb0badd088f87b54b8a2d20
2 files changed +6 -8 +14
+6 -8
--- src/style.c
+++ src/style.c
@@ -410,18 +410,16 @@
410410
/*
411411
** Do not overwrite the TH1 variable "default_csp" if it exists, as this
412412
** allows it to be properly overridden via the TH1 setup script (i.e. it
413413
** is evaluated before the header is rendered).
414414
*/
415
- if( !Th_ExistsVar(g.interp, "default_csp", -1) ){
416
- char *zDfltCsp = sqlite3_mprintf("default-src 'self' data: ; "
417
- "script-src 'self' 'nonce-%s' ; "
418
- "style-src 'self' 'unsafe-inline'",
419
- zNonce);
420
- Th_Store("default_csp", zDfltCsp);
421
- sqlite3_free(zDfltCsp);
422
- }
415
+ char *zDfltCsp = sqlite3_mprintf("default-src 'self' data: ; "
416
+ "script-src 'self' 'nonce-%s' ; "
417
+ "style-src 'self' 'unsafe-inline'",
418
+ zNonce);
419
+ Th_MaybeStore("default_csp", zDfltCsp);
420
+ sqlite3_free(zDfltCsp);
423421
Th_Store("nonce", zNonce);
424422
Th_Store("project_name", db_get("project-name","Unnamed Fossil Project"));
425423
Th_Store("project_description", db_get("project-description",""));
426424
if( zTitle ) Th_Store("title", zTitle);
427425
Th_Store("baseurl", g.zBaseURL);
428426
--- src/style.c
+++ src/style.c
@@ -410,18 +410,16 @@
410 /*
411 ** Do not overwrite the TH1 variable "default_csp" if it exists, as this
412 ** allows it to be properly overridden via the TH1 setup script (i.e. it
413 ** is evaluated before the header is rendered).
414 */
415 if( !Th_ExistsVar(g.interp, "default_csp", -1) ){
416 char *zDfltCsp = sqlite3_mprintf("default-src 'self' data: ; "
417 "script-src 'self' 'nonce-%s' ; "
418 "style-src 'self' 'unsafe-inline'",
419 zNonce);
420 Th_Store("default_csp", zDfltCsp);
421 sqlite3_free(zDfltCsp);
422 }
423 Th_Store("nonce", zNonce);
424 Th_Store("project_name", db_get("project-name","Unnamed Fossil Project"));
425 Th_Store("project_description", db_get("project-description",""));
426 if( zTitle ) Th_Store("title", zTitle);
427 Th_Store("baseurl", g.zBaseURL);
428
--- src/style.c
+++ src/style.c
@@ -410,18 +410,16 @@
410 /*
411 ** Do not overwrite the TH1 variable "default_csp" if it exists, as this
412 ** allows it to be properly overridden via the TH1 setup script (i.e. it
413 ** is evaluated before the header is rendered).
414 */
415 char *zDfltCsp = sqlite3_mprintf("default-src 'self' data: ; "
416 "script-src 'self' 'nonce-%s' ; "
417 "style-src 'self' 'unsafe-inline'",
418 zNonce);
419 Th_MaybeStore("default_csp", zDfltCsp);
420 sqlite3_free(zDfltCsp);
 
 
421 Th_Store("nonce", zNonce);
422 Th_Store("project_name", db_get("project-name","Unnamed Fossil Project"));
423 Th_Store("project_description", db_get("project-description",""));
424 if( zTitle ) Th_Store("title", zTitle);
425 Th_Store("baseurl", g.zBaseURL);
426
--- src/th_main.c
+++ src/th_main.c
@@ -2125,10 +2125,24 @@
21252125
}
21262126
}
21272127
g.th1Flags &= ~TH_INIT_MASK;
21282128
g.th1Flags |= (flags & TH_INIT_MASK);
21292129
}
2130
+
2131
+/*
2132
+** Store a string value in a variable in the interpreter if the variable
2133
+** does not already exist.
2134
+*/
2135
+void Th_MaybeStore(const char *zName, const char *zValue){
2136
+ Th_FossilInit(TH_INIT_DEFAULT);
2137
+ if( zValue && !Th_ExistsVar(g.interp, zName, -1) ){
2138
+ if( g.thTrace ){
2139
+ Th_Trace("maybe_set %h {%h}<br />\n", zName, zValue);
2140
+ }
2141
+ Th_SetVar(g.interp, zName, -1, zValue, strlen(zValue));
2142
+ }
2143
+}
21302144
21312145
/*
21322146
** Store a string value in a variable in the interpreter.
21332147
*/
21342148
void Th_Store(const char *zName, const char *zValue){
21352149
--- src/th_main.c
+++ src/th_main.c
@@ -2125,10 +2125,24 @@
2125 }
2126 }
2127 g.th1Flags &= ~TH_INIT_MASK;
2128 g.th1Flags |= (flags & TH_INIT_MASK);
2129 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2130
2131 /*
2132 ** Store a string value in a variable in the interpreter.
2133 */
2134 void Th_Store(const char *zName, const char *zValue){
2135
--- src/th_main.c
+++ src/th_main.c
@@ -2125,10 +2125,24 @@
2125 }
2126 }
2127 g.th1Flags &= ~TH_INIT_MASK;
2128 g.th1Flags |= (flags & TH_INIT_MASK);
2129 }
2130
2131 /*
2132 ** Store a string value in a variable in the interpreter if the variable
2133 ** does not already exist.
2134 */
2135 void Th_MaybeStore(const char *zName, const char *zValue){
2136 Th_FossilInit(TH_INIT_DEFAULT);
2137 if( zValue && !Th_ExistsVar(g.interp, zName, -1) ){
2138 if( g.thTrace ){
2139 Th_Trace("maybe_set %h {%h}<br />\n", zName, zValue);
2140 }
2141 Th_SetVar(g.interp, zName, -1, zValue, strlen(zValue));
2142 }
2143 }
2144
2145 /*
2146 ** Store a string value in a variable in the interpreter.
2147 */
2148 void Th_Store(const char *zName, const char *zValue){
2149

Keyboard Shortcuts

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