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 4FC75C32774 for ; Tue, 23 Aug 2022 05:59:28 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id A6C3683E03; Tue, 23 Aug 2022 07:59:25 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=jms.id.au Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="kSBongEP"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9584D83CF7; Tue, 23 Aug 2022 07:59:23 +0200 (CEST) Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) (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 F2E6C84355 for ; Tue, 23 Aug 2022 07:59:20 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=jms.id.au Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=joel.stan@gmail.com Received: by mail-pl1-x632.google.com with SMTP id 20so11896975plo.10 for ; Mon, 22 Aug 2022 22:59:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:sender:from:to:cc; bh=+frkMqqOCiaecadLuEYHL50abTObTwQk81W3RC2IhRA=; b=kSBongEPanIfWrUr29UWZ3i7Cx7GHO/OJig1ryB1Fc0O4BOwivOjyk7o2rpzgaA6dt TgOuSxwJxyY5R3cGAsqoB5u6WhyW/t0rx6zXCe1KssX6bMCuFJUzuOhd1RhV/QTevRZs P6OHIzc3n0Epbx800qs6Kz1lcYWLvgl4v8WJG40s1eZIzC/J34XaGiEODZCZqcHD4xCb yOBwprr+2l9o20J+xcv6pEDgyPVhyW8qRgEy/9E4jiI8wUzRB8yPN1HmD5pj9+ssMS1F rzDOw9BuuFFtVd1GB1ta2B2V9NdepxeQWB8mIR0Oubo0o+NPenfoThnjXQ2IHRKDUDfu mNzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:sender:x-gm-message-state:from:to:cc; bh=+frkMqqOCiaecadLuEYHL50abTObTwQk81W3RC2IhRA=; b=FKT2q2ITXiDkh2AFG/BUrUPljnXaVTzV/OF/1hEruScqBoewU8i5l5nYQmNoJkmHaf tbIKM29vboLhD/xaeKXEBsaxnTAzpLhKFfehJdjdD9FSMN4wN0x80zNY/cnUvMlIp7c3 0jqm0JN8hMyl2Y0GiwELdMAm0pgHO6OovbJbB1l7arZemDeZlsOEIsRvVtpGxDwGDFTR mVF3mEUjSVkXCl8Q/D1VG8zwDUWU2aiKIyc4MRkD+0howVufpOh1ZX8pKpxbSNJ/R5GF IrWs8w4OyWM0+EoEZL7jzR7eJj28SqLzuOAwSdSzziNSSNoBjWUzk1HQnch4aAUnhc0I 7VHg== X-Gm-Message-State: ACgBeo0qt5QL4+/Vhafj6wX++7UUwn0YuMvJplHcdR1Mwq1/2X9jotHd y6an/cijrty/VrSL2wCUuQ4= X-Google-Smtp-Source: AA6agR6o/V5i3BuwitoFZX4cjXAB2WUizpWxDXcdLLJLwz1fvBHBt0is2h5cr1UkrGcS15YHoF1nrw== X-Received: by 2002:a17:90b:4f91:b0:1cd:3a73:3a5d with SMTP id qe17-20020a17090b4f9100b001cd3a733a5dmr1798535pjb.98.1661234358897; Mon, 22 Aug 2022 22:59:18 -0700 (PDT) Received: from localhost.localdomain (2403-5808-8af8--7926-51ea-3ff2-71dd.ip6.aussiebb.net. [2403:5808:8af8:0:7926:51ea:3ff2:71dd]) by smtp.gmail.com with ESMTPSA id y2-20020a62ce02000000b0052ea306a1e8sm9706468pfg.210.2022.08.22.22.59.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Aug 2022 22:59:18 -0700 (PDT) From: Joel Stanley To: Simon Glass Cc: u-boot@lists.denx.de Subject: [PATCH] image: Ensure image header name is null terminated Date: Tue, 23 Aug 2022 15:59:07 +1000 Message-Id: <20220823055907.416060-1-joel@jms.id.au> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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 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'; } int image_check_hcrc(const image_header_t *hdr); -- 2.35.1