diff options
author | Heinrich Schuchardt <heinrich.schuchardt@canonical.com> | 2024-11-26 13:19:20 -0300 |
---|---|---|
committer | Heinrich Schuchardt <heinrich.schuchardt@canonical.com> | 2024-12-04 12:24:37 +0100 |
commit | 737c2dca95e5c4fec208026f367a5333fbdad21f (patch) | |
tree | e3451eecd4bb7590967421438c2258600a94ee48 /net/wget.c | |
parent | ab49ede318751c8a1920e3fd5957f16e4df7f490 (diff) | |
download | u-boot-737c2dca95e5c4fec208026f367a5333fbdad21f.tar.gz |
net: zero terminate string with headers in wget_fill_info()
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 <adrianox@gmail.com>
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Diffstat (limited to 'net/wget.c')
-rw-r--r-- | net/wget.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/net/wget.c b/net/wget.c index 3bc2522cde5..5d70b7a82e0 100644 --- a/net/wget.c +++ b/net/wget.c @@ -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, ' '); |