]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
httpc: Fix multi-value "Connection" header checks
authorJacek Tomasiak <jacek.tomasiak@gmail.com>
Sat, 5 Feb 2022 00:03:44 +0000 (01:03 +0100)
committerFlole998 <Flole998@users.noreply.github.com>
Sat, 12 Feb 2022 18:29:41 +0000 (19:29 +0100)
Connection header was checked for exact "close" or "upgrade" values
while it could contain multiple values delimited with commas.
New function was added for checking such cases.

Code is based on kv_find_value() function from:
https://cvsweb.openbsd.org/cgi-bin/cvsweb/src/usr.sbin/relayd/relayd.c

This fixes #6090

src/httpc.c

index 52ecf6dcea94c682349e7b74e5461a4c3bc5f50d..45b96a68fcfb79832f279497b13e640f7da185ef 100644 (file)
@@ -940,6 +940,24 @@ http_client_data_received( http_client_t *hc, char *buf, ssize_t len, int hdr )
   return end ? 1 : 0;
 }
 
+static int
+http_arg_contains(const char *arg, const char *val)
+{
+  char *a, *next, *p;
+  /* copy will be modified by strsep() */
+  a = strdup(arg);
+  for (next = p = a; p != NULL; p = strsep(&next, ",")) {
+    /* skip whitespace */
+    p += strspn(p, " \t\r\n");
+    if (strcasecmp(p, val) == 0) {
+      free(a);
+      return 1;
+    }
+  }
+  free(a);
+  return 0;
+}
+
 static int
 http_client_run0( http_client_t *hc )
 {
@@ -1093,7 +1111,7 @@ header:
   }
   p = http_arg_get(&hc->hc_args, "Connection");
   if (p && ver != RTSP_VERSION_1_0) {
-    if (strcasecmp(p, "close") == 0 || strcasecmp(p, "upgrade") == 0) /* Some servers
+    if (http_arg_contains(p, "close") || http_arg_contains(p, "upgrade")) /* Some servers
       send the upgrade header to switch to http2 even though we did not request this.
       Assume that we can not keep alive the connection in that case */
       hc->hc_keepalive = 0;