repair matching of headers, add regress test for this error
authorbenno <benno@openbsd.org>
Sun, 13 Jul 2014 00:18:05 +0000 (00:18 +0000)
committerbenno <benno@openbsd.org>
Sun, 13 Jul 2014 00:18:05 +0000 (00:18 +0000)
ok reyk

regress/usr.sbin/relayd/args-http-mark-marked2.pl [new file with mode: 0644]
usr.sbin/relayd/relay_http.c

diff --git a/regress/usr.sbin/relayd/args-http-mark-marked2.pl b/regress/usr.sbin/relayd/args-http-mark-marked2.pl
new file mode 100644 (file)
index 0000000..234c8af
--- /dev/null
@@ -0,0 +1,43 @@
+# match and set header with tags
+
+use strict;
+use warnings;
+
+my %header_client = (
+    "User-Agent" => "Mozilla Bla",
+    "MyHeader" => "UnmatchableContent",
+);
+
+our %args = (
+    client => {
+       func => \&http_client,
+       header => \%header_client,
+       len => 33,
+    },
+    relayd => {
+       protocol => [ "http",
+           # setting the User-Agent should succeed
+           'match request header "User-Agent" value "Mozilla*" tag BORK',
+           'match request header set "User-Agent" value "BORK" tagged BORK',
+           'match request header log "User-Agent"',
+           # setting MyHeader should not happen
+           'match request header "MyHeader" value "SomethingDifferent" tag FOO',
+           'match request header set "MyHeader" value "FOO" tagged FOO',
+           'match request header log "MyHeader"',
+       ],
+       loggrep => {
+           'User-Agent: BORK' => 1,
+           'MyHeader: FOO' => 0,
+       },
+    },
+    server => {
+       func => \&http_server,
+       loggrep => {
+           "User-Agent: BORK" => 1,
+           "MyHeader: FOO" => 0,
+       }
+    },
+    len => 33,
+);
+
+1;
index 9e30487..ede8aa4 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: relay_http.c,v 1.27 2014/07/12 15:47:18 benno Exp $   */
+/*     $OpenBSD: relay_http.c,v 1.28 2014/07/13 00:18:05 benno Exp $   */
 
 /*
  * Copyright (c) 2006 - 2014 Reyk Floeter <reyk@openbsd.org>
@@ -1229,6 +1229,13 @@ relay_httpheader_test(struct ctl_relay_event *cre, struct relay_rule *rule,
        } else if (match == NULL) {
                /* Fail if header doesn't exist */
                return (-1);
+       } else {
+               if (fnmatch(kv->kv_key, match->kv_key, FNM_CASEFOLD) == FNM_NOMATCH)
+                       return (-1);
+               if (kv->kv_value != NULL &&
+                   match->kv_value != NULL &&
+                   fnmatch(kv->kv_value, match->kv_value, 0) == FNM_NOMATCH)
+                       return (-1);
        }
 
        relay_match(actions, kv, match, &desc->http_headers);