Fossil SCM

Set a default timeout on CGI requests of 300 seconds.

drh 2019-08-13 19:31 trunk
Commit 859d6b16949351dc81b5c1066e3e6f29290ef2ffcc94e37335b4ec6a1d2e07bc
1 file changed +35 -7
+35 -7
--- src/main.c
+++ src/main.c
@@ -1947,10 +1947,13 @@
19471947
**
19481948
** debug: FILE Causing debugging information to be written
19491949
** into FILE.
19501950
**
19511951
** errorlog: FILE Warnings, errors, and panics written to FILE.
1952
+**
1953
+** timeout: SECONDS Do not run for longer than SECONDS. The default
1954
+** timeout is 300 seconds.
19521955
**
19531956
** extroot: DIR Directory that is the root of the sub-CGI tree
19541957
** on the /ext page.
19551958
**
19561959
** redirect: REPO URL Extract the "name" query parameter and search
@@ -1981,10 +1984,11 @@
19811984
g.httpOut = stdout;
19821985
g.httpIn = stdin;
19831986
fossil_binary_mode(g.httpOut);
19841987
fossil_binary_mode(g.httpIn);
19851988
g.cgiOutput = 1;
1989
+ fossil_set_timeout(300);
19861990
blob_read_from_file(&config, zFile, ExtFILE);
19871991
while( blob_line(&config, &line) ){
19881992
if( !blob_token(&line, &key) ) continue;
19891993
if( blob_buffer(&key)[0]=='#' ) continue;
19901994
if( blob_eq(&key, "repository:") && blob_tail(&line, &value) ){
@@ -2105,10 +2109,19 @@
21052109
** Enables the /ext webpage to use sub-cgi rooted at DIRECTORY
21062110
*/
21072111
g.zExtRoot = mprintf("%s", blob_str(&value));
21082112
blob_reset(&value);
21092113
continue;
2114
+ }
2115
+ if( blob_eq(&key, "timeout:") && blob_token(&line, &value) ){
2116
+ /* timeout: SECONDS
2117
+ **
2118
+ ** Set an alarm() that kills the process after SECONDS. The
2119
+ ** default value is 300 seconds.
2120
+ */
2121
+ fossil_set_timeout(atoi(blob_str(&value)));
2122
+ continue;
21102123
}
21112124
if( blob_eq(&key, "HOME:") && blob_token(&line, &value) ){
21122125
/* HOME: VALUE
21132126
**
21142127
** Set CGI parameter "HOME" to VALUE. This is legacy. Use
@@ -2453,15 +2466,31 @@
24532466
}
24542467
#endif
24552468
#endif
24562469
24572470
/*
2458
-** Send a time-out reply
2471
+** Respond to a SIGALRM by writing a message to the error log (if there
2472
+** is one) and exiting.
24592473
*/
2460
-void sigalrm_handler(int x){
2474
+static void sigalrm_handler(int x){
24612475
fossil_panic("TIMEOUT");
24622476
}
2477
+
2478
+/*
2479
+** Arrange to timeout using SIGALRM after N seconds. Or if N==0, cancel
2480
+** any pending timeout.
2481
+**
2482
+** Bugs:
2483
+** (1) This only works on unix systems.
2484
+** (2) Any call to sleep() or sqlite3_sleep() will cancel the alarm.
2485
+*/
2486
+void fossil_set_timeout(int N){
2487
+#ifndef _WIN32
2488
+ signal(SIGALRM, sigalrm_handler);
2489
+ alarm(N);
2490
+#endif
2491
+}
24632492
24642493
/*
24652494
** COMMAND: server*
24662495
** COMMAND: ui
24672496
**
@@ -2539,11 +2568,11 @@
25392568
int isUiCmd; /* True if command is "ui", not "server' */
25402569
const char *zNotFound; /* The --notfound option or NULL */
25412570
int flags = 0; /* Server flags */
25422571
#if !defined(_WIN32)
25432572
int noJail; /* Do not enter the chroot jail */
2544
- const char *zMaxLatency; /* Maximum runtime of any single HTTP request */
2573
+ const char *zTimeout = "300"; /* Max runtime of any single HTTP request */
25452574
#endif
25462575
int allowRepoList; /* List repositories on URL "/" */
25472576
const char *zAltBase; /* Argument to the --baseurl option */
25482577
const char *zFileGlob; /* Static content must match this */
25492578
char *zIpAddr = 0; /* Bind to this IP address */
@@ -2571,11 +2600,11 @@
25712600
zFileGlob = find_option("files",0,1);
25722601
}
25732602
skin_override();
25742603
#if !defined(_WIN32)
25752604
noJail = find_option("nojail",0,0)!=0;
2576
- zMaxLatency = find_option("max-latency",0,1);
2605
+ zTimeout = find_option("max-latency",0,1);
25772606
#endif
25782607
g.useLocalauth = find_option("localauth", 0, 0)!=0;
25792608
Th_InitTraceLog();
25802609
zPort = find_option("port", "P", 1);
25812610
isUiCmd = g.argv[1][0]=='u';
@@ -2689,13 +2718,12 @@
26892718
**
26902719
** So, when control reaches this point, we are running as a
26912720
** child process, the HTTP or SCGI request is pending on file
26922721
** descriptor 0 and the reply should be written to file descriptor 1.
26932722
*/
2694
- if( zMaxLatency ){
2695
- signal(SIGALRM, sigalrm_handler);
2696
- alarm(atoi(zMaxLatency));
2723
+ if( zTimeout ){
2724
+ fossil_set_timeout(atoi(zTimeout));
26972725
}
26982726
g.httpIn = stdin;
26992727
g.httpOut = stdout;
27002728
27012729
#if !defined(_WIN32)
27022730
--- src/main.c
+++ src/main.c
@@ -1947,10 +1947,13 @@
1947 **
1948 ** debug: FILE Causing debugging information to be written
1949 ** into FILE.
1950 **
1951 ** errorlog: FILE Warnings, errors, and panics written to FILE.
 
 
 
1952 **
1953 ** extroot: DIR Directory that is the root of the sub-CGI tree
1954 ** on the /ext page.
1955 **
1956 ** redirect: REPO URL Extract the "name" query parameter and search
@@ -1981,10 +1984,11 @@
1981 g.httpOut = stdout;
1982 g.httpIn = stdin;
1983 fossil_binary_mode(g.httpOut);
1984 fossil_binary_mode(g.httpIn);
1985 g.cgiOutput = 1;
 
1986 blob_read_from_file(&config, zFile, ExtFILE);
1987 while( blob_line(&config, &line) ){
1988 if( !blob_token(&line, &key) ) continue;
1989 if( blob_buffer(&key)[0]=='#' ) continue;
1990 if( blob_eq(&key, "repository:") && blob_tail(&line, &value) ){
@@ -2105,10 +2109,19 @@
2105 ** Enables the /ext webpage to use sub-cgi rooted at DIRECTORY
2106 */
2107 g.zExtRoot = mprintf("%s", blob_str(&value));
2108 blob_reset(&value);
2109 continue;
 
 
 
 
 
 
 
 
 
2110 }
2111 if( blob_eq(&key, "HOME:") && blob_token(&line, &value) ){
2112 /* HOME: VALUE
2113 **
2114 ** Set CGI parameter "HOME" to VALUE. This is legacy. Use
@@ -2453,15 +2466,31 @@
2453 }
2454 #endif
2455 #endif
2456
2457 /*
2458 ** Send a time-out reply
 
2459 */
2460 void sigalrm_handler(int x){
2461 fossil_panic("TIMEOUT");
2462 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2463
2464 /*
2465 ** COMMAND: server*
2466 ** COMMAND: ui
2467 **
@@ -2539,11 +2568,11 @@
2539 int isUiCmd; /* True if command is "ui", not "server' */
2540 const char *zNotFound; /* The --notfound option or NULL */
2541 int flags = 0; /* Server flags */
2542 #if !defined(_WIN32)
2543 int noJail; /* Do not enter the chroot jail */
2544 const char *zMaxLatency; /* Maximum runtime of any single HTTP request */
2545 #endif
2546 int allowRepoList; /* List repositories on URL "/" */
2547 const char *zAltBase; /* Argument to the --baseurl option */
2548 const char *zFileGlob; /* Static content must match this */
2549 char *zIpAddr = 0; /* Bind to this IP address */
@@ -2571,11 +2600,11 @@
2571 zFileGlob = find_option("files",0,1);
2572 }
2573 skin_override();
2574 #if !defined(_WIN32)
2575 noJail = find_option("nojail",0,0)!=0;
2576 zMaxLatency = find_option("max-latency",0,1);
2577 #endif
2578 g.useLocalauth = find_option("localauth", 0, 0)!=0;
2579 Th_InitTraceLog();
2580 zPort = find_option("port", "P", 1);
2581 isUiCmd = g.argv[1][0]=='u';
@@ -2689,13 +2718,12 @@
2689 **
2690 ** So, when control reaches this point, we are running as a
2691 ** child process, the HTTP or SCGI request is pending on file
2692 ** descriptor 0 and the reply should be written to file descriptor 1.
2693 */
2694 if( zMaxLatency ){
2695 signal(SIGALRM, sigalrm_handler);
2696 alarm(atoi(zMaxLatency));
2697 }
2698 g.httpIn = stdin;
2699 g.httpOut = stdout;
2700
2701 #if !defined(_WIN32)
2702
--- src/main.c
+++ src/main.c
@@ -1947,10 +1947,13 @@
1947 **
1948 ** debug: FILE Causing debugging information to be written
1949 ** into FILE.
1950 **
1951 ** errorlog: FILE Warnings, errors, and panics written to FILE.
1952 **
1953 ** timeout: SECONDS Do not run for longer than SECONDS. The default
1954 ** timeout is 300 seconds.
1955 **
1956 ** extroot: DIR Directory that is the root of the sub-CGI tree
1957 ** on the /ext page.
1958 **
1959 ** redirect: REPO URL Extract the "name" query parameter and search
@@ -1981,10 +1984,11 @@
1984 g.httpOut = stdout;
1985 g.httpIn = stdin;
1986 fossil_binary_mode(g.httpOut);
1987 fossil_binary_mode(g.httpIn);
1988 g.cgiOutput = 1;
1989 fossil_set_timeout(300);
1990 blob_read_from_file(&config, zFile, ExtFILE);
1991 while( blob_line(&config, &line) ){
1992 if( !blob_token(&line, &key) ) continue;
1993 if( blob_buffer(&key)[0]=='#' ) continue;
1994 if( blob_eq(&key, "repository:") && blob_tail(&line, &value) ){
@@ -2105,10 +2109,19 @@
2109 ** Enables the /ext webpage to use sub-cgi rooted at DIRECTORY
2110 */
2111 g.zExtRoot = mprintf("%s", blob_str(&value));
2112 blob_reset(&value);
2113 continue;
2114 }
2115 if( blob_eq(&key, "timeout:") && blob_token(&line, &value) ){
2116 /* timeout: SECONDS
2117 **
2118 ** Set an alarm() that kills the process after SECONDS. The
2119 ** default value is 300 seconds.
2120 */
2121 fossil_set_timeout(atoi(blob_str(&value)));
2122 continue;
2123 }
2124 if( blob_eq(&key, "HOME:") && blob_token(&line, &value) ){
2125 /* HOME: VALUE
2126 **
2127 ** Set CGI parameter "HOME" to VALUE. This is legacy. Use
@@ -2453,15 +2466,31 @@
2466 }
2467 #endif
2468 #endif
2469
2470 /*
2471 ** Respond to a SIGALRM by writing a message to the error log (if there
2472 ** is one) and exiting.
2473 */
2474 static void sigalrm_handler(int x){
2475 fossil_panic("TIMEOUT");
2476 }
2477
2478 /*
2479 ** Arrange to timeout using SIGALRM after N seconds. Or if N==0, cancel
2480 ** any pending timeout.
2481 **
2482 ** Bugs:
2483 ** (1) This only works on unix systems.
2484 ** (2) Any call to sleep() or sqlite3_sleep() will cancel the alarm.
2485 */
2486 void fossil_set_timeout(int N){
2487 #ifndef _WIN32
2488 signal(SIGALRM, sigalrm_handler);
2489 alarm(N);
2490 #endif
2491 }
2492
2493 /*
2494 ** COMMAND: server*
2495 ** COMMAND: ui
2496 **
@@ -2539,11 +2568,11 @@
2568 int isUiCmd; /* True if command is "ui", not "server' */
2569 const char *zNotFound; /* The --notfound option or NULL */
2570 int flags = 0; /* Server flags */
2571 #if !defined(_WIN32)
2572 int noJail; /* Do not enter the chroot jail */
2573 const char *zTimeout = "300"; /* Max runtime of any single HTTP request */
2574 #endif
2575 int allowRepoList; /* List repositories on URL "/" */
2576 const char *zAltBase; /* Argument to the --baseurl option */
2577 const char *zFileGlob; /* Static content must match this */
2578 char *zIpAddr = 0; /* Bind to this IP address */
@@ -2571,11 +2600,11 @@
2600 zFileGlob = find_option("files",0,1);
2601 }
2602 skin_override();
2603 #if !defined(_WIN32)
2604 noJail = find_option("nojail",0,0)!=0;
2605 zTimeout = find_option("max-latency",0,1);
2606 #endif
2607 g.useLocalauth = find_option("localauth", 0, 0)!=0;
2608 Th_InitTraceLog();
2609 zPort = find_option("port", "P", 1);
2610 isUiCmd = g.argv[1][0]=='u';
@@ -2689,13 +2718,12 @@
2718 **
2719 ** So, when control reaches this point, we are running as a
2720 ** child process, the HTTP or SCGI request is pending on file
2721 ** descriptor 0 and the reply should be written to file descriptor 1.
2722 */
2723 if( zTimeout ){
2724 fossil_set_timeout(atoi(zTimeout));
 
2725 }
2726 g.httpIn = stdin;
2727 g.httpOut = stdout;
2728
2729 #if !defined(_WIN32)
2730

Keyboard Shortcuts

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