Message ID | 20230114085053.72059-4-W_Armin@gmx.de |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp194529wrn; Sat, 14 Jan 2023 00:54:48 -0800 (PST) X-Google-Smtp-Source: AMrXdXvaWD3HSi8wCYfMrGXwtP2d3z60jc4dRefwsjOqMCFKOFkD1Th+ra9hwb0i8m+PfByKCjZq X-Received: by 2002:a17:902:bd09:b0:193:3716:78cf with SMTP id p9-20020a170902bd0900b00193371678cfmr18946754pls.65.1673686488617; Sat, 14 Jan 2023 00:54:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673686488; cv=none; d=google.com; s=arc-20160816; b=ES1RYEIodFa1biQQ8sZpYo9suNlxz++R1MOFGmM/Qd6C1x7zA8ECpCSMGhR3nNH2sM l8Mu0h68lhx1yZ5gcF7fvigubnTGG33Ad2CRaBRKyTgRbRTKdtYlp7hPCTIemd+ZQaTU uNdFRMPDMPoEPSEwuhKhIPbiiroMu+s6qc/P9csJ1gylxjXNxcjvucfW0Ya4dHrQwiuF GDbncU7JMT3UQXfpzRs+PIL/BEx8iqCeG0jTE4MC1Cb7MCH6oNznFImPBmpZ3rsUfTry 4VHH0zqOSsTpqjoP/RUOd5T6Aaa/J1FGMsMDKr1VoOutTRnYxwwrogUqZkgN/STeu/E7 Od7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:ui-outboundreport:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=1ZPzE/x/V9gRI1TogFetowagFJHEvIpVuCJrtMlLBXM=; b=IgbN4karaZqP6vZMgxDi5RRUf3K2o68qAfa1E9V245UspIaxCtJD4jnysTIU6LYo59 FW1Kbxvk4A62jM6M0Mdi2QKTXfkVAn7hWpFT2o5g8MjhrF8aE5N6PPapT4WqatyZf+zF hGthZQPMZE5GqH8qNkKird++ZPTwxaR7ihVWQqL/82KdDRoEtv5qhYol2dtBkSoPXtHb 3IWMuWypwmaaF2aTNp2gWOeNSYw/pvkvODX3YR8IA1Y5Rd9+vNzmT/LEfPQaAQ90/L0Y 2DeNEt4mgLU/fPJA8MV73n9PsZPyKhi8f3lgY2AWohHFvqOnjedNkGnHuMYwtKNGwTKR LnAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=pLvDoi+U; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmx.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n6-20020a634d46000000b004a32a462c19si22527664pgl.843.2023.01.14.00.54.36; Sat, 14 Jan 2023 00:54:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=pLvDoi+U; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmx.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229924AbjANIvg (ORCPT <rfc822;stefanalexe48@gmail.com> + 99 others); Sat, 14 Jan 2023 03:51:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229845AbjANIvH (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Sat, 14 Jan 2023 03:51:07 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.17.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 789AD5BA6; Sat, 14 Jan 2023 00:51:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1673686260; bh=ZRXDOHGn9yZu57/DPz1iMB9OlkHhVNY+RiI8eWQZy7Y=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=pLvDoi+UkLmHCYXsNyLYXYV53IObWoyJZafOBDM7/xWU9N2OdOERE+YWsiX9kr8QE 21sD5GeM4fvtVk6H6wp4rQWv/rJhUhl9RsSVar35f6QYxod2K3jsgDJCTLQo6hAQrp G/U58GQ/193DUoulcnHyjjsIcWiqInNdAKuZ2dG061FCKGu9//lzxnRkPCrGoC1/w6 L9Xy+Usbspusw79LnqU1iX8jN/Gu5IsepspIfmflkTIxSKr3d3lJ7d7H4OoO95znmd IYef5GOS8GZSdeJCd8FnWxUvZgxkYAlJmF91wH23ZjvhEvC60LPHv6baZVILvbnXSt taDtekps0eb7w== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from esprimo-mx.users.agdsn.de ([141.30.226.129]) by mail.gmx.net (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MTzb8-1p7AIr3qJG-00R4ov; Sat, 14 Jan 2023 09:51:00 +0100 From: Armin Wolf <W_Armin@gmx.de> To: rafael@kernel.org, lenb@kernel.org Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/4] ACPI: battery: Replace strncpy() with strscpy() Date: Sat, 14 Jan 2023 09:50:52 +0100 Message-Id: <20230114085053.72059-4-W_Armin@gmx.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230114085053.72059-1-W_Armin@gmx.de> References: <20230114085053.72059-1-W_Armin@gmx.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:nEZOIaBECnOJgOL0HPTpdVTEJLBlJu+3+2Qk7c4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acuHP5uu5YPMHs05GI+pL3uN9p9xvwlI4dxKo1Qbrl/2TMxRCkZ5 qIXa7C54LuMA/pBLa03jlKCAX2Lmfg4tZUKJkXaDOj/x+7lc55qELSZLy2QpqTa72kATGk8hH JEsOV7fJW2zrZoFZkISpQqkHTak= X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754987483756859249?= X-GMAIL-MSGID: =?utf-8?q?1754987483756859249?= |
Series | ACPI: battery: Fix various string handling issues | |
Commit Message
Armin Wolf
Jan. 14, 2023, 8:50 a.m. UTC
Currently, strncpy() and manual NUL-termination is used
when copying integers. Switch to strscpy() which takes care
of NUL-terminating the result.
Signed-off-by: Armin Wolf <W_Armin@gmx.de>
---
drivers/acpi/battery.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
--
2.30.2
Comments
On Sat, Jan 14, 2023 at 9:51 AM Armin Wolf <W_Armin@gmx.de> wrote: > > Currently, strncpy() and manual NUL-termination is used > when copying integers. Switch to strscpy() which takes care > of NUL-terminating the result. > > Signed-off-by: Armin Wolf <W_Armin@gmx.de> > --- > drivers/acpi/battery.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c > index 9f6daa9f2010..b39b84b8f3ae 100644 > --- a/drivers/acpi/battery.c > +++ b/drivers/acpi/battery.c > @@ -449,8 +449,7 @@ static int extract_package(struct acpi_battery *battery, > > break; > case ACPI_TYPE_INTEGER: > - strncpy(ptr, (u8 *)&element->integer.value, sizeof(u64)); > - ptr[sizeof(u64)] = 0; > + strscpy(ptr, (u8 *)&element->integer.value, sizeof(u64) + 1); > > break; > default: > -- This can be folded into the previous patch. Otherwise you're patching your own patch which isn't particularly clean.
diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c index 9f6daa9f2010..b39b84b8f3ae 100644 --- a/drivers/acpi/battery.c +++ b/drivers/acpi/battery.c @@ -449,8 +449,7 @@ static int extract_package(struct acpi_battery *battery, break; case ACPI_TYPE_INTEGER: - strncpy(ptr, (u8 *)&element->integer.value, sizeof(u64)); - ptr[sizeof(u64)] = 0; + strscpy(ptr, (u8 *)&element->integer.value, sizeof(u64) + 1); break; default: