Fossil SCM

Patched cgi_set_cookie() to be a no-op when not running in HTTP(s) mode (e.g. in JSON CLI mode), since g.zTop is not set in that case. Resolves a segfault reported on the ML.

stephan 2018-07-05 16:51 trunk
Commit f488a5aa97a3b15f57e13b4a1f060b62b3a5fdf1b1bc1bd0c057cae611d74b7f
1 file changed +5 -3
+5 -3
--- src/cgi.c
+++ src/cgi.c
@@ -200,22 +200,24 @@
200200
void cgi_append_header(const char *zLine){
201201
blob_append(&extraHeader, zLine, -1);
202202
}
203203
204204
/*
205
-** Set a cookie.
205
+** Set a cookie by queuing up the appropriate HTTP header output. If
206
+** !g.isHTTP, this is a no-op.
206207
**
207208
** Zero lifetime implies a session cookie.
208209
*/
209210
void cgi_set_cookie(
210211
const char *zName, /* Name of the cookie */
211212
const char *zValue, /* Value of the cookie. Automatically escaped */
212213
const char *zPath, /* Path cookie applies to. NULL means "/" */
213214
int lifetime /* Expiration of the cookie in seconds from now */
214215
){
215
- char *zSecure = "";
216
- if( zPath==0 ){
216
+ char const *zSecure = "";
217
+ if(!g.isHTTP) return /* e.g. JSON CLI mode, where g.zTop is not set */;
218
+ else if( zPath==0 ){
217219
zPath = g.zTop;
218220
if( zPath[0]==0 ) zPath = "/";
219221
}
220222
if( g.zBaseURL!=0 && strncmp(g.zBaseURL, "https:", 6)==0 ){
221223
zSecure = " secure;";
222224
--- src/cgi.c
+++ src/cgi.c
@@ -200,22 +200,24 @@
200 void cgi_append_header(const char *zLine){
201 blob_append(&extraHeader, zLine, -1);
202 }
203
204 /*
205 ** Set a cookie.
 
206 **
207 ** Zero lifetime implies a session cookie.
208 */
209 void cgi_set_cookie(
210 const char *zName, /* Name of the cookie */
211 const char *zValue, /* Value of the cookie. Automatically escaped */
212 const char *zPath, /* Path cookie applies to. NULL means "/" */
213 int lifetime /* Expiration of the cookie in seconds from now */
214 ){
215 char *zSecure = "";
216 if( zPath==0 ){
 
217 zPath = g.zTop;
218 if( zPath[0]==0 ) zPath = "/";
219 }
220 if( g.zBaseURL!=0 && strncmp(g.zBaseURL, "https:", 6)==0 ){
221 zSecure = " secure;";
222
--- src/cgi.c
+++ src/cgi.c
@@ -200,22 +200,24 @@
200 void cgi_append_header(const char *zLine){
201 blob_append(&extraHeader, zLine, -1);
202 }
203
204 /*
205 ** Set a cookie by queuing up the appropriate HTTP header output. If
206 ** !g.isHTTP, this is a no-op.
207 **
208 ** Zero lifetime implies a session cookie.
209 */
210 void cgi_set_cookie(
211 const char *zName, /* Name of the cookie */
212 const char *zValue, /* Value of the cookie. Automatically escaped */
213 const char *zPath, /* Path cookie applies to. NULL means "/" */
214 int lifetime /* Expiration of the cookie in seconds from now */
215 ){
216 char const *zSecure = "";
217 if(!g.isHTTP) return /* e.g. JSON CLI mode, where g.zTop is not set */;
218 else if( zPath==0 ){
219 zPath = g.zTop;
220 if( zPath[0]==0 ) zPath = "/";
221 }
222 if( g.zBaseURL!=0 && strncmp(g.zBaseURL, "https:", 6)==0 ){
223 zSecure = " secure;";
224

Keyboard Shortcuts

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