]> granicus.if.org Git - curl/commitdiff
altsvc: accept quoted ma and persist values
authorDaniel Stenberg <daniel@haxx.se>
Mon, 30 Sep 2019 08:29:46 +0000 (10:29 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 30 Sep 2019 14:35:12 +0000 (16:35 +0200)
As mandated by the spec. Test 1654 is extended to verify.

Closes #4443

lib/altsvc.c
tests/data/test1654
tests/unit/unit1654.c

index a961e5c0560685b84810c766963b388a3eb2b9e6..64971a9f0fca0b9885b5bc8dadad8c4294103a96 100644 (file)
@@ -442,6 +442,7 @@ CURLcode Curl_altsvc_parse(struct Curl_easy *data,
       char option[32];
       unsigned long num;
       char *end_ptr;
+      bool quoted = FALSE;
       semip++; /* pass the semicolon */
       result = getalnum(&semip, option, sizeof(option));
       if(result)
@@ -451,12 +452,21 @@ CURLcode Curl_altsvc_parse(struct Curl_easy *data,
       if(*semip != '=')
         continue;
       semip++;
+      while(*semip && ISBLANK(*semip))
+        semip++;
+      if(*semip == '\"') {
+        /* quoted value */
+        semip++;
+        quoted = TRUE;
+      }
       num = strtoul(semip, &end_ptr, 10);
-      if(num < ULONG_MAX) {
+      if((end_ptr != semip) && num && (num < ULONG_MAX)) {
         if(strcasecompare("ma", option))
           maxage = num;
         else if(strcasecompare("persist", option) && (num == 1))
           persist = TRUE;
+        if(quoted && (*end_ptr == '\"'))
+          end_ptr++;
       }
       semip = end_ptr;
     }
index 5b32cb419c9362524d5b71c234a8366590b63bfe..6a82daa081db0cb1dc14011e4fe61e348aceb796 100644 (file)
@@ -53,6 +53,7 @@ h1 2.example.org 8080 h3 2.example.org 8080 "20190125 22:34:21" 0 0
 h1 3.example.org 8080 h2 example.com 8080 "20190125 22:34:21" 0 0
 h1 3.example.org 8080 h3 yesyes.com 8080 "20190125 22:34:21" 0 0
 h2 example.org 80 h2 example.com 443 "20190124 22:36:21" 0 0
+h2 example.net 80 h2 example.net 443 "20190124 22:37:21" 0 0
 </file>
 </verify>
 </testcase>
index 51fc5d16f587d6f0072e42b639e893036e0b32a5..a800d9c3a06d8508b07acf2eae51f7ae5a1d39d7 100644 (file)
@@ -97,6 +97,15 @@ UNITTEST_START
   }
   fail_unless(asi->num == 9, "wrong number of entries");
 
+  /* quoted 'ma' value */
+  result = Curl_altsvc_parse(curl, asi, "h2=\"example.net:443\"; ma=\"180\";",
+                             ALPN_h2, "example.net", 80);
+  if(result) {
+    fprintf(stderr, "Curl_altsvc_parse(4) failed!\n");
+    unitfail++;
+  }
+  fail_unless(asi->num == 10, "wrong number of entries");
+
   result = Curl_altsvc_parse(curl, asi,
                              "h2=\":443\", h3=\":443\"; ma = 120; persist = 1",
                              ALPN_h1, "curl.haxx.se", 80);
@@ -104,7 +113,7 @@ UNITTEST_START
     fprintf(stderr, "Curl_altsvc_parse(5) failed!\n");
     unitfail++;
   }
-  fail_unless(asi->num == 11, "wrong number of entries");
+  fail_unless(asi->num == 12, "wrong number of entries");
 
   /* clear that one again and decrease the counter */
   result = Curl_altsvc_parse(curl, asi, "clear;",
@@ -113,7 +122,7 @@ UNITTEST_START
     fprintf(stderr, "Curl_altsvc_parse(6) failed!\n");
     unitfail++;
   }
-  fail_unless(asi->num == 9, "wrong number of entries");
+  fail_unless(asi->num == 10, "wrong number of entries");
 
   Curl_altsvc_save(asi, outname);