Browse Source

[core] never evaluate else branches until the previous branches are aready (fixes #2598)

The first condition which evaluates true in any if-else... condition
chain short-circuits the chain, and any remaining conditions in the
chain are marked false.

Previous conditions in if-else condition chaining must be evaluatable
(to true or false) -- must not remain in unset (not yet evaluatable)
state -- prior to evaluating later conditions.  Since any true
condition short-circuits remaining conditions, all prev conditions
must be false prior to evaluating later conditions.

From: Glenn Strauss <gstrauss@gluelogic.com>

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@3081 152afb58-edef-0310-8abb-c4023f1b3aa9
svn/heads/lighttpd-1.4.x
Glenn Strauss 5 years ago
committed by Stefan Bühler
parent
commit
1c01a42aa3
  1. 1
      NEWS
  2. 9
      src/configfile-glue.c
  3. 6
      tests/condition.conf
  4. 17
      tests/core-condition.t

1
NEWS

@ -13,6 +13,7 @@ NEWS
* [mod_cgi] edge case chdir "/" when docroot "/" (fixes #2460)
* [mod_cgi] issue trace and exit if execve() fails (closes #2302)
* [configparser] don't continue after parse error (fixes #2717)
* [core] never evaluate else branches until the previous branches are ready (fixes #2598)
- 1.4.39 - 2016-01-02
* [core] fix memset_s call (fixes #2698)

9
src/configfile-glue.c

@ -264,7 +264,14 @@ static cond_result_t config_check_cond_nocache(server *srv, connection *con, dat
}
/* make sure prev is checked first */
config_check_cond_cached(srv, con, dc->prev);
switch (config_check_cond_cached(srv, con, dc->prev)) {
case COND_RESULT_UNSET:
return COND_RESULT_UNSET;
case COND_RESULT_FALSE:
break;
case COND_RESULT_TRUE:
return COND_RESULT_FALSE;
}
/* one of prev set me to FALSE */
switch (con->cond_cache[dc->context_ndx].result) {

6
tests/condition.conf

@ -86,3 +86,9 @@ else $HTTP["host"] == "test4.example.org" {
)
}
}
$HTTP["url"] != "/show/other/server-tag" {
}
else $HTTP["scheme"] == "http" {
server.tag = "special tag"
}

17
tests/core-condition.t

@ -8,7 +8,7 @@ BEGIN {
use strict;
use IO::Socket;
use Test::More tests => 19;
use Test::More tests => 21;
use LightyTest;
my $tf = LightyTest->new();
@ -65,6 +65,20 @@ EOF
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 301, 'Location' => "/match_6" } ];
ok($tf->handle_http($t) == 0, 'url subdir with path traversal');
$t->{REQUEST} = ( <<EOF
GET / HTTP/1.0
EOF
);
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 301, 'Server' => 'Apache 1.3.29' } ];
ok($tf->handle_http($t) == 0, 'condition: handle if before else branches');
$t->{REQUEST} = ( <<EOF
GET /show/other/server-tag HTTP/1.0
EOF
);
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 301, 'Server' => 'special tag' } ];
ok($tf->handle_http($t) == 0, 'condition: handle if before else branches #2');
ok($tf->stop_proc == 0, "Stopping lighttpd");
$tf->{CONFIGFILE} = 'lighttpd.conf';
@ -152,4 +166,3 @@ $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } ];
ok($tf->handle_http($t) == 0, 'condition: $HTTP["referer"] == "" and Referer: foobar');
ok($tf->stop_proc == 0, "Stopping lighttpd");
Loading…
Cancel
Save