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.
Commit
f488a5aa97a3b15f57e13b4a1f060b62b3a5fdf1b1bc1bd0c057cae611d74b7f
Parent
24ecb3bbd566e8b…
1 file changed
+5
-3
+5
-3
| --- src/cgi.c | ||
| +++ src/cgi.c | ||
| @@ -200,22 +200,24 @@ | ||
| 200 | 200 | void cgi_append_header(const char *zLine){ |
| 201 | 201 | blob_append(&extraHeader, zLine, -1); |
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | /* |
| 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. | |
| 206 | 207 | ** |
| 207 | 208 | ** Zero lifetime implies a session cookie. |
| 208 | 209 | */ |
| 209 | 210 | void cgi_set_cookie( |
| 210 | 211 | const char *zName, /* Name of the cookie */ |
| 211 | 212 | const char *zValue, /* Value of the cookie. Automatically escaped */ |
| 212 | 213 | const char *zPath, /* Path cookie applies to. NULL means "/" */ |
| 213 | 214 | int lifetime /* Expiration of the cookie in seconds from now */ |
| 214 | 215 | ){ |
| 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 ){ | |
| 217 | 219 | zPath = g.zTop; |
| 218 | 220 | if( zPath[0]==0 ) zPath = "/"; |
| 219 | 221 | } |
| 220 | 222 | if( g.zBaseURL!=0 && strncmp(g.zBaseURL, "https:", 6)==0 ){ |
| 221 | 223 | zSecure = " secure;"; |
| 222 | 224 |
| --- 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 |