]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
net-lwip: zero terminate string with headers in wget_lwip_fill_info()
authorAdriano Cordova <adrianox@gmail.com>
Tue, 26 Nov 2024 16:19:21 +0000 (13:19 -0300)
committerHeinrich Schuchardt <heinrich.schuchardt@canonical.com>
Wed, 4 Dec 2024 11:24:37 +0000 (12:24 +0100)
    This patch comes as a companion to the same patch but for the legacy
    net stack. Commit 1327c2a8d6 ("net/lwip: wget: integrate struct wget_info
    into wget code") introduced function wget_fill_info() which retrieves
    the headers from the HTTP server response. As we want to parse the
    string in later patches we need to ensure that it is NUL terminated.

    We must further check that wget_info->headers in not NULL.
    Otherwise a crash occurs.

Signed-off-by: Adriano Cordova <adrianox@gmail.com>
net/lwip/wget.c

index 5a64f6887c9a29148a5072bef42b2bce4fe0aa05..263d6dab26c9f44f70ad3d322ea750a010e20905 100644 (file)
@@ -40,8 +40,13 @@ struct wget_ctx {
 
 static void wget_lwip_fill_info(struct pbuf *hdr, u16_t hdr_len, u32_t hdr_cont_len)
 {
-       if (wget_info->headers && hdr_len < MAX_HTTP_HEADERS_SIZE)
-               pbuf_copy_partial(hdr, (void *)wget_info->headers, hdr_len, 0);
+       if (wget_info->headers) {
+               if (hdr_len < MAX_HTTP_HEADERS_SIZE)
+                       pbuf_copy_partial(hdr, (void *)wget_info->headers, hdr_len, 0);
+               else
+                       hdr_len = 0;
+               wget_info->headers[hdr_len] = 0;
+       }
        wget_info->hdr_cont_len = (u32)hdr_cont_len;
 }