Fossil SCM
When errors occur during CGI, make sure the error is returned in a correct CGI reply.
Commit
396cc2a4eb1e99bf889ecaf45e3c25822837b4b4
Parent
5eac33a6bdc2779…
2 files changed
+12
-1
+3
-2
M
src/db.c
+12
-1
| --- src/db.c | ||
| +++ src/db.c | ||
| @@ -56,13 +56,24 @@ | ||
| 56 | 56 | /* |
| 57 | 57 | ** Call this routine when a database error occurs. |
| 58 | 58 | */ |
| 59 | 59 | static void db_err(const char *zFormat, ...){ |
| 60 | 60 | va_list ap; |
| 61 | + char *z; | |
| 61 | 62 | va_start(ap, zFormat); |
| 62 | - fprintf(stderr, "%s\n", vmprintf(zFormat, ap)); | |
| 63 | + z = vmprintf(zFormat, ap); | |
| 63 | 64 | va_end(ap); |
| 65 | + if( g.cgiPanic ){ | |
| 66 | + g.cgiPanic = 0; | |
| 67 | + cgi_printf("<p><font color=\"red\">%h</font></p>", z); | |
| 68 | + style_footer(); | |
| 69 | + cgi_reply(); | |
| 70 | + }else{ | |
| 71 | + fprintf(stderr, "%s: %s\n", g.argv[0], z); | |
| 72 | + } | |
| 73 | + db_force_rollback(); | |
| 74 | + exit(1); | |
| 64 | 75 | exit(1); |
| 65 | 76 | } |
| 66 | 77 | |
| 67 | 78 | static int nBegin = 0; /* Nesting depth of BEGIN */ |
| 68 | 79 | static int doRollback = 0; /* True to force a rollback */ |
| 69 | 80 |
| --- src/db.c | |
| +++ src/db.c | |
| @@ -56,13 +56,24 @@ | |
| 56 | /* |
| 57 | ** Call this routine when a database error occurs. |
| 58 | */ |
| 59 | static void db_err(const char *zFormat, ...){ |
| 60 | va_list ap; |
| 61 | va_start(ap, zFormat); |
| 62 | fprintf(stderr, "%s\n", vmprintf(zFormat, ap)); |
| 63 | va_end(ap); |
| 64 | exit(1); |
| 65 | } |
| 66 | |
| 67 | static int nBegin = 0; /* Nesting depth of BEGIN */ |
| 68 | static int doRollback = 0; /* True to force a rollback */ |
| 69 |
| --- src/db.c | |
| +++ src/db.c | |
| @@ -56,13 +56,24 @@ | |
| 56 | /* |
| 57 | ** Call this routine when a database error occurs. |
| 58 | */ |
| 59 | static void db_err(const char *zFormat, ...){ |
| 60 | va_list ap; |
| 61 | char *z; |
| 62 | va_start(ap, zFormat); |
| 63 | z = vmprintf(zFormat, ap); |
| 64 | va_end(ap); |
| 65 | if( g.cgiPanic ){ |
| 66 | g.cgiPanic = 0; |
| 67 | cgi_printf("<p><font color=\"red\">%h</font></p>", z); |
| 68 | style_footer(); |
| 69 | cgi_reply(); |
| 70 | }else{ |
| 71 | fprintf(stderr, "%s: %s\n", g.argv[0], z); |
| 72 | } |
| 73 | db_force_rollback(); |
| 74 | exit(1); |
| 75 | exit(1); |
| 76 | } |
| 77 | |
| 78 | static int nBegin = 0; /* Nesting depth of BEGIN */ |
| 79 | static int doRollback = 0; /* True to force a rollback */ |
| 80 |
+3
-2
| --- src/main.c | ||
| +++ src/main.c | ||
| @@ -215,11 +215,11 @@ | ||
| 215 | 215 | va_start(ap, zFormat); |
| 216 | 216 | z = vmprintf(zFormat, ap); |
| 217 | 217 | va_end(ap); |
| 218 | 218 | if( g.cgiPanic ){ |
| 219 | 219 | g.cgiPanic = 0; |
| 220 | - cgi_printf("<p><font color=\"red\">%h</font></p>"); | |
| 220 | + cgi_printf("<p><font color=\"red\">%h</font></p>", z); | |
| 221 | 221 | style_footer(); |
| 222 | 222 | cgi_reply(); |
| 223 | 223 | }else{ |
| 224 | 224 | fprintf(stderr, "%s: %s\n", g.argv[0], z); |
| 225 | 225 | } |
| @@ -232,11 +232,11 @@ | ||
| 232 | 232 | va_start(ap, zFormat); |
| 233 | 233 | z = vmprintf(zFormat, ap); |
| 234 | 234 | va_end(ap); |
| 235 | 235 | if( g.cgiPanic ){ |
| 236 | 236 | g.cgiPanic = 0; |
| 237 | - cgi_printf("<p><font color=\"red\">%h</font></p>"); | |
| 237 | + cgi_printf("<p><font color=\"red\">%h</font></p>", z); | |
| 238 | 238 | style_footer(); |
| 239 | 239 | cgi_reply(); |
| 240 | 240 | }else{ |
| 241 | 241 | fprintf(stderr, "%s: %s\n", g.argv[0], z); |
| 242 | 242 | } |
| @@ -485,10 +485,11 @@ | ||
| 485 | 485 | if( g.argc==3 && strcmp(g.argv[1],"cgi")==0 ){ |
| 486 | 486 | zFile = g.argv[2]; |
| 487 | 487 | }else{ |
| 488 | 488 | zFile = g.argv[1]; |
| 489 | 489 | } |
| 490 | + g.cgiPanic = 1; | |
| 490 | 491 | blob_read_from_file(&config, zFile); |
| 491 | 492 | while( blob_line(&config, &line) ){ |
| 492 | 493 | if( !blob_token(&line, &key) ) continue; |
| 493 | 494 | if( blob_buffer(&key)[0]=='#' ) continue; |
| 494 | 495 | if( blob_eq(&key, "debug:") && blob_token(&line, &value) ){ |
| 495 | 496 |
| --- src/main.c | |
| +++ src/main.c | |
| @@ -215,11 +215,11 @@ | |
| 215 | va_start(ap, zFormat); |
| 216 | z = vmprintf(zFormat, ap); |
| 217 | va_end(ap); |
| 218 | if( g.cgiPanic ){ |
| 219 | g.cgiPanic = 0; |
| 220 | cgi_printf("<p><font color=\"red\">%h</font></p>"); |
| 221 | style_footer(); |
| 222 | cgi_reply(); |
| 223 | }else{ |
| 224 | fprintf(stderr, "%s: %s\n", g.argv[0], z); |
| 225 | } |
| @@ -232,11 +232,11 @@ | |
| 232 | va_start(ap, zFormat); |
| 233 | z = vmprintf(zFormat, ap); |
| 234 | va_end(ap); |
| 235 | if( g.cgiPanic ){ |
| 236 | g.cgiPanic = 0; |
| 237 | cgi_printf("<p><font color=\"red\">%h</font></p>"); |
| 238 | style_footer(); |
| 239 | cgi_reply(); |
| 240 | }else{ |
| 241 | fprintf(stderr, "%s: %s\n", g.argv[0], z); |
| 242 | } |
| @@ -485,10 +485,11 @@ | |
| 485 | if( g.argc==3 && strcmp(g.argv[1],"cgi")==0 ){ |
| 486 | zFile = g.argv[2]; |
| 487 | }else{ |
| 488 | zFile = g.argv[1]; |
| 489 | } |
| 490 | blob_read_from_file(&config, zFile); |
| 491 | while( blob_line(&config, &line) ){ |
| 492 | if( !blob_token(&line, &key) ) continue; |
| 493 | if( blob_buffer(&key)[0]=='#' ) continue; |
| 494 | if( blob_eq(&key, "debug:") && blob_token(&line, &value) ){ |
| 495 |
| --- src/main.c | |
| +++ src/main.c | |
| @@ -215,11 +215,11 @@ | |
| 215 | va_start(ap, zFormat); |
| 216 | z = vmprintf(zFormat, ap); |
| 217 | va_end(ap); |
| 218 | if( g.cgiPanic ){ |
| 219 | g.cgiPanic = 0; |
| 220 | cgi_printf("<p><font color=\"red\">%h</font></p>", z); |
| 221 | style_footer(); |
| 222 | cgi_reply(); |
| 223 | }else{ |
| 224 | fprintf(stderr, "%s: %s\n", g.argv[0], z); |
| 225 | } |
| @@ -232,11 +232,11 @@ | |
| 232 | va_start(ap, zFormat); |
| 233 | z = vmprintf(zFormat, ap); |
| 234 | va_end(ap); |
| 235 | if( g.cgiPanic ){ |
| 236 | g.cgiPanic = 0; |
| 237 | cgi_printf("<p><font color=\"red\">%h</font></p>", z); |
| 238 | style_footer(); |
| 239 | cgi_reply(); |
| 240 | }else{ |
| 241 | fprintf(stderr, "%s: %s\n", g.argv[0], z); |
| 242 | } |
| @@ -485,10 +485,11 @@ | |
| 485 | if( g.argc==3 && strcmp(g.argv[1],"cgi")==0 ){ |
| 486 | zFile = g.argv[2]; |
| 487 | }else{ |
| 488 | zFile = g.argv[1]; |
| 489 | } |
| 490 | g.cgiPanic = 1; |
| 491 | blob_read_from_file(&config, zFile); |
| 492 | while( blob_line(&config, &line) ){ |
| 493 | if( !blob_token(&line, &key) ) continue; |
| 494 | if( blob_buffer(&key)[0]=='#' ) continue; |
| 495 | if( blob_eq(&key, "debug:") && blob_token(&line, &value) ){ |
| 496 |