From patchwork Tue Apr 15 19:34:26 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 881238 Delivered-To: patch@linaro.org Received: by 2002:adf:f902:0:b0:38f:210b:807b with SMTP id b2csp626043wrr; Tue, 15 Apr 2025 12:35:06 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXlQFBB08rMb291HGvfjlzyMiVgMxd7tD/W80DPzHuXqqIIPx0WCgBRqYp9C157qCR0lUgHMQ==@linaro.org X-Google-Smtp-Source: AGHT+IEdM5DP5e5mJIqmkyJD7CAMRWXr5ImQ64mohR6kN7YS67iemSvwq+5dR3hY6EZStgGkr2Ro X-Received: by 2002:a05:6102:5f0b:b0:4c1:86bc:f959 with SMTP id ada2fe7eead31-4cb528f3894mr534364137.8.1744745705975; Tue, 15 Apr 2025 12:35:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1744745705; cv=none; d=google.com; s=arc-20240605; b=VWWFl3H2StEsReHdAMx3fXkrkkTBd319NYuszUxGKEv9grZYoxxyLf2wycaESwy73q 3IJ7MOXaWt+wv/KQUdmrqGcHJBU8UZxTk7xuGaSHepRLLbAyabumlXCW7M/J65wH5MRw vJtlJL3qaHScQQKylJ5zt7gzIpGar3tEj3L8tVgRChtZ/+LZe2cjkyilvoyOgp4dTilz XVeEpg8VbsRS7vJ9gahMDGV5YiijffHJfsQxtthZWb9wHgMWk5gZGj///pi7UU6Bi0BC vnmweYzKGuPDBn6hmHWRu+M6an0MWYGv5e0J0hOe6Cp8OT7rgkFXklpCECvg/UpdnasB ay8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=zLR7UW7V70MRs5WGvk88LiGNkaGRuqIFsd+Dt9PTzVA=; fh=+TzJuMMnKDMsbGyXcXAynrdn4hYe+uVLmq5NLJkVciY=; b=eV8PRM+PPQFdNqGTZw3Mj4U8LA3fCm4UpZaVSyC4FfaBrPIn8Lh/eJOKxztfgql/gh HaCSMMDYNkAY0tqySOAw4lW+/4X+O9DaN3mpI+Gmc3p1UPoyeXQKuJ8BrIrMszYCTsNt P9GxA5NcdB6guRGHoAs4oIlhPeorUpRBAoY0eMdRxCl6zkPL0jKTSqffcuUtGkgBmWws KCik1fHW1gxBbl1mxYuvsLA+OXgD4UeSPdKw9mN/Fk0W3gkeFbEc2TUevoGUOTNoLY7c XYbfgK6oXFdFzG8JWU1zsy32WHIyqS8MjYMSvUviiChEiQh/0zFNF0rHXBkCLo0FDrQt 2tmQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Tkmllmrk; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id ada2fe7eead31-4c9c98c8f04si4276933137.479.2025.04.15.12.35.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Apr 2025 12:35:05 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Tkmllmrk; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D1FFF82A8B; Tue, 15 Apr 2025 21:34:54 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="Tkmllmrk"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5165D82B3D; Tue, 15 Apr 2025 21:34:53 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 3CBE682B1C for ; Tue, 15 Apr 2025 21:34:51 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jerome.forissier@linaro.org Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-39c266c2dd5so5349559f8f.3 for ; Tue, 15 Apr 2025 12:34:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1744745690; x=1745350490; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zLR7UW7V70MRs5WGvk88LiGNkaGRuqIFsd+Dt9PTzVA=; b=TkmllmrkEdJv2w6ynzH6j0DYgjDe8a3c43JTV13an8AGLpfCp5ILpmCcwfKAA8Zel9 UTS5ddt4HNqzcwhjRBe7N2c1mHSk59uSd4TMYYRCihKa31KdtHsgSfVbkxNADWywBfPe Us3FChnCF0PT0wv2qsq2ky8PDYV380ef+tbtNDoL8xSeCKd0VJ+IEihDAaZLVubxZa1x PrIqpkqY60xqFAsmnz52toBhLnm0UUdTPjoT1de7PcgyUZEImxWNrmH7+kYV6XXb6/3v WaCsxJGTgHOvQzlvASJgZ0/+0UNFTByNihI00SGc4QX/5polYwJGwgVhaOl+9FL22vxI IDSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744745690; x=1745350490; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zLR7UW7V70MRs5WGvk88LiGNkaGRuqIFsd+Dt9PTzVA=; b=DLpRLQaCxIm4LP2Tdb9CNl9OsI4v4GYDHdPDVi1F8guY/R1ixVk3B3E9+ET45yjkfo UsVkM0rSeZfHJ8ww3HJFISRNnSzEj8W1+VbbGX5SKXiEOxTcxFYMUFug+Lv/cOl68SeJ X9ZcBEfd0IxDVbxKvHO9CxChF/qCnAOZ8IsvCbHF/Neb14fY2oor3yoIygqAvqA6lPhu GmKLF2Do7wfDOSmd+86xxXJsNRIb6k5eNrT8eT864sX0AjZ/a3FhcDqMEDXWSQ9nahU3 24nGklQ1VjD7REejaxpL49l4v3E2FrU9R2ClryPiXa3D1MlDzRk/x6mRzsEgOYpvIcZZ 1a5Q== X-Gm-Message-State: AOJu0YxkpTBC5PShTQnuY61d2sPogLnGZ85p8DBEOqCA3boAiGRMDOAR R05MwaUtg8NpLK3utgo++h7cSaHonsNJ5TXKlz5f3N8inJI5b1rZCfiyZPgUfHlC47XA9x2wQtd IjnQ= X-Gm-Gg: ASbGnctGib2sw7VmlY1YyxQZrS3jDcz4Duzo/EO2zv3QIXvTKGfZSMCGRAAakppWNco 7e9fY+ecYuczaYjAQp3tnU4Fea53RamqajWqnzsg+tYPFvUgbghm0P/ATKXiWJhdQ47l59i7UXC t3oAXbqaOSMS8xCauaoqWDD7vZXAKbZcZ08N3Gz3t266Os5ABmpQXRASP0xXCS1BvoSUlUkk5WY 2PlmZ1hIJQJOcVrdXpONW/8RkKTtyymHEo7nEUrtsYrtjc+7WNcsrLP2S+hpD7lBqEwPAVwvXGa XhEBlgVCSpxupdXZA65m3TE6NXICjLem9/GclxMEAY2rIbVpF73wveIq8aI= X-Received: by 2002:a05:6000:4305:b0:39a:ca05:54a9 with SMTP id ffacd0b85a97d-39ee2751d61mr589336f8f.29.1744745690474; Tue, 15 Apr 2025 12:34:50 -0700 (PDT) Received: from builder.. ([2a01:e0a:3cb:7bb0:6ebc:6ce:770e:95f9]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-39eaf43d046sm15520484f8f.63.2025.04.15.12.34.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Apr 2025 12:34:49 -0700 (PDT) From: Jerome Forissier To: U-Boot mailing list Cc: Jerome Forissier , Adriano Cordova , Heinrich Schuchardt , Ilias Apalodimas , Joe Hershberger , Ramon Fried , Simon Glass , Tom Rini Subject: [PATCH v4 1/4] net-lwip: change static function wget_loop() to be wget_do_request() Date: Tue, 15 Apr 2025 21:34:26 +0200 Message-ID: <20250415193436.1240804-2-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250415193436.1240804-1-jerome.forissier@linaro.org> References: <20250415193436.1240804-1-jerome.forissier@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean wget_do_request() currently does so little before calling the static function wget_loop() that we may as well rename wget_loop() to wget_do_request() and put everything in one function. Signed-off-by: Jerome Forissier --- Changes in v4: - New patch net/lwip/wget.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/net/lwip/wget.c b/net/lwip/wget.c index ec098148835..2b512a1bc84 100644 --- a/net/lwip/wget.c +++ b/net/lwip/wget.c @@ -372,13 +372,14 @@ static int set_cacert(char * const saddr, char * const ssz) #endif #endif /* CONFIG_WGET_CACERT || CONFIG_WGET_BUILTIN_CACERT */ -static int wget_loop(struct udevice *udev, ulong dst_addr, char *uri) +int wget_do_request(ulong dst_addr, char *uri) { #if CONFIG_IS_ENABLED(WGET_HTTPS) altcp_allocator_t tls_allocator; #endif httpc_connection_t conn; httpc_state_t *state; + struct udevice *udev; struct netif *netif; struct wget_ctx ctx; char *path; @@ -394,6 +395,13 @@ static int wget_loop(struct udevice *udev, ulong dst_addr, char *uri) if (parse_url(uri, ctx.server_name, &ctx.port, &path, &is_https)) return CMD_RET_USAGE; + net_lwip_set_current(); + + if (!wget_info) + wget_info = &default_wget_info; + + udev = eth_get_dev(); + netif = net_lwip_new_netif(udev); if (!netif) return -1; @@ -469,16 +477,6 @@ static int wget_loop(struct udevice *udev, ulong dst_addr, char *uri) return -1; } -int wget_do_request(ulong dst_addr, char *uri) -{ - net_lwip_set_current(); - - if (!wget_info) - wget_info = &default_wget_info; - - return wget_loop(eth_get_dev(), dst_addr, uri); -} - int do_wget(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[]) { char *end; From patchwork Tue Apr 15 19:34:27 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 881239 Delivered-To: patch@linaro.org Received: by 2002:adf:f902:0:b0:38f:210b:807b with SMTP id b2csp626107wrr; Tue, 15 Apr 2025 12:35:15 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUt99rJ/pIsh2uYsxEb4OFDh0qj8YW39wVy7SXCsCG1VBKD/8q8IetPDrswr92h3aEWIE43HQ==@linaro.org X-Google-Smtp-Source: AGHT+IEQXRzXjKttPGyjmIExCCwbqAOSviDfvXdgWQuW5m+9OZGWy6Cxu14rzOCEmpeThumooYU9 X-Received: by 2002:a05:6102:5617:b0:4c5:8b0c:5fde with SMTP id ada2fe7eead31-4cb51baf4afmr886872137.8.1744745715408; Tue, 15 Apr 2025 12:35:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1744745715; cv=none; d=google.com; s=arc-20240605; b=Jgu7Dmu1cgcm+uN421nkAQinDV2TkN1J9XHbZnHpPlG/5aJST4GSPkwRYfXTVRdouT BW1B9z5/bGZu/qZXkogkhGqsAaAZ/wMAGnMc4i3xgvjnd+2jr+/DYmjtQip+vT0zlwYH wxlCanVk4Z/LxWuDleeox2ouxHG93PEtk8E3bh+6pI0gkEdiC5QZV5e1osHDj0viIg5n sPe8ddv9CLsNo1+lERO3jzxyVvb3ausfzqmSa3NsmPj5Cp/vnFDHDbJEeODeRz82pSbo hhtLG9Wurfmi7jFDDRKfOEKt+6vmuPTMcK0USAJO8Qeqq142rB1be6KIU+YLbDdyWf+O Qkjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=1olj/4/0QjVfT/SCqMEBitoG5ohCI4M4SdcbZFvqcio=; fh=wlSvFc4i8C8NBaqMzyXvbiP5uL/OM4dxSL0gISf2ETs=; b=e9A63mJeC0nBPFOnZfHQXO7AHApRsDfkR7KYH0H7zlPn9c+PZ2mOovNGjjYX4WGrS/ Ja+si4hQpWRUtby/biWRQJMD1dYwDjenI+nv5gjlsSXAPTlGxRiWIgq+yRxIMwRGusMv q2k3jtxha6NBNZ2cXyTElkJ89PHrxx0MuxyLZrj+OEPC/qPQGUvHsB11+L0E0OvyfbiE e7QomQCddE6ZED2EPKKYRsEEZvNa8uiTelyFzZlwKqMEMcanWCKD88pvkaAbZsuZUl6v VZgf2sWQwo4LexXa5ME5WCK1vY6PPE0o3cQ+HeWPVp5UmLZQupvte+ytvfEMAPDlq+/N A0Fw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=sHsAxVlf; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id ada2fe7eead31-4c9c98c8dadsi4343026137.478.2025.04.15.12.35.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Apr 2025 12:35:15 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=sHsAxVlf; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 29DE282B45; Tue, 15 Apr 2025 21:34:56 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="sHsAxVlf"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id AFCA782B54; Tue, 15 Apr 2025 21:34:54 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 8512482A27 for ; Tue, 15 Apr 2025 21:34:52 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jerome.forissier@linaro.org Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-43cf680d351so69065e9.0 for ; Tue, 15 Apr 2025 12:34:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1744745692; x=1745350492; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=1olj/4/0QjVfT/SCqMEBitoG5ohCI4M4SdcbZFvqcio=; b=sHsAxVlfqsHhyK+5Rl1jMYHNgbQIXICujUE3FRm9x+Ht+mr4IpxSUrbhSWeQZ1Q6K+ 1fWjQB3w7u960OACPkndFXZy5OyW+Yf2/UKPBlvG9uHFFboCFFv0fTCKq3kVku6LRMcG XiovlAJb5gzIpq4Sojz4K+1uBF5a25nWfcynGwHb1Q5VpXYxvzvaofsnhEAXDSkWLyq6 F/qqmgk/hWCgqdUT6pYKxnkQxGK20KD53uPUBNlMWnYQcXnJkeFzHrmOgcaViNXvYMNw jr8VyAG2RB9LMMso+jFF+451Z/8p5ZEY4tMnE/jAzAJLZYdUkNvTVAsNilVlK10HN3SH fwAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744745692; x=1745350492; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1olj/4/0QjVfT/SCqMEBitoG5ohCI4M4SdcbZFvqcio=; b=iAJ2OBTDfFagbtOI3PTT9X7Oq6yAj4pB0grmVXIGWVxN8CIcunIe69TWccPhGX4sSq FVXyeJl6V8hLIKyX/sckdjWaOiscvPdlSaM4AAdmmu2+5qT7dTXrFPwiZa1jSkZUK3X3 o5MC5p9TeWiMsHZCozgMqy9YwlQj5vbfglTnpcfUTJoAUnaQ6IrdpX71oHQwzU68J+WA rtjJ8wsaihxk3jyvs/OsoLaDwbw9bAFLkPDZCTqav3LXDMTAiT6cvSH7QZR+brQeoFA8 6nJ+R64Re/i4jCcO1I54/ATpbaWxzx/41UOAnTgkuN9n/1wqErlNw2VDjj3KNHUBr6xZ T7Jg== X-Gm-Message-State: AOJu0Ywl52oUF1BOm9kiWJu6/18NjJZPz7+weD7U0obb3fsQt73SaoPR bXYK/ZIXI8D3m6XiP44DGfcddt1B6BpPpK63/e0i/Ak8Q3GIbrwG3Ic70XBcRxaxd+nFfBvPDBI AsXA= X-Gm-Gg: ASbGncsm1RurrTCNM6yDiq3EJ0OMg5SQZNeJkeQvn3eFwe1UJ/B1o47UXaVcOeeYYSA HkKyYQyYZXb8nA2n0xndXHQa6Bg3/hqIel6ppm+Yjkmlo60DVzSERRZ4kPDnIqiaye5bKwlyoI6 c+wabHd52jTe6cW24jVFit7DitQfPU1QkLAEpW7ZYtlCux58jim6GC1ERvf4cxKCOzomnRObBrj MrewWSfUOGOwOkQIL2vWulOtj2Po4eGbRvViPel0c550B6dSnoF402S6IamDQV1r+9Pvh03Lka9 ShMV2rUvZwLt7fub48gx6vEIImWN5SFhr08WBQ7HvrI5yLn9zhk6mrCx3qw= X-Received: by 2002:a5d:6d88:0:b0:390:e9ee:f27a with SMTP id ffacd0b85a97d-39ee27738f9mr662809f8f.28.1744745691703; Tue, 15 Apr 2025 12:34:51 -0700 (PDT) Received: from builder.. ([2a01:e0a:3cb:7bb0:6ebc:6ce:770e:95f9]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-39eaf43d046sm15520484f8f.63.2025.04.15.12.34.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Apr 2025 12:34:51 -0700 (PDT) From: Jerome Forissier To: U-Boot mailing list Cc: Jerome Forissier , Heinrich Schuchardt , Adriano Cordova , Ilias Apalodimas , Joe Hershberger , Mikhail Kshevetskiy , Ramon Fried , Simon Glass , Sughosh Ganu , Tom Rini Subject: [PATCH v4 2/4] net, net-lwip: wget: suppress console output when called by EFI Date: Tue, 15 Apr 2025 21:34:27 +0200 Message-ID: <20250415193436.1240804-3-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250415193436.1240804-1-jerome.forissier@linaro.org> References: <20250415193436.1240804-1-jerome.forissier@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Functions called from EFI applications should not do console output. Refactor the wget code to implement this requirement. The wget_http_info struct is used to hold the boolean that signifies whether the output is allowed or not. Signed-off-by: Jerome Forissier Reported-by: Heinrich Schuchardt --- Changes in v4: - Patch renamed, deals with NET in addition to NET_LWIP Changes in v3: - New patch include/net-common.h | 2 ++ lib/efi_loader/efi_net.c | 2 +- net/lwip/wget.c | 33 +++++++++++++++++++++++---------- net/wget.c | 23 +++++++++++++++++------ 4 files changed, 43 insertions(+), 17 deletions(-) diff --git a/include/net-common.h b/include/net-common.h index 30860f5975a..1043b24d0b9 100644 --- a/include/net-common.h +++ b/include/net-common.h @@ -555,6 +555,7 @@ enum wget_http_method { * Filled by client. * @hdr_cont_len: content length according to headers. Filled by wget * @headers: buffer for headers. Filled by wget. + * @silent: do not print anything to the console. Filled by client. */ struct wget_http_info { enum wget_http_method method; @@ -565,6 +566,7 @@ struct wget_http_info { bool check_buffer_size; u32 hdr_cont_len; char *headers; + bool silent; }; extern struct wget_http_info default_wget_info; diff --git a/lib/efi_loader/efi_net.c b/lib/efi_loader/efi_net.c index b3291b4f1d5..9ff0b691ee1 100644 --- a/lib/efi_loader/efi_net.c +++ b/lib/efi_loader/efi_net.c @@ -51,7 +51,7 @@ static int next_dp_entry; static struct wget_http_info efi_wget_info = { .set_bootdev = false, .check_buffer_size = true, - + .silent = true, }; #endif diff --git a/net/lwip/wget.c b/net/lwip/wget.c index 2b512a1bc84..3529768eb06 100644 --- a/net/lwip/wget.c +++ b/net/lwip/wget.c @@ -217,7 +217,8 @@ static err_t httpc_recv_cb(void *arg, struct altcp_pcb *pcb, struct pbuf *pbuf, memcpy((void *)ctx->daddr, buf->payload, buf->len); ctx->daddr += buf->len; ctx->size += buf->len; - if (ctx->size - ctx->prevsize > PROGRESS_PRINT_STEP_BYTES) { + if (!wget_info->silent && + ctx->size - ctx->prevsize > PROGRESS_PRINT_STEP_BYTES) { printf("#"); ctx->prevsize = ctx->size; } @@ -255,11 +256,15 @@ static void httpc_result_cb(void *arg, httpc_result_t httpc_result, elapsed = get_timer(ctx->start_time); if (!elapsed) elapsed = 1; - if (rx_content_len > PROGRESS_PRINT_STEP_BYTES) - printf("\n"); - 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->silent) { + if (rx_content_len > PROGRESS_PRINT_STEP_BYTES) + printf("\n"); + 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("Http", ctx->server_name, ctx->path, map_sysmem(ctx->saved_daddr, 0), rx_content_len); @@ -339,7 +344,8 @@ static int _set_cacert(const void *addr, size_t sz) mbedtls_x509_crt_init(&crt); ret = mbedtls_x509_crt_parse(&crt, cacert, cacert_size); if (ret) { - printf("Could not parse certificates (%d)\n", ret); + if (!wget_info->silent) + printf("Could not parse certificates (%d)\n", ret); free(cacert); cacert = NULL; cacert_size = 0; @@ -392,6 +398,12 @@ int wget_do_request(ulong dst_addr, char *uri) ctx.prevsize = 0; ctx.start_time = 0; + if (!wget_info) + wget_info = &default_wget_info; + + net_lwip_set_current(); + udev = eth_get_dev(); + if (parse_url(uri, ctx.server_name, &ctx.port, &path, &is_https)) return CMD_RET_USAGE; @@ -421,9 +433,10 @@ int wget_do_request(ulong dst_addr, char *uri) if (cacert_auth_mode == AUTH_REQUIRED) { if (!ca || !ca_sz) { - printf("Error: cacert authentication mode is " - "'required' but no CA certificates " - "given\n"); + if (!wget_info->silent) + printf("Error: cacert authentication " + "mode is 'required' but no CA " + "certificates given\n"); return CMD_RET_FAILURE; } } else if (cacert_auth_mode == AUTH_NONE) { diff --git a/net/wget.c b/net/wget.c index c73836cbc9d..3c0fff488eb 100644 --- a/net/wget.c +++ b/net/wget.c @@ -59,8 +59,10 @@ static inline int store_block(uchar *src, unsigned int offset, unsigned int len) if (CONFIG_IS_ENABLED(LMB) && wget_info->set_bootdev) { if (store_addr < image_load_addr || lmb_read_check(store_addr, len)) { - printf("\nwget error: "); - printf("trying to overwrite reserved memory...\n"); + if (!wget_info->silent) { + printf("\nwget error: "); + printf("trying to overwrite reserved memory\n"); + } return -1; } } @@ -76,6 +78,9 @@ static void show_block_marker(u32 packets) { int cnt; + if (wget_info->silent) + return; + if (content_length != -1) { if (net_boot_file_size > content_length) content_length = net_boot_file_size; @@ -101,11 +106,15 @@ static void tcp_stream_on_closed(struct tcp_stream *tcp) net_set_state(wget_loop_state); if (wget_loop_state != NETLOOP_SUCCESS) { net_boot_file_size = 0; - printf("\nwget: Transfer Fail, TCP status - %d\n", tcp->status); + if (!wget_info->silent) + printf("\nwget: Transfer Fail, TCP status - %d\n", + tcp->status); return; } - printf("\nPackets received %d, Transfer Successful\n", tcp->rx_packets); + if (!wget_info->silent) + printf("\nPackets received %d, Transfer Successful\n", + tcp->rx_packets); wget_info->file_size = net_boot_file_size; if (wget_info->method == WGET_HTTP_METHOD_GET && wget_info->set_bootdev) { efi_set_bootdev("Http", NULL, image_url, @@ -139,7 +148,8 @@ static void tcp_stream_on_rcv_nxt_update(struct tcp_stream *tcp, u32 rx_bytes) tcp->state == TCP_ESTABLISHED) goto end; - printf("ERROR: misssed HTTP header\n"); + if (!wget_info->silent) + printf("ERROR: misssed HTTP header\n"); tcp_stream_close(tcp); goto end; } @@ -346,7 +356,8 @@ void wget_start(void) tcp_stream_set_on_create_handler(tcp_stream_on_create); tcp = tcp_stream_connect(web_server_ip, server_port); if (!tcp) { - printf("No free tcp streams\n"); + if (!wget_info->silent) + printf("No free tcp streams\n"); net_set_state(NETLOOP_FAIL); return; } From patchwork Tue Apr 15 19:34:28 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 881240 Delivered-To: patch@linaro.org Received: by 2002:adf:f902:0:b0:38f:210b:807b with SMTP id b2csp626152wrr; Tue, 15 Apr 2025 12:35:24 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXo1+ffNP401TFiTSzuk1XgLJhMomu2iwM5F4WP/poB7rs8lXP4L1TsMQ2fibGrzz0wqbD99Q==@linaro.org X-Google-Smtp-Source: AGHT+IGY4JXIRxgfnE/XljZlX8NLcvVzL9QVE3Vp4Q2DQxQcRCdIwHpkvxz17fZorVciGzX08F2u X-Received: by 2002:a05:6102:2338:b0:4c1:b0ad:a0bd with SMTP id ada2fe7eead31-4cb52ad6125mr453954137.23.1744745724370; Tue, 15 Apr 2025 12:35:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1744745724; cv=none; d=google.com; s=arc-20240605; b=bcYS4U3z2i/38pqQiTGwv3A2naABwCEvULCHhC3HvKEMSQIAUH6YcOma29fHODjvMQ JS0M1/dMoui4Ul91mPK8llZ7bobYUvUqhpL1zh/1QIM/tdzPbsmsFF3jQmX7YebCcLhq Zyxe8w50GzR+4ijnPI6JV7LMmZ77fx39cAUliPf8C85bXGevykZGz/hjtcanxehfpcEH TYgyT8CJaTA3POC/QKvb4lmdICnQjQYk7Jffel/u+8i3U9qd1RprdgzpPIZkF3jSxZXX Cjd7Gqg437nnhKPU/y9PZVSx66O5cXdRTdnj6V1MEtdWoVJldee8McScP+cYA2+7soe8 02Gw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=K6SlZ+QrGe7TdAv9GQXjMxCdI1gWfzU65+/7rndF1tg=; fh=Nh72lUSdYooCwChGvpRzkAxqTTKBSHBw+XTRimgIlH0=; b=Wlfhx4kHgLs7s9zNG9QPZy0M1sFxGEPRP5ye4MKxwbmgXF2Ga62rq/BLGuO/EaM9Qh GOrXpmDNArwv0ssybI7zP195/k0NuIkupEq9TL00PVtNopECAB3HHGxgdCohjIn3FHqP Yf0cNhCMI5U1JRuDBK43G/aPi2ULTsaCLFhVElZNYBuiZy54I7WjsMhjkz1IXITbn+Z3 trWDxl7lKNdH9lJFeLaRI2JvHuML+/7gk345YgcSmzRIV2du3F4g4L6mmv2HyDDTKa8D D2X/ogLvmXMzDb/afbSyVmLomGuu/cU//SvviH1mAqWtRTRF5Yfb2uP7BSyQJo4S5gEK 1xVg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DnVAKGho; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id ada2fe7eead31-4c9c976c658si4860072137.157.2025.04.15.12.35.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Apr 2025 12:35:24 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DnVAKGho; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 6974782B7F; Tue, 15 Apr 2025 21:34:56 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="DnVAKGho"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 95E8E82B72; Tue, 15 Apr 2025 21:34:55 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 8577082B32 for ; Tue, 15 Apr 2025 21:34:53 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jerome.forissier@linaro.org Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-39c0dfad22aso3501376f8f.2 for ; Tue, 15 Apr 2025 12:34:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1744745693; x=1745350493; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=K6SlZ+QrGe7TdAv9GQXjMxCdI1gWfzU65+/7rndF1tg=; b=DnVAKGhoj56vjxRh2T4lyMe8c7+3HbW+IBJ6gqB48diSzHHFGkBkN3fU4ZlGcgOe7a 114pdvr7GMDGtpIklkTknr3VRmAnEGPqYYJ5Rhk2y5kz6+1uwe7wqiIKQ/Dg9b4e4+f1 CfBJAZi+s7xSAlHO9QkzCv9bBaHb+i25gLD3p0yLcIqhmOTiTjfUPbuUR4baPYhTm5Hp TyA+k1gAHYMJnFwhcSbfAA1BN/maynqbT0OiQzhDo/0TmBjWNhRKeFgj0STYEoyBf9Yl OmhuFkxnJzWhebGMypk61CmofHQOQNEmbxA2CiocIEHRgpPwRZFDPZzKMQy2+Sg96bXV gudw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744745693; x=1745350493; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=K6SlZ+QrGe7TdAv9GQXjMxCdI1gWfzU65+/7rndF1tg=; b=H/ycrbxyar3kBG8Y6cqLYolX6uFzTR/iw6KMnpBQ2r7sEmdBzM5t0WpD7nYdOaL9/r lG27Ze0PWrAzFUZQ9h3eG/3kiBk/PEV3mvj8YYdbxNJsEx9DVFD8NR7+w6I2bzuhroMI puO5tx0FPTN0BHY1XOy2LcBJ3q5xv1OrMKDYYu9mKtfweXR+HBeCFze6XdtVn63K1UfP R4uab5c6VSexRs2LOHsDqqbZvyuud2tguucVAofO6BsuRChhxriS5S8xmHivcYkc5K+J 7Sj7lgHw3zP5gAxaXi7P6qyym8e+/Dq7KB6Z1TSjC9hFUaeOjsJ9B4HZa0Ft8Etp+HYd bO7w== X-Gm-Message-State: AOJu0YzAJkhKeg3BKdKSnSQesMpkmHEvCs/xZ2sqD9mrAD9D4ymbkcId NWf9A/OS+uGtiJ4z/O8Ks21WQ1t7dtlh9j/Qtqtduf8FwbtN55h7dr8gNZEmPPOJxwZwe1qSd0X TwVg= X-Gm-Gg: ASbGncufeQlcPqjKEBvSlVkdwV5sW6nNETVNeO6gOINYBnNQwVFOh/YcNsxIlGxD+M3 kbg53v97lk9Gm/PKFEFTMK7dLTtMz4DdfDgp++3yBLtDBL5AoM7dKEZIqkul+PeLzKZ0kYqkTH3 XinxxN09OZuRQDkAEXzdOi2wZe/hEiyMNufnLqKr1fN0RuRVQKY6BQO8shwDdBsEIf2y19Hp2SB CoQwCRVMTJvjeBaGCmWiRbH+BMNtqThoKc5BeK2FQlqBTXIDDJqVqDfaJs+bDSbddN1dEriZ09r iy6Wl9VOmjPsnNuuO2iQY99mbdzpi9NAWz/J0FA/flbrJVQ1Bmr7PEWbGpI= X-Received: by 2002:a05:6000:1449:b0:39a:c9ae:9efe with SMTP id ffacd0b85a97d-39ee2736ce7mr585613f8f.18.1744745692680; Tue, 15 Apr 2025 12:34:52 -0700 (PDT) Received: from builder.. ([2a01:e0a:3cb:7bb0:6ebc:6ce:770e:95f9]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-39eaf43d046sm15520484f8f.63.2025.04.15.12.34.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Apr 2025 12:34:52 -0700 (PDT) From: Jerome Forissier To: U-Boot mailing list Cc: Jerome Forissier , Sughosh Ganu , Adriano Cordova , Heinrich Schuchardt , Ilias Apalodimas , Joe Hershberger , Ramon Fried , Simon Glass , Tom Rini Subject: [PATCH v4 3/4] net-lwip: wget: add LMB and buffer checks Date: Tue, 15 Apr 2025 21:34:28 +0200 Message-ID: <20250415193436.1240804-4-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250415193436.1240804-1-jerome.forissier@linaro.org> References: <20250415193436.1240804-1-jerome.forissier@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Legacy NET wget invokes a store_block() function which performs buffer validation (LMB, address wrapping). Do the same with NET_LWIP. Signed-off-by: Jerome Forissier Suggested-by: Sughosh Ganu --- Changes in v4: - The 'silent' boolean in stored in struct wget_http_info (same as NET) Changes in v3: - store_block(): add Sphinx-like documentation - store_block(): do not print to the console if ctx->silent Changes in v2: - httpc_recv_cb(): add a call to altcp_abort(). Otherwise the transfer continues and we try to write later blocks which makes no sense if one has been rejected already. Thanks Sughosh G. for testing and reporting. net/lwip/wget.c | 64 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 55 insertions(+), 9 deletions(-) diff --git a/net/lwip/wget.c b/net/lwip/wget.c index 3529768eb06..42d364e4115 100644 --- a/net/lwip/wget.c +++ b/net/lwip/wget.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include "lwip/altcp_tls.h" #include @@ -201,11 +202,58 @@ static int parse_legacy_arg(char *arg, char *nurl, size_t rem) return 0; } +/** + * store_block() - copy received data + * + * This function is called by the receive callback to copy a block of data + * into its final location (ctx->daddr). Before doing so, it checks if the copy + * is allowed. + * + * @ctx: the context for the current transfer + * @src: the data received from the TCP stack + * @len: the length of the data + */ +static int store_block(struct wget_ctx *ctx, void *src, u16_t len) +{ + ulong store_addr = ctx->daddr; + uchar *ptr; + + /* Avoid overflow */ + if (wget_info->buffer_size && wget_info->buffer_size < ctx->size + len) + return -1; + + if (CONFIG_IS_ENABLED(LMB) && wget_info->set_bootdev) { + if (store_addr + len < store_addr || + lmb_read_check(store_addr, len)) { + if (!wget_info->silent) { + printf("\nwget error: "); + printf("trying to overwrite reserved memory\n"); + } + return -1; + } + } + + ptr = map_sysmem(store_addr, len); + memcpy(ptr, src, len); + unmap_sysmem(ptr); + + ctx->daddr += len; + ctx->size += len; + if (ctx->size - ctx->prevsize > PROGRESS_PRINT_STEP_BYTES) { + if (!wget_info->silent) + printf("#"); + ctx->prevsize = ctx->size; + } + + return 0; +} + static err_t httpc_recv_cb(void *arg, struct altcp_pcb *pcb, struct pbuf *pbuf, err_t err) { struct wget_ctx *ctx = arg; struct pbuf *buf; + err_t ret; if (!pbuf) return ERR_BUF; @@ -214,19 +262,17 @@ static err_t httpc_recv_cb(void *arg, struct altcp_pcb *pcb, struct pbuf *pbuf, ctx->start_time = get_timer(0); for (buf = pbuf; buf; buf = buf->next) { - memcpy((void *)ctx->daddr, buf->payload, buf->len); - ctx->daddr += buf->len; - ctx->size += buf->len; - if (!wget_info->silent && - ctx->size - ctx->prevsize > PROGRESS_PRINT_STEP_BYTES) { - printf("#"); - ctx->prevsize = ctx->size; + if (store_block(ctx, buf->payload, buf->len) < 0) { + altcp_abort(pcb); + ret = ERR_BUF; + goto out; } } - altcp_recved(pcb, pbuf->tot_len); + ret = ERR_OK; +out: pbuf_free(pbuf); - return ERR_OK; + return ret; } static void httpc_result_cb(void *arg, httpc_result_t httpc_result, From patchwork Tue Apr 15 19:34:29 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 881241 Delivered-To: patch@linaro.org Received: by 2002:adf:f902:0:b0:38f:210b:807b with SMTP id b2csp626208wrr; Tue, 15 Apr 2025 12:35:34 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVkU2K7uLeD4JNrd/owOkgbf1eUJB9xtEayJUlVjMq8e0ygB6nJx0ugoOAAwhZZmApbzaAsyw==@linaro.org X-Google-Smtp-Source: AGHT+IGO4LdQIf3nEBoZ4rDfE0Fr5Qcw7pkk2WOm5SUP6KuoMNJE798Zia7K/bXKx79gx9q+sszr X-Received: by 2002:a05:6122:3d16:b0:50b:e9a5:cd7b with SMTP id 71dfb90a1353d-529092ff545mr434713e0c.9.1744745733765; Tue, 15 Apr 2025 12:35:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1744745733; cv=none; d=google.com; s=arc-20240605; b=Oj58VPYB3HKhDEJtBYlMAZ09Qy7zqYi7YP/vXiKyO0aVFxvkZHiil9OiTPo62CZsui fq9g+5PyXGWly/jZhpxLUngueZofFjqRpu2QKc3FevPinChhPBpQBdPuinSe+IFlUQZK tnvFYEHhy9zxg0Yd0/pqyvUICEKUjrn9SP+htdIz3QJRYYTXgjwE+66n+ADa2oBlJhNB KSyAdLp4nh6IQPNOlFGktdOP2gxKuFM9mI2zaTUZKieVpKgLm2H1mqHymubT1avKo7Ok JCf2UPQtYxzdkxPicjZoyywZrpPIow1p6t/YMEvnD9wAyC5PTnHWIFLaVjvtc10XBdjb hHKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=g48XLGI3oYJiC+FEguq2qZRcjoaBxDTm/BABIiCSeQY=; fh=PQg1uaxoFkVPH7GvYt2sPX/rmqpadkXu1gxBQgKczic=; b=kkOQvCRFFE49Ule7mEaROl0EGeDlAQurYOQ6obbBuPBiRg5n5lni0OzihcNXn2Vq7Z IfydNNpuJAAwBlhtpcvP+39CoS6wZyzVjz7subsl9ZQ/nlPzAXK2wHcabX31Pu8HIYeb RGmwDatPkbPsWLD86XJ2JlmbV4TbOlWcfxDjZTGtFhlcyCuflJcLTJTbEYa+empUqzkA UbH9GmGn8gbVDvP5fllPjRgn/KiVSsw7XifEhBaVFrEUsymOe9Cva24wpBI0dWDLV33d yZ8sl9RBR0smNgIy7z8EgCy84fL82/nYE/k0AvMNIAfYgIER8Y8ihEU8hpvPbT2P+UST cRBw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jzJTSAxx; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id 71dfb90a1353d-527abd48967si4900268e0c.13.2025.04.15.12.35.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Apr 2025 12:35:33 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jzJTSAxx; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id AFC2982BA7; Tue, 15 Apr 2025 21:34:58 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="jzJTSAxx"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B218682B92; Tue, 15 Apr 2025 21:34:56 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 63E5182B4A for ; Tue, 15 Apr 2025 21:34:54 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jerome.forissier@linaro.org Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-39c0e0bc733so5168484f8f.1 for ; Tue, 15 Apr 2025 12:34:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1744745693; x=1745350493; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=g48XLGI3oYJiC+FEguq2qZRcjoaBxDTm/BABIiCSeQY=; b=jzJTSAxxVDpg5ndWE3PxZPn5f5SiMI8exzQr7h3oCJcbQu33AuL8NhvNmqmHhv/f67 vs5emf/5rjem/LnzCoHM9tuwY6y8sk5ahKxbwXR9hVWSWJw3p6j4UX9Eh/1YkrglSHzO hJSG4sqakslomfD1C2KMQuvrcoUXUR0k0SSoUcjXPQ0npbk4bw3cj4EySmrM371BKJh0 9AEkUp34Y2XBrzYvKfBXxQNLBmE+zWpFHgIYqXNNQJeW+ThDjH+5LifiorZ9EiG/kl9c uMbeKo+zsYAnAJyrXFft76x7sDlP4h0ihUUZ1hIgb1yK2KfA6vi95clO6FTzdGT3PTV0 bFwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744745693; x=1745350493; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=g48XLGI3oYJiC+FEguq2qZRcjoaBxDTm/BABIiCSeQY=; b=tkJAP4ifmwitoIEsNg5fGMHWkbnSHTjAoVfdbkxJHZ86I+qcm4Orv6101wnrPd0bLe /FTPEbTCEJRQ0V1YybhXWQxmtMF6KnDa601t0cST1J88YRhIlPoXueo4f10Np1u+Ir84 3RXFoZgcF18/TKyIoIak/H7CqnK/VAMFagWXe1/uugFg0irWb8CxL0v+KBdO6Gt1mup3 ZdRopD4jbWKGbnutIgqzChL7IJY2nSTkWBxF62Dxsmugnv+lxOFZgfMNOmQKBqiJi3gD Ec1ZWOVA8wyJBbWJr8xbssm5q24Xi/IlRJCnotsQNWcPrbrJL45yeXDFSeFkVfc/RNv5 p6JA== X-Gm-Message-State: AOJu0YxJc5jyqlcNacXsvzVWgdqmNHRnNqYj2lsWH9b+0qK+SgoTNXMn 2waL6C+QzjN7mgvuA5b6hjTRcZJfCOQ/smDdLfvPRL8TQk2XgLcmJeefqidQMT6+6+S+O6noTjE 3E0k= X-Gm-Gg: ASbGncsa1mSv6C3pmVkV1IygpEjr4eNuEYA4V/fS41+R5h+xxK+87sqwpvRvykXeniB QU7o0Eb8s2aw+O73mMNygBqP87f4yp6waQ/WSnbrDIEx5f59sAap4becg2kWqFcBkmfKF6txiWs K6u9xnGNvXr8MgdvoQQYJZS5GlgiVWUBG8m/dKuPpmbmdOGk3VAV1TXkmfH6xup6hD/YoCZQ4s6 m69286mQ2wTDY5grrXOcSW7DdAgCqRctyo88D9RSH15EjjrsfKW2C7cNo0oD3Z7vO4ZWvd2rUnF iMwsC2SVLiry6Ee6Ya7D4BngMzw8AHzcmKb66vOTsFZz+GNr X-Received: by 2002:a05:6000:22c2:b0:39e:cbde:8889 with SMTP id ffacd0b85a97d-39ee27295fdmr652202f8f.6.1744745693582; Tue, 15 Apr 2025 12:34:53 -0700 (PDT) Received: from builder.. ([2a01:e0a:3cb:7bb0:6ebc:6ce:770e:95f9]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-39eaf43d046sm15520484f8f.63.2025.04.15.12.34.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Apr 2025 12:34:53 -0700 (PDT) From: Jerome Forissier To: U-Boot mailing list Cc: Jerome Forissier , Sughosh Ganu , Ilias Apalodimas , Joe Hershberger , Ramon Fried , Tom Rini Subject: [PATCH v4 4/4] net-lwip: tftp: add LMB and buffer checks Date: Tue, 15 Apr 2025 21:34:29 +0200 Message-ID: <20250415193436.1240804-5-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250415193436.1240804-1-jerome.forissier@linaro.org> References: <20250415193436.1240804-1-jerome.forissier@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Legacy NET tftp invokes a store_block() function which performs buffer validation (LMB, address wrapping). Do the same with NET_LWIP. Signed-off-by: Jerome Forissier Suggested-by: Sughosh Ganu --- (no changes since v3) Changes in v3: - store_block(): add Sphinx-like documentation net/lwip/tftp.c | 56 +++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 45 insertions(+), 11 deletions(-) diff --git a/net/lwip/tftp.c b/net/lwip/tftp.c index 123d66b5dba..c7f1420ca0f 100644 --- a/net/lwip/tftp.c +++ b/net/lwip/tftp.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -31,6 +32,47 @@ struct tftp_ctx { enum done_state done; }; +/** + * store_block() - copy received data + * + * This function is called by the receive callback to copy a block of data + * into its final location (ctx->daddr). Before doing so, it checks if the copy + * is allowed. + * + * @ctx: the context for the current transfer + * @src: the data received from the TCP stack + * @len: the length of the data + */ +static int store_block(struct tftp_ctx *ctx, void *src, u16_t len) +{ + ulong store_addr = ctx->daddr; + void *ptr; + + if (CONFIG_IS_ENABLED(LMB)) { + if (store_addr + len < store_addr || + lmb_read_check(store_addr, len)) { + puts("\nTFTP error: "); + puts("trying to overwrite reserved memory...\n"); + return -1; + } + } + + ptr = map_sysmem(store_addr, len); + memcpy(ptr, src, len); + unmap_sysmem(ptr); + + ctx->daddr += len; + ctx->size += len; + ctx->block_count++; + if (ctx->block_count % 10 == 0) { + putc('#'); + if (ctx->block_count % (65 * 10) == 0) + puts("\n\t "); + } + + return 0; +} + static void *tftp_open(const char *fname, const char *mode, u8_t is_write) { return NULL; @@ -71,17 +113,9 @@ static int tftp_write(void *handle, struct pbuf *p) struct tftp_ctx *ctx = handle; struct pbuf *q; - for (q = p; q; q = q->next) { - memcpy((void *)ctx->daddr, q->payload, q->len); - ctx->daddr += q->len; - ctx->size += q->len; - ctx->block_count++; - if (ctx->block_count % 10 == 0) { - putc('#'); - if (ctx->block_count % (65 * 10) == 0) - puts("\n\t "); - } - } + for (q = p; q; q = q->next) + if (store_block(ctx, q->payload, q->len) < 0) + return -1; return 0; }