summaryrefslogtreecommitdiff
path: root/net/lwip/wget.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/lwip/wget.c')
-rw-r--r--net/lwip/wget.c28
1 files changed, 15 insertions, 13 deletions
diff --git a/net/lwip/wget.c b/net/lwip/wget.c
index 46858cb5dd3..b76f6c0f1d9 100644
--- a/net/lwip/wget.c
+++ b/net/lwip/wget.c
@@ -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;
}
@@ -175,7 +180,7 @@ static int parse_legacy_arg(char *arg, char *nurl, size_t rem)
if (rem < n)
return -1;
- strlcpy(p, server, n);
+ strncpy(p, server, n);
p += n;
rem -= n;
if (rem < 1)
@@ -186,7 +191,7 @@ static int parse_legacy_arg(char *arg, char *nurl, size_t rem)
n = strlen(path);
if (rem < n)
return -1;
- strlcpy(p, path, n);
+ strncpy(p, path, n);
p += n;
rem -= n;
if (rem < 1)
@@ -255,10 +260,9 @@ static void httpc_result_cb(void *arg, httpc_result_t httpc_result,
printf("%u bytes transferred in %lu ms (", rx_content_len, elapsed);
print_size(rx_content_len / elapsed * 1000, "/s)\n");
printf("Bytes transferred = %lu (%lx hex)\n", ctx->size, ctx->size);
- if (wget_info->set_bootdev) {
- efi_set_bootdev("Net", "", ctx->path, map_sysmem(ctx->saved_daddr, 0),
+ if (wget_info->set_bootdev)
+ efi_set_bootdev("Http", ctx->server_name, ctx->path, map_sysmem(ctx->saved_daddr, 0),
rx_content_len);
- }
wget_lwip_set_file_size(rx_content_len);
if (env_set_hex("filesize", rx_content_len) ||
env_set_hex("fileaddr", ctx->saved_daddr)) {
@@ -283,7 +287,6 @@ static err_t httpc_headers_done_cb(httpc_state_t *connection, void *arg, struct
static int wget_loop(struct udevice *udev, ulong dst_addr, char *uri)
{
- char server_name[SERVER_NAME_SIZE];
#if defined CONFIG_WGET_HTTPS
altcp_allocator_t tls_allocator;
#endif
@@ -292,7 +295,6 @@ static int wget_loop(struct udevice *udev, ulong dst_addr, char *uri)
struct netif *netif;
struct wget_ctx ctx;
char *path;
- u16 port;
bool is_https;
ctx.daddr = dst_addr;
@@ -302,7 +304,7 @@ static int wget_loop(struct udevice *udev, ulong dst_addr, char *uri)
ctx.prevsize = 0;
ctx.start_time = 0;
- if (parse_url(uri, server_name, &port, &path, &is_https))
+ if (parse_url(uri, ctx.server_name, &ctx.port, &path, &is_https))
return CMD_RET_USAGE;
netif = net_lwip_new_netif(udev);
@@ -314,7 +316,7 @@ static int wget_loop(struct udevice *udev, ulong dst_addr, char *uri)
if (is_https) {
tls_allocator.alloc = &altcp_tls_alloc;
tls_allocator.arg =
- altcp_tls_create_config_client(NULL, 0, server_name);
+ altcp_tls_create_config_client(NULL, 0, ctx.server_name);
if (!tls_allocator.arg) {
log_err("error: Cannot create a TLS connection\n");
@@ -350,7 +352,7 @@ static int wget_loop(struct udevice *udev, ulong dst_addr, char *uri)
return -1;
}
-int wget_with_dns(ulong dst_addr, char *uri)
+int wget_do_request(ulong dst_addr, char *uri)
{
eth_set_current();
@@ -384,7 +386,7 @@ int do_wget(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[])
return CMD_RET_FAILURE;
wget_info = &default_wget_info;
- if (wget_with_dns(dst_addr, nurl))
+ if (wget_do_request(dst_addr, nurl))
return CMD_RET_FAILURE;
return CMD_RET_SUCCESS;