Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp647816ybv; Thu, 13 Feb 2020 07:09:08 -0800 (PST) X-Google-Smtp-Source: APXvYqwrAvtHGpRKobLmgMz85eRm4rsOQTuDWLhnKyc08NzVS70qkH61CZbkWeYR26qAJyXY/sCb X-Received: by 2002:a9d:6c06:: with SMTP id f6mr14094282otq.318.1581606547951; Thu, 13 Feb 2020 07:09:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581606547; cv=none; d=google.com; s=arc-20160816; b=ZY59lk0/Ylw1WqywForM3lrCfPAFZupzfEmHe+nne9jRmv7wATFyFuWHVaOTtKo9G6 tasukwiIkwWFMtjCvpMUchTVjlQaWo5wfad44oVen8xG/RWwpEMax93EGyEx15g2zgYD sxY5LsUJYNfYbMzjgj+tXB29uuqTBVtVvtfWjnwtLMkFggNo3xUTCVWVhJe3vdTMA1W7 quXj2Qs03DvTq0fpdo5WpU4s3C9Vq1VhMDbgqFESIkeh5Dw5nFscRO4Npkw13nJXF/HW OrduFqVTbK+ERd54ElanuI9JjoMyw9VftZzavppVGDKNX0BMWnVYvOSbR/cdaQG6qB7I QB7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=ljdX2toI1glkUCHAbgskAX4FstAA5OW+os6LVO25kAo=; b=lefr0p+XxW/rjNuqzU95IGXEMKXFxbmgxu0p0wLeXW7lw/DDEXgpF13speJ8QSw9oS l5Ujg9vEe1zvQlRTxwHk7Yj0TY7JTYgO0xFxEaJecu+VFgw9M65AbhkiznX/jiVcWCiO whFjUrpPQHeE/GOaNwxYO1ruY2dTvX4ZqdP7meaIiXHnLJFvXy7uxACNtzv33gnloElJ 2eQCJe/d465ns8pnYUnhjLiayXF4tNmCoWwIM3yCGcWHQy2NDgNXARMHOLPs+V55tRgi 3nhOyi/mI6qDO8MIGIv6pdK/ZrHn96LiD9OuO/sUzNJcmoFl1AeftHeYdcxOvB21l5UM UokA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xIThK0ku; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u16si1307709otq.92.2020.02.13.07.08.44; Thu, 13 Feb 2020 07:09:07 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xIThK0ku; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727782AbgBMPGK (ORCPT + 99 others); Thu, 13 Feb 2020 10:06:10 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:36704 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727595AbgBMPGK (ORCPT ); Thu, 13 Feb 2020 10:06:10 -0500 Received: by mail-wr1-f68.google.com with SMTP id z3so7118978wru.3 for ; Thu, 13 Feb 2020 07:06:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ljdX2toI1glkUCHAbgskAX4FstAA5OW+os6LVO25kAo=; b=xIThK0kuWRRu5Y/bTutWxrzpIW+BSCNi0v8BmUX+XuR5+Ft7S3ZZCcvzk6P/neUQ70 VjqW+5MupHA0wCCA4rVskUR1a/9n79Jd5MtHw1ofG5qF+24seGbyfRkAx6SNTQdgHSkc cJLcT3fqoJhU2hvbFuOUfReP6NWnGD+vhSk5d4wtsamH3/+hQspt4IlCNTwleMs+KKyq ImjrTLR/wyrXE+P8ar9XkOjLTVUEJelIi8xWuhyWFx9hIWXwCM28ndOv7DWlJSVY0VqG /giR5bIHISKcVY0xbBMxojHvxSKEIbm5K30TRELmiDY9yaFwAE8VKpeU/NUxyDWQVWAc B8FQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ljdX2toI1glkUCHAbgskAX4FstAA5OW+os6LVO25kAo=; b=lwtEPJT4Yit58Fqc69saKzw42jwmO1RtcpPjk6WqkWV8y9OsczC6cZKXy3ZIF6hqGW RAFP+d2d8oTN80btGpsMdC9zG1VjKRD6we2ADrw7F76IwxVrdKOxSFsblIibgVdT2Pj1 91CekcwGm3IJELscKUs7HS9lP2ZzKxdK7k4l1xlnn4y4mqyErPTG2EaKuYYMm6esX5iD u+/RI/8he/lmwQ6UVsdz1zfw0nUue2w/zCTvE8WPyAUYq1gyra6aGNDGcpOwQLSkOiwG +JKIT9N7wUqPBVikqhPfQ7/zm7IxgO7QaxnC7Zb6t5YSNFCc8l0HnUWAx4zIe5yvMZE9 OtTg== X-Gm-Message-State: APjAAAXjt3D1H1o7QF6kshXMktEMPhI6eRwG4+aW3zBkYfmb3mefr+9n dlSHYw6OAGvAV4K8uLxeDbB4sw== X-Received: by 2002:adf:9c8c:: with SMTP id d12mr21750911wre.404.1581606368580; Thu, 13 Feb 2020 07:06:08 -0800 (PST) Received: from wychelm.lan (cpc141214-aztw34-2-0-cust773.18-1.cable.virginm.net. [86.9.19.6]) by smtp.gmail.com with ESMTPSA id m9sm3162376wrx.55.2020.02.13.07.06.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Feb 2020 07:06:08 -0800 (PST) From: Daniel Thompson To: Jason Wessel , Daniel Thompson , Douglas Anderson Cc: kgdb-bugreport@lists.sourceforge.net, linux-kernel@vger.kernel.org, patches@linaro.org Subject: [PATCH] kdb: Eliminate strncpy() warnings by replacing with strscpy() Date: Thu, 13 Feb 2020 15:05:53 +0000 Message-Id: <20200213150553.313596-1-daniel.thompson@linaro.org> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently the code to manage the kdb history buffer uses strncpy() to copy strings to/and from the history and exhibits the classic "but nobody ever told me that strncpy() doesn't always terminate strings" bug. Modern gcc compilers recognise this bug and issue a warning. In reality these calls will only abridge the copied string if kdb_read() has *already* overflowed the command buffer. Thus the use of counted copies here is only used to reduce the secondary effects of a bug elsewhere in the code. Therefore transitioning these calls into strscpy() (without checking the return code) is appropriate. Signed-off-by: Daniel Thompson --- kernel/debug/kdb/kdb_main.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c index ba12e9f4661e..a4641be4123c 100644 --- a/kernel/debug/kdb/kdb_main.c +++ b/kernel/debug/kdb/kdb_main.c @@ -1102,12 +1102,12 @@ static int handle_ctrl_cmd(char *cmd) case CTRL_P: if (cmdptr != cmd_tail) cmdptr = (cmdptr-1) % KDB_CMD_HISTORY_COUNT; - strncpy(cmd_cur, cmd_hist[cmdptr], CMD_BUFLEN); + strscpy(cmd_cur, cmd_hist[cmdptr], CMD_BUFLEN); return 1; case CTRL_N: if (cmdptr != cmd_head) cmdptr = (cmdptr+1) % KDB_CMD_HISTORY_COUNT; - strncpy(cmd_cur, cmd_hist[cmdptr], CMD_BUFLEN); + strscpy(cmd_cur, cmd_hist[cmdptr], CMD_BUFLEN); return 1; } return 0; @@ -1314,7 +1314,7 @@ static int kdb_local(kdb_reason_t reason, int error, struct pt_regs *regs, if (*cmdbuf != '\n') { if (*cmdbuf < 32) { if (cmdptr == cmd_head) { - strncpy(cmd_hist[cmd_head], cmd_cur, + strscpy(cmd_hist[cmd_head], cmd_cur, CMD_BUFLEN); *(cmd_hist[cmd_head] + strlen(cmd_hist[cmd_head])-1) = '\0'; @@ -1324,7 +1324,7 @@ static int kdb_local(kdb_reason_t reason, int error, struct pt_regs *regs, cmdbuf = cmd_cur; goto do_full_getstr; } else { - strncpy(cmd_hist[cmd_head], cmd_cur, + strscpy(cmd_hist[cmd_head], cmd_cur, CMD_BUFLEN); } base-commit: bb6d3fb354c5ee8d6bde2d576eb7220ea09862b9 -- 2.23.0