Fossil SCM
Any call to fossil_fatal() while generating a webpage changes the output to a 400 Bad Request with an appropriately formatted web page.
Commit
a0863d2b46174995a79f0f8e1c4c0fbf51020513d74152ece711e5b9fb0130d6
Parent
60c8eca305b1ea9…
2 files changed
+1
-1
+10
-4
+1
-1
| --- src/main.c | ||
| +++ src/main.c | ||
| @@ -162,11 +162,11 @@ | ||
| 162 | 162 | const char *zContentType; /* The content type of the input HTTP request */ |
| 163 | 163 | int iErrPriority; /* Priority of current error message */ |
| 164 | 164 | char *zErrMsg; /* Text of an error message */ |
| 165 | 165 | int sslNotAvailable; /* SSL is not available. Do not redirect to https: */ |
| 166 | 166 | Blob cgiIn; /* Input to an xfer www method */ |
| 167 | - int cgiOutput; /* Write error and status messages to CGI */ | |
| 167 | + int cgiOutput; /* 0: command-line 1: CGI. 2: CGI after an error */ | |
| 168 | 168 | int xferPanic; /* Write error messages in XFER protocol */ |
| 169 | 169 | int fullHttpReply; /* True for full HTTP reply. False for CGI reply */ |
| 170 | 170 | Th_Interp *interp; /* The TH1 interpreter */ |
| 171 | 171 | char *th1Setup; /* The TH1 post-creation setup script, if any */ |
| 172 | 172 | int th1Flags; /* The TH1 integration state flags */ |
| 173 | 173 |
| --- src/main.c | |
| +++ src/main.c | |
| @@ -162,11 +162,11 @@ | |
| 162 | const char *zContentType; /* The content type of the input HTTP request */ |
| 163 | int iErrPriority; /* Priority of current error message */ |
| 164 | char *zErrMsg; /* Text of an error message */ |
| 165 | int sslNotAvailable; /* SSL is not available. Do not redirect to https: */ |
| 166 | Blob cgiIn; /* Input to an xfer www method */ |
| 167 | int cgiOutput; /* Write error and status messages to CGI */ |
| 168 | int xferPanic; /* Write error messages in XFER protocol */ |
| 169 | int fullHttpReply; /* True for full HTTP reply. False for CGI reply */ |
| 170 | Th_Interp *interp; /* The TH1 interpreter */ |
| 171 | char *th1Setup; /* The TH1 post-creation setup script, if any */ |
| 172 | int th1Flags; /* The TH1 integration state flags */ |
| 173 |
| --- src/main.c | |
| +++ src/main.c | |
| @@ -162,11 +162,11 @@ | |
| 162 | const char *zContentType; /* The content type of the input HTTP request */ |
| 163 | int iErrPriority; /* Priority of current error message */ |
| 164 | char *zErrMsg; /* Text of an error message */ |
| 165 | int sslNotAvailable; /* SSL is not available. Do not redirect to https: */ |
| 166 | Blob cgiIn; /* Input to an xfer www method */ |
| 167 | int cgiOutput; /* 0: command-line 1: CGI. 2: CGI after an error */ |
| 168 | int xferPanic; /* Write error messages in XFER protocol */ |
| 169 | int fullHttpReply; /* True for full HTTP reply. False for CGI reply */ |
| 170 | Th_Interp *interp; /* The TH1 interpreter */ |
| 171 | char *th1Setup; /* The TH1 post-creation setup script, if any */ |
| 172 | int th1Flags; /* The TH1 integration state flags */ |
| 173 |
+10
-4
| --- src/printf.c | ||
| +++ src/printf.c | ||
| @@ -1056,10 +1056,11 @@ | ||
| 1056 | 1056 | else |
| 1057 | 1057 | #endif |
| 1058 | 1058 | { |
| 1059 | 1059 | if( g.cgiOutput ){ |
| 1060 | 1060 | cgi_printf("<p class=\"generalError\">%h</p>", z); |
| 1061 | + cgi_set_status(500, "Internal Server Error"); | |
| 1061 | 1062 | cgi_reply(); |
| 1062 | 1063 | }else if( !g.fQuiet ){ |
| 1063 | 1064 | fossil_force_newline(); |
| 1064 | 1065 | fossil_puts("Fossil internal error: ", 1); |
| 1065 | 1066 | fossil_puts(z, 1); |
| @@ -1086,20 +1087,24 @@ | ||
| 1086 | 1087 | } |
| 1087 | 1088 | } |
| 1088 | 1089 | else |
| 1089 | 1090 | #endif |
| 1090 | 1091 | { |
| 1091 | - if( g.cgiOutput ){ | |
| 1092 | - g.cgiOutput = 0; | |
| 1093 | - cgi_printf("<p class=\"generalError\">\n%h\n</p>\n", z); | |
| 1092 | + if( g.cgiOutput==1 ){ | |
| 1093 | + g.cgiOutput = 2; | |
| 1094 | + cgi_reset_content(); | |
| 1095 | + style_header("Bad Request"); | |
| 1096 | + @ <p class="generalError">%h(z)</p> | |
| 1097 | + cgi_set_status(400, "Bad Request"); | |
| 1098 | + style_footer(); | |
| 1094 | 1099 | cgi_reply(); |
| 1095 | 1100 | }else if( !g.fQuiet ){ |
| 1096 | 1101 | fossil_force_newline(); |
| 1097 | 1102 | fossil_trace("%s\n", z); |
| 1098 | 1103 | } |
| 1099 | 1104 | } |
| 1100 | - free(z); | |
| 1105 | + fossil_free(z); | |
| 1101 | 1106 | db_force_rollback(); |
| 1102 | 1107 | fossil_exit(rc); |
| 1103 | 1108 | } |
| 1104 | 1109 | |
| 1105 | 1110 | /* This routine works like fossil_fatal() except that if called |
| @@ -1131,10 +1136,11 @@ | ||
| 1131 | 1136 | #endif |
| 1132 | 1137 | { |
| 1133 | 1138 | if( g.cgiOutput ){ |
| 1134 | 1139 | g.cgiOutput = 0; |
| 1135 | 1140 | cgi_printf("<p class=\"generalError\">\n%h\n</p>\n", z); |
| 1141 | + cgi_set_status(400, "Bad Request"); | |
| 1136 | 1142 | cgi_reply(); |
| 1137 | 1143 | }else{ |
| 1138 | 1144 | fossil_force_newline(); |
| 1139 | 1145 | fossil_trace("%s\n", z); |
| 1140 | 1146 | } |
| 1141 | 1147 |
| --- src/printf.c | |
| +++ src/printf.c | |
| @@ -1056,10 +1056,11 @@ | |
| 1056 | else |
| 1057 | #endif |
| 1058 | { |
| 1059 | if( g.cgiOutput ){ |
| 1060 | cgi_printf("<p class=\"generalError\">%h</p>", z); |
| 1061 | cgi_reply(); |
| 1062 | }else if( !g.fQuiet ){ |
| 1063 | fossil_force_newline(); |
| 1064 | fossil_puts("Fossil internal error: ", 1); |
| 1065 | fossil_puts(z, 1); |
| @@ -1086,20 +1087,24 @@ | |
| 1086 | } |
| 1087 | } |
| 1088 | else |
| 1089 | #endif |
| 1090 | { |
| 1091 | if( g.cgiOutput ){ |
| 1092 | g.cgiOutput = 0; |
| 1093 | cgi_printf("<p class=\"generalError\">\n%h\n</p>\n", z); |
| 1094 | cgi_reply(); |
| 1095 | }else if( !g.fQuiet ){ |
| 1096 | fossil_force_newline(); |
| 1097 | fossil_trace("%s\n", z); |
| 1098 | } |
| 1099 | } |
| 1100 | free(z); |
| 1101 | db_force_rollback(); |
| 1102 | fossil_exit(rc); |
| 1103 | } |
| 1104 | |
| 1105 | /* This routine works like fossil_fatal() except that if called |
| @@ -1131,10 +1136,11 @@ | |
| 1131 | #endif |
| 1132 | { |
| 1133 | if( g.cgiOutput ){ |
| 1134 | g.cgiOutput = 0; |
| 1135 | cgi_printf("<p class=\"generalError\">\n%h\n</p>\n", z); |
| 1136 | cgi_reply(); |
| 1137 | }else{ |
| 1138 | fossil_force_newline(); |
| 1139 | fossil_trace("%s\n", z); |
| 1140 | } |
| 1141 |
| --- src/printf.c | |
| +++ src/printf.c | |
| @@ -1056,10 +1056,11 @@ | |
| 1056 | else |
| 1057 | #endif |
| 1058 | { |
| 1059 | if( g.cgiOutput ){ |
| 1060 | cgi_printf("<p class=\"generalError\">%h</p>", z); |
| 1061 | cgi_set_status(500, "Internal Server Error"); |
| 1062 | cgi_reply(); |
| 1063 | }else if( !g.fQuiet ){ |
| 1064 | fossil_force_newline(); |
| 1065 | fossil_puts("Fossil internal error: ", 1); |
| 1066 | fossil_puts(z, 1); |
| @@ -1086,20 +1087,24 @@ | |
| 1087 | } |
| 1088 | } |
| 1089 | else |
| 1090 | #endif |
| 1091 | { |
| 1092 | if( g.cgiOutput==1 ){ |
| 1093 | g.cgiOutput = 2; |
| 1094 | cgi_reset_content(); |
| 1095 | style_header("Bad Request"); |
| 1096 | @ <p class="generalError">%h(z)</p> |
| 1097 | cgi_set_status(400, "Bad Request"); |
| 1098 | style_footer(); |
| 1099 | cgi_reply(); |
| 1100 | }else if( !g.fQuiet ){ |
| 1101 | fossil_force_newline(); |
| 1102 | fossil_trace("%s\n", z); |
| 1103 | } |
| 1104 | } |
| 1105 | fossil_free(z); |
| 1106 | db_force_rollback(); |
| 1107 | fossil_exit(rc); |
| 1108 | } |
| 1109 | |
| 1110 | /* This routine works like fossil_fatal() except that if called |
| @@ -1131,10 +1136,11 @@ | |
| 1136 | #endif |
| 1137 | { |
| 1138 | if( g.cgiOutput ){ |
| 1139 | g.cgiOutput = 0; |
| 1140 | cgi_printf("<p class=\"generalError\">\n%h\n</p>\n", z); |
| 1141 | cgi_set_status(400, "Bad Request"); |
| 1142 | cgi_reply(); |
| 1143 | }else{ |
| 1144 | fossil_force_newline(); |
| 1145 | fossil_trace("%s\n", z); |
| 1146 | } |
| 1147 |