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 0FCDAC433EF for ; Wed, 30 Mar 2022 17:13:20 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 965DE8411C; Wed, 30 Mar 2022 19:13:17 +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="Sy+EeXZ3"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 104AE8413C; Wed, 30 Mar 2022 19:13:16 +0200 (CEST) Received: from mail-qt1-x835.google.com (mail-qt1-x835.google.com [IPv6:2607:f8b0:4864:20::835]) (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 503F584064 for ; Wed, 30 Mar 2022 19:13:12 +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-qt1-x835.google.com with SMTP id bp39so18662141qtb.6 for ; Wed, 30 Mar 2022 10:13:12 -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=Pd4a/PYSdtJPFEtR9dONeTm7KUAPD6AoUTj7CZk1bpY=; b=Sy+EeXZ3OCEpNxnhYxth7X0a/nZz5wvf/96xaJqlD6Ut1b2zmwwhVGmQIDlSXrFSp+ 5YqgbQub/ewpP3u895TvQn2twsHkpRit1BBMObSaRwcKjZTlqopR5N4b1n0fzTcOtg7k dV4yNOuFW1G89xY64+kd9XiHCORd4zZtFvlg1/buHjf4O296T3bnJrmqdCzSYbRFnfWq fIuBg/Tr97l586qoeCvKvVLVM3So8IEhYVEs/yJQk9yse5kdUj6VriKEaapfLpRs58YQ Q/SB3nhQdQnhWktvn4FyYh+NFK3HFIUx4B6j5Am58ljE3WMnGM05+ydMbS1KK0lpO/Rx kOvA== 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=Pd4a/PYSdtJPFEtR9dONeTm7KUAPD6AoUTj7CZk1bpY=; b=Sdf9vyO9ySsfCFaXOqsMSlTuQtjXHVvKw5AXLha4a/HWrGv9BUSonra3Np4VAh7XzB m/GWQF3rw5kDs4GMBMoDyBLxPiMBK4uIIRCufdOhPBzbzsX23qKZN/TL9rBk/I26Nl0q 1+B3VYXW4JLs4jtUSHUlk7TMqgQ9lfPOH4Q8gzQ+zqlobC1/xZZhdemhasUL5KVbbKU6 RdSo0FfKEGUcQO8YE1kh4+nL6Ctn8czZ9zX6/AWT19twwpK+hrMX//vsjYULP9zoe5fy eu9AgT/k79HlAAuwaY05izLrRJ90ajtm5TMLwn3WTqzRzu4ssqEmOrphv7plEHgMECrd 1zrA== X-Gm-Message-State: AOAM530AjOAeCvahmv8oXwB7IPNjSonNdWns1Q4uBskel5TJc5IdCQmz depsMCnqlWFnNOWEVP04WlU= X-Google-Smtp-Source: ABdhPJxZqDFBpQZA1ztm9GiJhy5wTO39970wOmGtdm64nMN7Z1DrVh2jf1OyGnx4p5zwGIB3a3+eBw== X-Received: by 2002:a05:622a:1493:b0:2e2:3003:5eda with SMTP id t19-20020a05622a149300b002e230035edamr539446qtx.428.1648660391132; Wed, 30 Mar 2022 10:13:11 -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 3-20020a370503000000b0067b03f03589sm11089225qkf.53.2022.03.30.10.13.10 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 30 Mar 2022 10:13:10 -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:13:10 -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:07 PM, Andy Shevchenko wrote: > On Wed, Mar 30, 2022 at 8:01 PM Andy Shevchenko > wrote: >> On Wed, Mar 30, 2022 at 7:49 PM Sean Anderson wrote: > > ... > >>> #define for_each_console_dev(i, file, dev) \ >>> - for (i = 0, dev = console_devices[file][i]; \ >> >> When we enter the loop, the dev is assigned and perhaps valid >> >>> - i < cd_count[file]; \ >>> - i++, dev = console_devices[file][i]) >>> + for (i = 0; i < cd_count[file] && \ >> >> Not the case anymore. >> >>> + (dev = console_devices[file][i]); i++) > > On the second look, it seems a bit unusual, but for loop checks the > condition before entering and in such case the dev will be assigned if > the count is greater than 0. > So, basically the difference is that dev is left completely > uninitialized in case of count==0. However, it may not be a problem. Well, in such a case, the value of console_devices[file][i] is bogus anyway, so stack garbage is just as good. If it turns out to be a problem, this can always be rewritten to for (i = 0 dev = NULL; i < cd_count[file] && \ (dev = console_devices[file][i]); i++) > Anyways, I would rather see better written for-loop that we see the iterations Sorry, I'm not sure what you mean by this... Ideally this loop would be written like for (i = 0 dev = NULL; i < cd_count[file]; i++) { dev = console_devices[file][i]); /* loop body */ } which is much more obviously correct. But since this macro must use the following block as the loop body, it's trickier to do. --Sean