]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
tool: avoid including leading spaces in the Location hyperlink
authorDavide Masserut <dm@mssdvd.com>
Fri, 25 Aug 2023 16:41:10 +0000 (18:41 +0200)
committerDan Fandrich <dan@coneharvesters.com>
Tue, 29 Aug 2023 17:12:05 +0000 (10:12 -0700)
Co-authored-by: Dan Fandrich <dan@coneharvesters.com>
Closes #11735

src/tool_cb_hdr.c

index aab96ae0374e297ca34662bc9a5d0473af372209..df44f7aa73ce3c1f34723bf6c6599feb42592c54 100644 (file)
@@ -349,6 +349,7 @@ void write_linked_location(CURL *curl, const char *location, size_t loclen,
   char *copyloc = NULL, *locurl = NULL, *scheme = NULL, *finalurl = NULL;
   const char *loc = location;
   size_t llen = loclen;
+  int space_skipped = 0;
   char *vver = getenv("VTE_VERSION");
 
   if(vver) {
@@ -360,9 +361,10 @@ void write_linked_location(CURL *curl, const char *location, size_t loclen,
   }
 
   /* Strip leading whitespace of the redirect URL */
-  while(llen && *loc == ' ') {
+  while(llen && (*loc == ' ' || *loc == '\t')) {
     ++loc;
     --llen;
+    ++space_skipped;
   }
 
   /* Strip the trailing end-of-line characters, normally "\r\n" */
@@ -401,8 +403,10 @@ void write_linked_location(CURL *curl, const char *location, size_t loclen,
      !strcmp("https", scheme) ||
      !strcmp("ftp", scheme) ||
      !strcmp("ftps", scheme)) {
-    fprintf(stream, LINK "%s" LINKST "%.*s" LINKOFF,
-            finalurl, (int)loclen, location);
+    fprintf(stream, "%.*s" LINK "%s" LINKST "%.*s" LINKOFF,
+            space_skipped, location,
+            finalurl,
+            (int)loclen - space_skipped, loc);
     goto locdone;
   }