Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp1504004rda; Mon, 23 Oct 2023 14:58:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHsirWsScdQI5VNo67HAA1qbXy/4cpadYZw64jbp3NN/RwzqVH4vF1+Wl/VpwYT/wlPlHyu X-Received: by 2002:a05:6870:3d99:b0:1e9:de2c:3bd with SMTP id lm25-20020a0568703d9900b001e9de2c03bdmr14446113oab.30.1698098329887; Mon, 23 Oct 2023 14:58:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698098329; cv=none; d=google.com; s=arc-20160816; b=PCuByv8H8sWQySBWiGJ+KWJCdt4oq7iIh4IunPf47lhsz0HepumC57ZUNhozXYfHTo Hcz+cmO/0D8UnyItmCgJmgTrpgeR/WH62d94JGF6pD1iplhkiuEBg3sSHGn1KufHW3pR rwgJbxnz45XqaBCwabqIJFlXE6cLoDjBHkbcPbgS5rxISBQveTdOKrEz/Hghx3e4M9ZC I5suwjH/KUzK26DY0zjX4lxry4IfLPOX4veOMytKcyCzEPG5Vq/Yc+Shbx9Zl0yhVcic fUXRbp47wXFfZhES7bukRdmOr3mIGtUNRgreqd6zDwjO9oM7C/Z99CMJ/+mOXO551dOn N2dQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:mime-version:date :dkim-signature; bh=lplfIxKbwXfc4j0px8yADDJAew/JRR45TLtG3ONcRNY=; fh=1cRhf3BjmHQ62/JRsAsvieH3KPX3EpWHfpOP3L/umno=; b=jAStS+LaaHn8eonhaR2nKNgrrpkyVPmyOB1yN4dOdhIF5+6Wr08s6aby3niEoJdwHR twLFuIJ7zYdwgTDnZRtKEFCZHRivkAz8lOV4jvefJqA0HIspIjPNczbFiW2GJ4aoDmAR /UDsVG2VtvAmSq88BgA+nGtTcT3NV6Py9kfY9Q5RJ+LIVyaF8j6kK2wK/BhA7bcpGq2q HtZXbhNXCFOV/GEwnEfXQ25X+ntZ2x1DHjwwp/mrxoTOB8Q2XUZ05CWjXDH25zpxRsnr ZaLlnaXl7z8wNbBgpfJJHLhp2adJNosdzGf46ygTvmcvEF8GJ54Xm+X5hqPshhSCXmu3 /v2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=zsEk+K9L; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id p19-20020a639513000000b00573fe48c908si7019845pgd.128.2023.10.23.14.58.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 14:58:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=zsEk+K9L; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id BE21A80AF3D5; Mon, 23 Oct 2023 14:58:46 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233725AbjJWV6j (ORCPT + 99 others); Mon, 23 Oct 2023 17:58:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48970 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233719AbjJWV6i (ORCPT ); Mon, 23 Oct 2023 17:58:38 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC88310C8 for ; Mon, 23 Oct 2023 14:58:33 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5a8ead739c3so51478137b3.3 for ; Mon, 23 Oct 2023 14:58:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698098313; x=1698703113; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=lplfIxKbwXfc4j0px8yADDJAew/JRR45TLtG3ONcRNY=; b=zsEk+K9LK51vLhoScELCPAHscZxaV/QIVvVRl3uUREKyCWbWMxLfi7UEHFaq/TNqot kc2InySeSLAmxbzFfXoD4VaTXEHz3lxVQVWhXiRs0ZJENU1DosZURBGKrivvNrWMYfzf QjUFtbbpe4gx7x7H3TSKT8+slg91pTvi36yZ6w7MQkD2VFqk2uBbIZxCTDAWpTBb/dt3 1lV/m5OLgvSqsnAz1v5W5i3BgjOCyG1AslO2NpP6VG7hXKdUFm3HqWCpKg2f1+WEAGBe sz9mIb/w9qstcklDlkbRKHINhwg5oczgf740n02rE6hVWXAbsB2lpngxoo5XQiIhVuvu lo5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698098313; x=1698703113; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=lplfIxKbwXfc4j0px8yADDJAew/JRR45TLtG3ONcRNY=; b=pP0Y+vcx0YjKVIkrw7JTcV98ydiWo/LsiH+OUgKMmVgWHhFHSTpcOSt1WkYJVWJ74w LJkxXguhJZ3BvuKnMT1YjWudsPx96Jj2IYZ/CN6VdkuKm9Qd1qMGFe7nNRFcS7etZZfr 9k6HWH+poPIphxPt0YTYsA0pK+cAml9KkX7xox8KD3mFBtni53M7CeEsBqT5vJsjRtXK gkSZC9MXAG7oM67jCBYW1qFzYClFDbe+2a7MaHQ7qSZ1YiIHLhXWTi7y05VklruwIHx/ UPdZaETqmEA+M+cfh8Mw1OzroySCA0ihl8N7sXEcptk8dGQjsFg7P5bQ4FvD5RUdstA4 80ng== X-Gm-Message-State: AOJu0YxErrGCKwOdyKBGRO4I333qlBuzRjNB75zdGMMXo5z1xsJGyiny 1eM8FOTHdHFbKMuYs5XW200UDLo8hHWl1RkDNw== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a0d:dd02:0:b0:579:f832:74b with SMTP id g2-20020a0ddd02000000b00579f832074bmr247586ywe.10.1698098313044; Mon, 23 Oct 2023 14:58:33 -0700 (PDT) Date: Mon, 23 Oct 2023 21:58:32 +0000 Mime-Version: 1.0 X-B4-Tracking: v=1; b=H4sIAIfsNmUC/x2NQQqDQAwAvyI5N9BVZKlfkVK62awGZJWkiEX8e 0MPc5jLzAnGKmwwNCco72KyVpdwa4Dmd50YJbtDe2+74KB9tNL2xayysxoamSAvBy6SuBA6r7p mxhkppRL7LjxiiuDBTbnI8Z+Nz+v6AXD8Le58AAAA X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1698098312; l=2186; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=hqkcQUr/WEsQ9djykeodKpHEXayH5DyAwwnmmf9qdpA=; b=SagiCpSLtykvm17v/plCsQA3GNG2yh2JnJbu/1dbbizqlrX1TDrPn0NwucSKvOETDBvbBkuR8 zoejEP8XQ5HATTtFw7HIQW0WisLKWtvKaqJs6GR2DhqV+cm7zv/GNb9 X-Mailer: b4 0.12.3 Message-ID: <20231023-strncpy-drivers-scsi-elx-libefc-efc_node-h-v1-1-8b66878b6796@google.com> Subject: [PATCH] scsi: elx: libefc: replace deprecated strncpy with strscpy From: Justin Stitt To: James Smart , Ram Vegesna , "James E.J. Bottomley" , "Martin K. Petersen" Cc: linux-scsi@vger.kernel.org, target-devel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, Justin Stitt Content-Type: text/plain; charset="utf-8" X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Mon, 23 Oct 2023 14:58:47 -0700 (PDT) strncpy() is deprecated for use on NUL-terminated destination strings [1] and as such we should prefer more robust and less ambiguous string interfaces. A suitable replacement is `strscpy` [2] due to the fact that it guarantees NUL-termination on the destination buffer without unnecessarily NUL-padding. There seems to not be any uses of `current_state_name` other than in these assignments. Judging from context surrounding these assignments, especially considering the string literal "invalid" being assigned, we want both current_state_name and prev_state_name to be NUL-terminated strings. Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings [1] Link: https://manpages.debian.org/testing/linux-manual-4.8/strscpy.9.en.html [2] Link: https://github.com/KSPP/linux/issues/90 Cc: linux-hardening@vger.kernel.org Signed-off-by: Justin Stitt --- Note: build-tested only. Found with: $ rg "strncpy\(" --- drivers/scsi/elx/libefc/efc_node.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/scsi/elx/libefc/efc_node.h b/drivers/scsi/elx/libefc/efc_node.h index e9c600ac45d5..3a16703d0f97 100644 --- a/drivers/scsi/elx/libefc/efc_node.h +++ b/drivers/scsi/elx/libefc/efc_node.h @@ -26,12 +26,12 @@ efc_node_evt_set(struct efc_sm_ctx *ctx, enum efc_sm_event evt, struct efc_node *node = ctx->app; if (evt == EFC_EVT_ENTER) { - strncpy(node->current_state_name, handler, + strscpy(node->current_state_name, handler, sizeof(node->current_state_name)); } else if (evt == EFC_EVT_EXIT) { - strncpy(node->prev_state_name, node->current_state_name, + strscpy(node->prev_state_name, node->current_state_name, sizeof(node->prev_state_name)); - strncpy(node->current_state_name, "invalid", + strscpy(node->current_state_name, "invalid", sizeof(node->current_state_name)); } node->prev_evt = node->current_evt; --- base-commit: 9c5d00cb7b6bbc5a7965d9ab7d223b5402d1f02c change-id: 20231023-strncpy-drivers-scsi-elx-libefc-efc_node-h-cbbf753197b7 Best regards, -- Justin Stitt