Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9CF96C4332F for ; Sun, 13 Nov 2022 20:45:50 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 2EC6284D45; Sun, 13 Nov 2022 21:45:48 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1668372348; bh=BgN86FkLF+keXPCibY5jrj6or0R5zoTvpSXZQcD9WUM=; h=From:To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From; b=ZzogocnTleTmQp6OtoiOH+s45Ga7PHQ+SDDIrGxhJEwuIO6F53C7vc6Pc/VbQpKhk iSV+8bi0YybcsQyVabRBpdDpzobaaw8Sp4+MQUnmPdddGTL7OWqacuP149M+TvIsx1 YcWxmPLOMJckWONaeKLMitUd2X619ML53rXUZoxmlpniSCLy8RbzScwqyKbaeAA8Nv KSdi8WmiOFQwV1PojQ6T75h4tERg0zMl0DCpCjnAdauLEep0u7CM3QDgs8I4LfpVvt lBcVDuzKKPPkMptjXnnwr2PAsXudlQoBd/fKS/H7WxXy0ab6BNNSial6D5q30qpSXB sU0Z3oWyWnKCA== Received: from tr.lan (ip-86-49-120-218.bb.vodafone.cz [86.49.120.218]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: marex@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id 4C38B84D45; Sun, 13 Nov 2022 21:45:46 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1668372346; bh=BgN86FkLF+keXPCibY5jrj6or0R5zoTvpSXZQcD9WUM=; h=From:To:Cc:Subject:Date:From; b=aW/9jaJqo1xUuBiLz1QwJfY6YpvY1B4MTL2P13OkmZ7+RrhWS73Vq6tGoGtMgB0iN +FnRwQf9kEaKj2o3m6ksNEoAHp4mBPSrQ11KlxBCtHz12bkDya7sipRkh7qMDq1p5u bRSRrzN/7pdXjBStG5U/klhlN/ELE/NsJITRBES2EKZE6O1fr+7x4grBH2z+pa37Ah qSF1KUNCt00ZICAfwvon8PCSLeX0QEBn6hjXB6mAOdbkzMAqhzREzusfCrbHdoxmgb nzV1m+a+0lrS8gUo3X51rbuQF9duG8FVGvuRoh2a+TeJvh8LUGhjSp1ipOXdaanHez NzHQ5yOlO9VSA== From: Marek Vasut To: u-boot@lists.denx.de Cc: Marek Vasut , Heinrich Schuchardt , Simon Glass , Tom Rini Subject: [PATCH 1/2] cmd: fdt: Fix iteration over elements above index 2 in fdt get Date: Sun, 13 Nov 2022 21:45:34 +0100 Message-Id: <20221113204535.104440-1-marex@denx.de> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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.6 at phobos.denx.de X-Virus-Status: Clean Always increment both the iterator and pointer into the string property value by length of the current element + 1 (to cater for the string delimiter), otherwise the element extracted from the string property value would be extracted from an offset that is multiple of the length of the first element, instead of sum of element lengths until select index. This fixes 'fdt get value' operation for index above 2. Fixes: 13982ced2cc ("cmd: fdt: Add support for reading stringlist property values") Signed-off-by: Marek Vasut --- Cc: Heinrich Schuchardt Cc: Simon Glass Cc: Tom Rini --- cmd/fdt.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/cmd/fdt.c b/cmd/fdt.c index 4b2dcfec863..8e51a431261 100644 --- a/cmd/fdt.c +++ b/cmd/fdt.c @@ -60,11 +60,14 @@ static int fdt_value_env_set(const void *nodep, int len, * Iterate over all members in stringlist and find the one at * offset $index. If no such index exists, indicate failure. */ - for (i = 0; i < len; i += strlen(nodec) + 1) { - if (index-- > 0) + for (i = 0; i < len; ) { + if (index-- > 0) { + i += strlen(nodec) + 1; + nodec += strlen(nodec) + 1; continue; + } - env_set(var, nodec + i); + env_set(var, nodec); return 0; } -- 2.35.1