Check-in [396cc2a4eb]
Not logged in
Overview

SHA1 Hash:396cc2a4eb1e99bf889ecaf45e3c25822837b4b4
Date: 2007-07-30 13:34:35
User: drh
Comment:When errors occur during CGI, make sure the error is returned in a correct CGI reply.
Timelines: ancestors | descendants | both | trunk
Other Links: files | ZIP archive | manifest

Tags And Properties
Changes
[hide diffs]

Modified src/db.c from [84850dc1ab] to [73fc8fe15d].

@@ -56,13 +56,24 @@
 /*
 ** Call this routine when a database error occurs.
 */
 static void db_err(const char *zFormat, ...){
   va_list ap;
+  char *z;
   va_start(ap, zFormat);
-  fprintf(stderr, "%s\n", vmprintf(zFormat, ap));
+  z = vmprintf(zFormat, ap);
   va_end(ap);
+  if( g.cgiPanic ){
+    g.cgiPanic = 0;
+    cgi_printf("<p><font color=\"red\">%h</font></p>", z);
+    style_footer();
+    cgi_reply();
+  }else{
+    fprintf(stderr, "%s: %s\n", g.argv[0], z);
+  }
+  db_force_rollback();
+  exit(1);
   exit(1);
 }
 
 static int nBegin = 0;      /* Nesting depth of BEGIN */
 static int doRollback = 0;  /* True to force a rollback */

Modified src/main.c from [e0071db8be] to [66d6462906].

@@ -215,11 +215,11 @@
   va_start(ap, zFormat);
   z = vmprintf(zFormat, ap);
   va_end(ap);
   if( g.cgiPanic ){
     g.cgiPanic = 0;
-    cgi_printf("<p><font color=\"red\">%h</font></p>");
+    cgi_printf("<p><font color=\"red\">%h</font></p>", z);
     style_footer();
     cgi_reply();
   }else{
     fprintf(stderr, "%s: %s\n", g.argv[0], z);
   }
@@ -232,11 +232,11 @@
   va_start(ap, zFormat);
   z = vmprintf(zFormat, ap);
   va_end(ap);
   if( g.cgiPanic ){
     g.cgiPanic = 0;
-    cgi_printf("<p><font color=\"red\">%h</font></p>");
+    cgi_printf("<p><font color=\"red\">%h</font></p>", z);
     style_footer();
     cgi_reply();
   }else{
     fprintf(stderr, "%s: %s\n", g.argv[0], z);
   }
@@ -485,10 +485,11 @@
   if( g.argc==3 && strcmp(g.argv[1],"cgi")==0 ){
     zFile = g.argv[2];
   }else{
     zFile = g.argv[1];
   }
+  g.cgiPanic = 1;
   blob_read_from_file(&config, zFile);
   while( blob_line(&config, &line) ){
     if( !blob_token(&line, &key) ) continue;
     if( blob_buffer(&key)[0]=='#' ) continue;
     if( blob_eq(&key, "debug:") && blob_token(&line, &value) ){