This is the changes that I added to rpki-client http.c which I have not
yet merged into ftp(1)

This is rev 1.67 of http.c:
date: 2022/09/08 13:52:36;  author: claudio;  state: Exp;  lines: +6 -4;
commitid: lZD6EB9xp7I5lQCo;
In http_get_line() additionally strip any trailing space or tab from
lines.
In many places the HTTP allows for extra spaces which need to be ignored.
Similar the chunked encoding extensions are separated from the chunk size
by a ':' but the spec also allows for bad whitespaces in all shapes and
forms. Adjust the logic in http_parse_chunked() to stop when the first
space, tab or ':' is seen. There is no need to check for newlines since
those are stripped by http_get_line().
OK tb@

-- 
:wq Claudio

Index: fetch.c
===================================================================
RCS file: /cvs/src/usr.bin/ftp/fetch.c,v
retrieving revision 1.210
diff -u -p -r1.210 fetch.c
--- fetch.c     15 Sep 2022 12:47:10 -0000      1.210
+++ fetch.c     9 Nov 2022 15:10:41 -0000
@@ -875,7 +875,8 @@ noslash:
                        goto cleanup_url_get;
                }
 
-               while (len > 0 && (buf[len-1] == '\r' || buf[len-1] == '\n'))
+               while (len > 0 && (buf[len-1] == '\r' || buf[len-1] == '\n' ||
+                   buf[len-1] == ' ' || buf[len-1] == '\t'))
                        buf[--len] = '\0';
                if (len == 0)
                        break;
@@ -1161,7 +1162,7 @@ save_chunked(FILE *fin, struct tls *tls,
                if (getline(&header, &hsize, fin) == -1)
                        break;
                /* strip CRLF and any optional chunk extension */
-               header[strcspn(header, ";\r\n")] = '\0';
+               header[strcspn(header, "; \t\r\n")] = '\0';
                errno = 0;
                chunksize = strtoul(header, &end, 16);
                if (errno || header[0] == '\0' || *end != '\0' ||

Reply via email to