From patchwork Mon Nov 27 12:57:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 747553 Delivered-To: patch@linaro.org Received: by 2002:a5d:6706:0:b0:32d:baff:b0ca with SMTP id o6csp3135219wru; Mon, 27 Nov 2023 05:04:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IEHyWJWg/20hihjawxpQvyStshQErPlO1/z/JwEeq6vGtPKdXlMvMnr3zyHESFMUh8v8aNJ X-Received: by 2002:a05:6a00:22c5:b0:6c2:cf23:3e21 with SMTP id f5-20020a056a0022c500b006c2cf233e21mr12640882pfj.17.1701090272564; Mon, 27 Nov 2023 05:04:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701090272; cv=none; d=google.com; s=arc-20160816; b=lXIZSyrD9CVyKK6UB51XzEDiSKI1BIZwfeWotKKacZSDXwLEJHjGZzNPFHWmhdFJGX R7r2hbXdnqZxxMgI+4v2F6gF040cPdSugEkptGMGha3XeqQ6ByCgsNI+d96fjRxDU8Ju NOhhPNFgaJIj+r4x5YCADfE1Y6p7lGAP7BrJZ1STWysd9TVnPfGctzDNY0cd2bwnqGJB n6SzaJpPVzwg8bLOVFBWCURqzluzIYx7p3l6AsysyULZ0OPytE/icY54TNBT6ATsLWgB MwGxLIcOTa/d1AlF1+eak6TFQA75BNOvF24GiFa08OM8HF9XQxnxmjTOPapezs6W6dqE wSwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; 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=VLaiV9HF80Rqq8fubeu6ab2vfbV1DnaWvPksOl/hwC0=; fh=QyNHqymfSLfpkarWtc7IKVRHBXLRqHmsXw8S5qDkAYI=; b=xWM85/NhN2SAtMACnmyT8GRsE5h/xjnsoCoSo7Fzzl6Qc8UVDwNcS9lsRm5Wv1hmJY kHzLnX7+qfNBpj4KT3GB8RfQ89SxdOmUuuqSolvrqBb8GzX8tCKuyjMYCrknhD5lKxop i9TUWbEAJW528Gm/drFJuE+tsjF/sLHEvhFofy7Y9ukHWrWwCb1wzWFYN5XVp2C9gLlm QOLeTe1OhwgUWk02n6ScP4DFUiTwmOAg6O3czCBL+q3PrZY28pDirGI2+6/IK/ALGeo/ 23TeQfiKFkZspbZuoy81sJaoT+6q2QiEK9qGknV5rLZ4GsKzp4q5AP6+VL4GdZy3iYgo bGsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=I08CgCnE; 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 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 o66-20020a634145000000b005be03f0da7esi10548121pga.174.2023.11.27.05.04.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Nov 2023 05:04:32 -0800 (PST) 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=I08CgCnE; 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 Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id A0AB387652; Mon, 27 Nov 2023 14:00:54 +0100 (CET) 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="I08CgCnE"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9FA9D87657; Mon, 27 Nov 2023 14:00:51 +0100 (CET) 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,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-lf1-x130.google.com (mail-lf1-x130.google.com [IPv6:2a00:1450:4864:20::130]) (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 A7A2287570 for ; Mon, 27 Nov 2023 14:00:49 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=maxim.uvarov@linaro.org Received: by mail-lf1-x130.google.com with SMTP id 2adb3069b0e04-50aab20e828so5952459e87.2 for ; Mon, 27 Nov 2023 05:00:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1701090048; x=1701694848; 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=VLaiV9HF80Rqq8fubeu6ab2vfbV1DnaWvPksOl/hwC0=; b=I08CgCnEfW6uDZvYrTpc+DqKwPjXcO/DG2p3vMIiaBd7fAXhVoJn5cczinlkf2itA/ 6eS+mHIhXTYHkehWFx6cuSBPjRipMd+n7NbJQnkKl0Gu1sVbIdDgKlS+tEuwPfbZ4cJ7 DZtHNfd/xHrdxulvWGZsEndnS6eOQC2B+i79FNeajHiuT/uA2hy1cVrSDKcDztbE9rwE 8yWDzW8rCafs0cvh1PRscotnbBouIAZDhqzzO99o7+J18jeqGouyRziC3NWqER8E2eX5 IcIJzI8T2f1rslx8Dt7DROz4zQLGLwdQzTqtki9YMY80Njfsooegc8EX5rkvsZGnFkKy TwDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701090048; x=1701694848; 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=VLaiV9HF80Rqq8fubeu6ab2vfbV1DnaWvPksOl/hwC0=; b=sXnJHQ146PUg7q5PnnzlqyJtrZMtSfFqM8InHCt5BsJCl315OjhVwlzTD33SExlzUD mQ6r0T1T8gviMXalycHlitGKnFqhH41q2upv0cn3kB9LfiVqc5FyFieMOH7tPjLYEc4O KdrwQrqK3teRWtw1wW05d9966/J2POKuTxKOEBEHyV+Fk4Ig4f+wo8xUFYKnFJC0n6NB 3mg/ZzDnNhRwXEll2+mgs4MpmVPXQ4IOIqaaIGgXLoMKxD2UWCClWEfQ3xjr72Q9/eUV rFcRBJgwlyaxuRVhoajwNBJagNIth4+2v0s9IBbZxbFe+FN0uJErtcsBza7YcQqLFP26 MjfA== X-Gm-Message-State: AOJu0Yw3NbeufR1bUw8sNsDLIl6ux3Frwnm3Emre6iqayWkybcxQ3Rsz 0VXn/a8Sb8g/Er4b3VOfHw89tEvjIQpDQlp9Acl95A== X-Received: by 2002:a05:6512:3b22:b0:50a:71e1:e1d0 with SMTP id f34-20020a0565123b2200b0050a71e1e1d0mr9402569lfv.6.1701090048448; Mon, 27 Nov 2023 05:00:48 -0800 (PST) Received: from localhost.localdomain ([45.82.14.220]) by smtp.gmail.com with ESMTPSA id f16-20020a19ae10000000b005092b887ba2sm1482489lfc.201.2023.11.27.05.00.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Nov 2023 05:00:48 -0800 (PST) From: Maxim Uvarov To: u-boot@lists.denx.de Cc: pbrobinson@gmail.com, ilias.apalodimas@linaro.org, trini@konsulko.com, goldsimon@gmx.de, Maxim Uvarov Subject: [PATHv11 17/43] net: sandbox: fix NULL pointer derefences Date: Mon, 27 Nov 2023 18:57:00 +0600 Message-Id: <20231127125726.3735-18-maxim.uvarov@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20231127125726.3735-1-maxim.uvarov@linaro.org> References: <20231127125726.3735-1-maxim.uvarov@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 Add additional checks for NULL pointers. Signed-off-by: Maxim Uvarov --- drivers/net/sandbox.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/net/sandbox.c b/drivers/net/sandbox.c index 13022addb6..75d32db3a9 100644 --- a/drivers/net/sandbox.c +++ b/drivers/net/sandbox.c @@ -65,6 +65,9 @@ int sandbox_eth_arp_req_to_reply(struct udevice *dev, void *packet, struct ethernet_hdr *eth_recv; struct arp_hdr *arp_recv; + if (!priv) + return -EAGAIN; + if (ntohs(eth->et_protlen) != PROT_ARP) return -EAGAIN; @@ -82,6 +85,8 @@ int sandbox_eth_arp_req_to_reply(struct udevice *dev, void *packet, /* Formulate a fake response */ eth_recv = (void *)priv->recv_packet_buffer[priv->recv_packets]; + if (!eth_recv) + return -EAGAIN; memcpy(eth_recv->et_dest, eth->et_src, ARP_HLEN); memcpy(eth_recv->et_src, priv->fake_host_hwaddr, ARP_HLEN); eth_recv->et_protlen = htons(PROT_ARP);