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 8C5C7C433F5 for ; Wed, 30 Mar 2022 17:26:16 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 613AC83D0C; Wed, 30 Mar 2022 19:26:14 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com 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=gmail.com header.i=@gmail.com header.b="GT/fiY9g"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E712B840A2; Wed, 30 Mar 2022 19:26:11 +0200 (CEST) Received: from mail-qv1-xf2e.google.com (mail-qv1-xf2e.google.com [IPv6:2607:f8b0:4864:20::f2e]) (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 D9A4D83B21 for ; Wed, 30 Mar 2022 19:26:06 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-qv1-xf2e.google.com with SMTP id kd21so14470917qvb.6 for ; Wed, 30 Mar 2022 10:26:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=haol9W+U0sxcen+ysf4JI+5LESDQ+dW4C56F0CvtrmI=; b=GT/fiY9ggoDv9GXenpfQgSs+sors7OG/I/YlUg4BzaydyfLY5g92I7MDo202HLOmsi Z0dHhAU1kxwZpRhrtS9sI0G/P0n5TGf6tV7dgwvvidavXu2U95zDgHvGjhqCWc+ijrpp Os3yCOW9QqK8kwY7+EophqayI6EgD2rRg3aHANYwjsfQkYebtSfAYFdDrwPxx7ht3EFf 4FxOxVPOOrpqow5Nrq1lCwQv1ivfahrD7Vjxe2B0neJ2xmleOsOd86M2IEm/g+fwbeLd iVkM8oqegeYDvlRNJ6mMEAxobTg8TKolAPEriusJMMI7MrvX5R8ms0EtxMZppTlqL7wa CNog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=haol9W+U0sxcen+ysf4JI+5LESDQ+dW4C56F0CvtrmI=; b=k4Mc1CeTtd5nvxGzmWN8p/lBSdWfAtFfeRgSpwW+en/zpcvJpgWow1skQaqVkYoEXp ciUezC8VcRVM818EZRdy556quMvWuXSNqMeA5XOPteVqZ9kGwiN4/e2lC7E32pUK3wE2 tUzuH9a/fH2WdUPLnT1qM+Ml/RFc17pjTMHgu8nHQpNwfG2T/8tGzZeryBp/N/cSK2SI yCrOqa0+Q2zJn+C/Yl1cfI9F9u11XrcxhM4g34m8nwV1spgP67MaGDZWAFEIPJLc5M04 rawaxhkNChBnMGna3n+2G1jUI9T6ZOPLtsKEpQ4nxZ/YUKu//h4XIrr3qSDSWxIZZ9wu IT5Q== X-Gm-Message-State: AOAM532DX/vQsn79wvXQ37HDyPoSapmic62RhOUE5ZcUVZ4tyq6teOzC C4dqokdRha0xDjJQfcRf57bQCkGmCtc= X-Google-Smtp-Source: ABdhPJz+ybqV03KMOmL4Lb7FK/vNYv/YiPlKc44dbGEIhFdWeQMwT0OnTcqsgg1dD0mFCa/RXWrjaA== X-Received: by 2002:a05:6214:2529:b0:443:7b3d:2d5c with SMTP id gg9-20020a056214252900b004437b3d2d5cmr461601qvb.50.1648661160682; Wed, 30 Mar 2022 10:26:00 -0700 (PDT) Received: from [192.168.1.201] (pool-108-18-137-133.washdc.fios.verizon.net. [108.18.137.133]) by smtp.googlemail.com with ESMTPSA id z28-20020a05620a101c00b0067d940a74b2sm10798576qkj.39.2022.03.30.10.26.00 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 30 Mar 2022 10:26:00 -0700 (PDT) Subject: Re: [PATCH] IOMUX: Fix access past end of console_devices To: Andy Shevchenko Cc: U-Boot Mailing List , Simon Glass , Andy Shevchenko References: <20220330164902.431732-1-seanga2@gmail.com> From: Sean Anderson Message-ID: Date: Wed, 30 Mar 2022 13:25:59 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit 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.5 at phobos.denx.de X-Virus-Status: Clean On 3/30/22 1:13 PM, Andy Shevchenko wrote: > On Wed, Mar 30, 2022 at 7:49 PM Sean Anderson wrote: > > Also I don't like to have workarounds for the broken tools. > But if you still want to have something, what about rather this > >> #define for_each_console_dev(i, file, dev) \ >> - for (i = 0, dev = console_devices[file][i]; \ >> - i < cd_count[file]; \ >> - i++, dev = console_devices[file][i]) >> + for (i = 0; i < cd_count[file] && \ >> + (dev = console_devices[file][i]); i++) > > for (i = 0, dev = console_devices[file][0]; \ > i < cd_count[file]; \ > i++, dev = console_devices[file][i]) > > ? > > Or if it's still complains > > for (i = 0, dev = cd_count[file] ? console_devices[file][0] : NULL; \ > i < cd_count[file]; \ > i++, dev = console_devices[file][i]) > > ? > The problem is not the first assignment but the last. Consider the case when cd_count[file] = 1 i = 0, dev = console_devices[file][0]; // OK i < cd_count[file] // 0 < 1 // loop body i++, dev = console_devices[file][1] // Oops, past the end i < cd_count[file] // 1 < 1, loop exit --Sean