Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp4300402rdb; Thu, 14 Sep 2023 19:38:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGdL27EK0Gg0/pHrogYRbUfCFMtoBVJGaXICUJSPoCuIlcQF3dou69cAU+F++kog6qiVzPz X-Received: by 2002:a05:6a20:7288:b0:135:7975:f55 with SMTP id o8-20020a056a20728800b0013579750f55mr556351pzk.47.1694745494777; Thu, 14 Sep 2023 19:38:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694745494; cv=none; d=google.com; s=arc-20160816; b=HWeORSYi9rDbZsRsEsxDA7AnUKDtooFytrhKFB5tDIy8oHKZ4LsX8sUwXauPh/NvwW HHVGLLTgGkDz+OFGcS/NjD/rQNGAhkXWV4ncZSgAo8hMEX6+8jwpaPqHiDvMYVVmaCs7 GGmWz2XWffjFi2wFJDOamF+Nj3TFij4J6tS73IH9GbDJgoVlObNMAfdj2XxKOwkhAEQN C5rciD4jv02X+TdHIGmcEonYVY/o2RIJPRmFd/B4oNFD/H9jk6ujRdQQBMgXZPkbGuKH 7nhbaJXp+rVNZQGU5sBtYBgjHYabLmtxDRLSawQTWoowE7M9LPhFJOla1oEjJgZDSaaC 6qnw== 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=L6wxH6wI0CxNppihK8yyqaPuo2ed2yk6gacxAzZ/YyQ=; fh=x95UiiO7x8ARzspXiDIsGxgY+UECTPNiK5BHfOj1rrU=; b=gLS40Ek0s+YQLMLThtG7/iZusaiq1YepOARC6KKUlhbwe5atqFacEUboq4F89i9WD/ Ry8qfXvAXbWIYxyr/GcSO4E0rYlTrB3o+fZahJcjQmsjzucPYAyh8Xsehn448ZVD1Qim KWe5QqibPGASx4YsRkioz8IRLpRINwpv9RZkhZRjGFLLfjrFBkLpULsF+z9Wv7S1jExc I3Cp5bvCvR1U7goDO2zsdsFY6jloEwwXBrDPekQiQm5BO1t1NNkhHiDbSKXEXG8JpWsM SAv1zy2VesU8R1nH6a8xMz48eZcbze+xnjiBoLyABS7+fyKPwoyuyIWXErygtspPRaYo H7Eg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=BM0YwBiw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id ca5-20020a17090af30500b0026f512692fdsi4685275pjb.91.2023.09.14.19.38.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 19:38:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=BM0YwBiw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (Postfix) with ESMTP id 6E7DD819875B; Thu, 14 Sep 2023 15:21:05 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229472AbjINWVC (ORCPT + 99 others); Thu, 14 Sep 2023 18:21:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229715AbjINWVB (ORCPT ); Thu, 14 Sep 2023 18:21:01 -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 E0D87269D for ; Thu, 14 Sep 2023 15:20:56 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-59224c40275so19940477b3.3 for ; Thu, 14 Sep 2023 15:20:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1694730056; x=1695334856; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=L6wxH6wI0CxNppihK8yyqaPuo2ed2yk6gacxAzZ/YyQ=; b=BM0YwBiwVFb8TzWvXVSas5oaWU302JRAzBkTRI+IJcHdIVkdRsJF3FFMuhyJ2HaWFu 18Ytjyc9eeDM8lYwHh1jc4D+h8FLxClwupHBsThQW0v81wsybwsoNl4RsebOtcNs56u8 tDN9p/BUNZJx5F7KgWEjMHUmaGHQV2xCFQIvl+3oqHn2bo/YqvmjZ77LqclnkTtwb/pO lzHCFI4KMm4QIF2yKkrvYr/+CPP7BJnzBiA1v+0fppHAFh1Pyv2XZWmOkxccDYAiSuKV Xjc56ChPLmrh7sM8kleY6eAR4hhoUR5oPqq+EfVXqHIyzzzg+PBvucRKGuTm6Hk5RpdZ ahfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694730056; x=1695334856; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=L6wxH6wI0CxNppihK8yyqaPuo2ed2yk6gacxAzZ/YyQ=; b=mj8JUAY5q6MVIO4adU4Li7cSuiLmyMt6bXAc6L0L+cO7DITuHPUuWi3/NIIR/gdyZR OULwzLpJKqy9yjmyqzgVjPs1F8iiiaCaHCRBBqANYnlX+rUGozxDSg5sasKAQ7zwuJ4z SA28EpeBYNBVZtWeKymo1AQZ8Lwjs3XlfxEydqsnXs/jLf/puZFVjYu9VTfdDjbup0RF qmdE0jIGiV+Hr7iR+93b57X499xsNYz6ENc5O5L9il407qvPUqDTVK6X4w7wNZ3zGV9I 7dT2MV6mv+lw2Fer674ZzNuLO56ONcnCCxM59QQXzYfqb6ToobDpuF8ti4Tjr+prZJTv YX1g== X-Gm-Message-State: AOJu0YzFgIz7NreN6OPHPrPx2DI9TQy03tPGkDlheOog+5VUlsidkOMg tFeYSWBCehiRU2J5P27F+HVtoPjzfHqKfe1Xbw== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a05:690c:710:b0:59b:f138:c83b with SMTP id bs16-20020a05690c071000b0059bf138c83bmr548ywb.3.1694730056164; Thu, 14 Sep 2023 15:20:56 -0700 (PDT) Date: Thu, 14 Sep 2023 22:20:55 +0000 Mime-Version: 1.0 X-B4-Tracking: v=1; b=H4sIAEaHA2UC/x2NMQrDMAwAvxI0RxC7JtB+pXQIlhyLgmOkEhJM/ l6T4YZb7hoYq7DBa2igvIvJVrq4cYCYl7IyCnUHP/nH9HQB7acl1hNJZWc1zEI3VTeSL5+GEWM KfnZh8Y4C9FJVTnLcl/fnuv40LAw+dQAAAA== X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1694730055; l=2074; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=+74GC7rHw1mTn7nixljv5X0qMRleq8S1K0Ou7Xb7zvw=; b=Kpg/iXSQK/dWh3bjDyW1nCyXP9t2hxjS3t8Kvy+Gk83wwymskJL9AwoLZSuYt0s95O1vww4sD edk9W7p0v+tDvqTc6FRuqWSc/e+ou1C/82uv+xmTsAPYQKfeT++S8J4 X-Mailer: b4 0.12.3 Message-ID: <20230914-strncpy-drivers-hid-hid-prodikeys-c-v1-1-10c00550f2c2@google.com> Subject: [PATCH] HID: prodikeys: refactor deprecated strncpy From: Justin Stitt To: Jiri Kosina , Benjamin Tissoires Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, Justin Stitt Content-Type: text/plain; charset="utf-8" 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 (pete.vger.email [0.0.0.0]); Thu, 14 Sep 2023 15:21:05 -0700 (PDT) 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 pete.vger.email `strncpy` is deprecated for use on NUL-terminated destination strings [1]. 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. 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: for some reason if NUL-padding is needed let's opt for `strscpy_pad()` --- drivers/hid/hid-prodikeys.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/hid/hid-prodikeys.c b/drivers/hid/hid-prodikeys.c index e4e9471d0f1e..c16d2ba6ea16 100644 --- a/drivers/hid/hid-prodikeys.c +++ b/drivers/hid/hid-prodikeys.c @@ -639,9 +639,9 @@ static int pcmidi_snd_initialise(struct pcmidi_snd *pm) goto fail; } - strncpy(card->driver, shortname, sizeof(card->driver)); - strncpy(card->shortname, shortname, sizeof(card->shortname)); - strncpy(card->longname, longname, sizeof(card->longname)); + strscpy(card->driver, shortname, sizeof(card->driver)); + strscpy(card->shortname, shortname, sizeof(card->shortname)); + strscpy(card->longname, longname, sizeof(card->longname)); /* Set up rawmidi */ err = snd_rawmidi_new(card, card->shortname, 0, @@ -652,7 +652,7 @@ static int pcmidi_snd_initialise(struct pcmidi_snd *pm) goto fail; } pm->rwmidi = rwmidi; - strncpy(rwmidi->name, card->shortname, sizeof(rwmidi->name)); + strscpy(rwmidi->name, card->shortname, sizeof(rwmidi->name)); rwmidi->info_flags = SNDRV_RAWMIDI_INFO_INPUT; rwmidi->private_data = pm; --- base-commit: 3669558bdf354cd352be955ef2764cde6a9bf5ec change-id: 20230914-strncpy-drivers-hid-hid-prodikeys-c-cf42614a21d4 Best regards, -- Justin Stitt