Fossil SCM

When errors occur during CGI, make sure the error is returned in a correct CGI reply.

drh 2007-07-30 13:34 trunk
Commit 396cc2a4eb1e99bf889ecaf45e3c25822837b4b4
2 files changed +12 -1 +3 -2
+12 -1
--- src/db.c
+++ src/db.c
@@ -56,13 +56,24 @@
5656
/*
5757
** Call this routine when a database error occurs.
5858
*/
5959
static void db_err(const char *zFormat, ...){
6060
va_list ap;
61
+ char *z;
6162
va_start(ap, zFormat);
62
- fprintf(stderr, "%s\n", vmprintf(zFormat, ap));
63
+ z = vmprintf(zFormat, ap);
6364
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);
6475
exit(1);
6576
}
6677
6778
static int nBegin = 0; /* Nesting depth of BEGIN */
6879
static int doRollback = 0; /* True to force a rollback */
6980
--- 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 @@
215215
va_start(ap, zFormat);
216216
z = vmprintf(zFormat, ap);
217217
va_end(ap);
218218
if( g.cgiPanic ){
219219
g.cgiPanic = 0;
220
- cgi_printf("<p><font color=\"red\">%h</font></p>");
220
+ cgi_printf("<p><font color=\"red\">%h</font></p>", z);
221221
style_footer();
222222
cgi_reply();
223223
}else{
224224
fprintf(stderr, "%s: %s\n", g.argv[0], z);
225225
}
@@ -232,11 +232,11 @@
232232
va_start(ap, zFormat);
233233
z = vmprintf(zFormat, ap);
234234
va_end(ap);
235235
if( g.cgiPanic ){
236236
g.cgiPanic = 0;
237
- cgi_printf("<p><font color=\"red\">%h</font></p>");
237
+ cgi_printf("<p><font color=\"red\">%h</font></p>", z);
238238
style_footer();
239239
cgi_reply();
240240
}else{
241241
fprintf(stderr, "%s: %s\n", g.argv[0], z);
242242
}
@@ -485,10 +485,11 @@
485485
if( g.argc==3 && strcmp(g.argv[1],"cgi")==0 ){
486486
zFile = g.argv[2];
487487
}else{
488488
zFile = g.argv[1];
489489
}
490
+ g.cgiPanic = 1;
490491
blob_read_from_file(&config, zFile);
491492
while( blob_line(&config, &line) ){
492493
if( !blob_token(&line, &key) ) continue;
493494
if( blob_buffer(&key)[0]=='#' ) continue;
494495
if( blob_eq(&key, "debug:") && blob_token(&line, &value) ){
495496
--- 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

Keyboard Shortcuts

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