Project

General

Profile

Bug #1159 ยป lighttpd-ticket-1159-patch.txt

Here is a patch that fixes the problem. -- andrewb - Anonymous, 2007-09-07 11:25

 
1
--- src/configfile-glue.c	(revision 269)
2
+++ src/configfile-glue.c	(working copy)
3
@@ -1,4 +1,5 @@
4
 #include <string.h>
5
+#include <stdlib.h>
6
 
7
 #include "base.h"
8
 #include "buffer.h"
9
@@ -90,6 +91,22 @@
10
 			case TYPE_STRING: {
11
 				data_string *ds = (data_string *)du;
12
 
13
+				/* If the value came from an environment variable, then it is a
14
+				 * data_string, although it may contain a number in ASCII
15
+				 * decimal format.  We try to interpret the string as a decimal
16
+				 * short before giving up, in order to support setting numeric
17
+				 * values with environment variables (eg, port number).
18
+				 */
19
+				if (ds->value->ptr && *ds->value->ptr) {
20
+					char *e;
21
+					long l = strtol(ds->value->ptr, &e, 10);
22
+					if (e != ds->value->ptr && !*e && l >=0 && l <= 65535) {
23
+						*((unsigned short *)(cv[i].destination)) = l;
24
+						break;
25
+
26
+					}
27
+				}
28
+
29
 				log_error_write(srv, __FILE__, __LINE__, "ssb", "got a string but expected a short:", cv[i].key, ds->value);
30
 
31
 				return -1;
    (1-1/1)