since fetch.c revision 1.211 ("strip spaces at end of header lines and
in chunked encoding headers") ftp removes trailing whitespaces early
so we don't need to re-do that upon every header we parse.

it can also be misleading since one can wonder why LAST_MODIFIED
doesn't have " \t" but only "\t", or confront it with rpki-client'
http.c and notice that there there is no strcspn() call in
Last-Modified handling.

I've tested it by modifying httpd(8) to append " \t " at the end of
every header (legal per rfc 7230) and observing that ftp still works
fine, including mtime handling.

A similar thing could be applied to rpki-client' http.c as well, it
should work the same.

As a bonus, drop the unused `s' variable in Retry-After handling.

ok?

diff /usr/src
commit - 9832f5035d799ae12e9f848cff5650481b673260
path + /usr/src
blob - eb4c872b72b3db468f782a12756bb7f8fb64784d
file + usr.bin/ftp/fetch.c
--- usr.bin/ftp/fetch.c
+++ usr.bin/ftp/fetch.c
@@ -891,7 +891,6 @@ noslash:
                if (strncasecmp(cp, CONTENTLEN, sizeof(CONTENTLEN) - 1) == 0) {
                        cp += sizeof(CONTENTLEN) - 1;
                        cp += strspn(cp, " \t");
-                       cp[strcspn(cp, " \t")] = '\0';
                        filesize = strtonum(cp, 0, LLONG_MAX, &errstr);
                        if (errstr != NULL)
                                goto improper;
@@ -964,10 +963,8 @@ noslash:
 #define RETRYAFTER "Retry-After:"
                } else if (isunavail &&
                    strncasecmp(cp, RETRYAFTER, sizeof(RETRYAFTER) - 1) == 0) {
-                       size_t s;
                        cp += sizeof(RETRYAFTER) - 1;
                        cp += strspn(cp, " \t");
-                       cp[strcspn(cp, " \t")] = '\0';
                        retryafter = strtonum(cp, 0, 0, &errstr);
                        if (errstr != NULL)
                                retryafter = -1;
@@ -976,7 +973,6 @@ noslash:
                            sizeof(TRANSFER_ENCODING) - 1) == 0) {
                        cp += sizeof(TRANSFER_ENCODING) - 1;
                        cp += strspn(cp, " \t");
-                       cp[strcspn(cp, " \t")] = '\0';
                        if (strcasecmp(cp, "chunked") == 0)
                                chunked = 1;
 #ifndef SMALL
@@ -985,7 +981,6 @@ noslash:
                            sizeof(LAST_MODIFIED) - 1) == 0) {
                        cp += sizeof(LAST_MODIFIED) - 1;
                        cp += strspn(cp, " \t");
-                       cp[strcspn(cp, "\t")] = '\0';
                        if (strptime(cp, "%a, %d %h %Y %T %Z", &lmt) == NULL)
                                server_timestamps = 0;
 #endif /* !SMALL */

Reply via email to