From mboxrd@z Thu Jan 1 00:00:00 1970 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 E2A33C32774 for ; Tue, 23 Aug 2022 07:28:04 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 900628460B; Tue, 23 Aug 2022 09:28:01 +0200 (CEST) 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=1661239682; bh=FQNofF16DPALeXJ1DNhsTI5u13hQY8s4wV6yNNDJaGA=; h=To:cc:From:Subject:In-reply-to:References:Date:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=Smpi0vB+RHmDTRKV40ikZS0XCqza8GlSp8kv4e+MxknD8EXZiWC81dkGq2juyaMpl 6in+EN+ZSfm7SfyoYHp0/wIP9SrfxKKvNrtHkGwfUXeTLiqxpxJkaVsONUdLqY+E0z xcYDvIgWMTZlkXtUQGYrZk+NNwbw1/1UO07h7vn51xRYs3wr3y/8OaZ3pNmhx6W+tX /ZBPdAVzyHLdAg+JOxen9dppHyukWd3SwK0rhneYZ/a+ktO2sfUvCBm3BhDm0MGf+M JVtES+Z3Ckz1eXN+4OR9r3QB2FljL9Md6ZEF5pJMjtawivmP8gEut4s2vDPNcHkX1J xaQvFKB/FKVjw== Received: from janitor.denx.de (unknown [62.91.23.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: noc@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id 4B7FE845FF for ; Tue, 23 Aug 2022 09:27:59 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1661239679; bh=FQNofF16DPALeXJ1DNhsTI5u13hQY8s4wV6yNNDJaGA=; h=To:cc:From:Subject:In-reply-to:References:Date:From; b=Jc78qYPlWipMgjgV5jdk3I2zgyvtzyd0n/mCstKvk+JHxyc/+pWj1X23ANkqBIG5f 96SQYewEeoxRUTHMNjv74YC2wkUoJd/wjVhTPysLas6PuFxT3VwGaHlGjZNx7itnte kN7vzPJrznsUFn+qifwq4mfmjH3F28BK20RkmnONu1N6LdtczJOvddrHmY4bZCL3/r opzPZoj6jZQZdfySHRsdt1YAe1YoOIaJjmTCwfepBJyNIgIVFz5Lap2j5TNendxhB+ de9DPDGoouUcxm7RYmILwlgX1GuAITKXdfVzYKXzQGakLNKIhHbPhSXD1X8ZP0CBiA 8EBYOCm/skGww== Received: by janitor.denx.de (Postfix, from userid 108) id E342FA025A; Tue, 23 Aug 2022 09:27:58 +0200 (CEST) Received: from gemini.denx.de (gemini.denx.de [10.4.0.2]) by janitor.denx.de (Postfix) with ESMTPS id 77F2BA0091; Tue, 23 Aug 2022 09:27:50 +0200 (CEST) Received: from gemini.denx.de (localhost [IPv6:::1]) by gemini.denx.de (Postfix) with ESMTP id 2BE9C1E04F9; Tue, 23 Aug 2022 09:27:50 +0200 (CEST) To: Joel Stanley cc: Simon Glass , u-boot@lists.denx.de From: Wolfgang Denk Subject: Re: [PATCH] image: Ensure image header name is null terminated MIME-Version: 1.0 Content-type: text/plain; charset=UTF-8 Content-transfer-encoding: 8bit In-reply-to: <20220823055907.416060-1-joel@jms.id.au> References: <20220823055907.416060-1-joel@jms.id.au> Comments: In-reply-to Joel Stanley message dated "Tue, 23 Aug 2022 15:59:07 +1000." Date: Tue, 23 Aug 2022 09:27:50 +0200 Message-ID: <1878698.1661239670@gemini.denx.de> 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 Dear Joel, In message <20220823055907.416060-1-joel@jms.id.au> you wrote: > When building with GCC 12: > > ../include/image.h:779:9: warning: ‘strncpy’ specified bound 32 equals destination size [-Wstringop-truncation] > 779 | strncpy(image_get_name(hdr), name, IH_NMLEN); > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > Ensure the copied string is null terminated by always setting the final > byte to 0. Shorten the strncpy to IH_NMLEN-1 as we will always overwrite > the last byte. > > We can't use strlcpy as this is code is built on the host as well as the > target. > > Fixes: b97a2a0a21f2 ("[new uImage] Define a API for image handling operations") > Signed-off-by: Joel Stanley > --- > include/image.h | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) > > diff --git a/include/image.h b/include/image.h > index e4c6a50b885f..665b2278b7fb 100644 > --- a/include/image.h > +++ b/include/image.h > @@ -776,7 +776,10 @@ image_set_hdr_b(comp) /* image_set_comp */ > > static inline void image_set_name(image_header_t *hdr, const char *name) > { > - strncpy(image_get_name(hdr), name, IH_NMLEN); > + char *hdr_name = image_get_name(hdr); > + > + strncpy(hdr_name, name, IH_NMLEN - 1); > + hdr_name[IH_NMLEN - 1] = '\0'; > } Why don't you use strlcpy() instead? This covers exactly the situation we have here. Best regards, Wolfgang Denk -- DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr. 5, 82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd@denx.de panic: can't find /