Bug #1159


Cannot set server.port from environment variable

Added by Anonymous about 17 years ago. Updated over 15 years ago.

Target version:


Given the environment:

export PORT

the following line in the lighty configuration file:

server.port = env.PORT

fails with the message:

(configfile-glue.c.91) got a string but expected a short: server.port 80

This means that port numbers cannot be set from environment variables, but code was introduced in source:trunk/src/configfile-glue.c@r1349 (3-Oct-2006) to handle this case. It would appear that the `buffer_isdigit()` test in source:trunk/src/configfile-glue.c is broken somehow.

-- andrewb


lighttpd-ticket-1159-patch.txt (997 Bytes) lighttpd-ticket-1159-patch.txt Here is a patch that fixes the problem. -- andrewb Anonymous, 2007-09-07 11:25

Related issues 1 (0 open1 closed)

Has duplicate Feature #1403: Can conf file parser auto type cast a string value to integer?FixedjanActions
Actions #1

Updated by darix almost 17 years ago

what i dont like about this patch is that it limits the number to 65535. while this might be ok for your use case (server.port) this is not a valid solution for the problem. what if i want to set the max request size from the environment?

the number shouldnt be limited at that position but checked later on in the code if it fits into the limits in this scope.

Actions #2

Updated by Anonymous almost 17 years ago

The hard-coded limit of 65535 is completely justified.

The case in question is for "T_CONFIG_SHORT", which generally suggests that a two-byte signed (or unsigned) value is wanted. This is confirmed, and the signed-vs-unsigned question is settled, a few lines further on, where an error message has the 65535 value hard-coded in. Good design dictates that the numeric limits of the lighty config language should be platform independent, not determined by the built-in types of the C compiler used to build it (ie, we don't really want 65536 overflowing on one platform but not on another). All the C standards I've ever read say that `sizeof(short)` is guaranteed to be at least two on all architectures. So I deduced that the assumption of two-byte shorts was deliberate on the part of the lighty developers, and respected that.

Incidentaly, Just a few lines higher, data_integer.value (which is of type int) is assigned to a `*(unsigned short *)` without checking for overflow. That is clearly a bug, but it further strengthens my argument.

-- andrewb

Actions #3

Updated by Anonymous over 16 years ago

Is this going to be fixed any time soon? The patch looks OK to me (if not, it's trivial to #define the maximum unsigned short as (1 << (sizeof(unsigned short) * 8)) - 1), and I just ran into this problem today myself.

Actions #4

Updated by stbuehler almost 16 years ago

Workaround: have a shell script that does this for you:


echo "server.port = ${PORT}" 
Actions #5

Updated by stbuehler over 15 years ago

  • Status changed from New to Fixed
  • Resolution set to fixed

Applied in r2321


Also available in: Atom