]> Git Repo - u-boot.git/commitdiff
net: zero terminate string with headers in wget_fill_info()
authorHeinrich Schuchardt <[email protected]>
Tue, 26 Nov 2024 16:19:20 +0000 (13:19 -0300)
committerHeinrich Schuchardt <[email protected]>
Wed, 4 Dec 2024 11:24:37 +0000 (12:24 +0100)
Commit 2dd076a9c1b4 ("net: wget: integrate struct wget_info into legacy
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.

Fixes: 2dd076a9c1b4 ("net: wget: integrate struct wget_info into legacy wget code")
Signed-off-by: Adriano Cordova <[email protected]>
Signed-off-by: Heinrich Schuchardt <[email protected]>
net/wget.c

index 3bc2522cde5a05da8f41ad2bb62c0aa9ad501378..5d70b7a82e006cfe1f6b14c06f237084b0c20564 100644 (file)
@@ -208,8 +208,13 @@ static void wget_fill_info(const uchar *pkt, int hlen)
        const char *second_space;
        char *pos, *end;
 
-       if (wget_info->headers && hlen < MAX_HTTP_HEADERS_SIZE)
-               strncpy(wget_info->headers, pkt, hlen);
+       if (wget_info->headers) {
+               if (hlen < MAX_HTTP_HEADERS_SIZE)
+                       strncpy(wget_info->headers, pkt, hlen);
+               else
+                       hlen = 0;
+               wget_info->headers[hlen] = 0;
+       }
 
        //Get status code
        first_space = strchr(pkt, ' ');
This page took 0.040346 seconds and 4 git commands to generate.