From patchwork Thu Feb 13 15:05:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Thompson X-Patchwork-Id: 183379 Delivered-To: patches@linaro.org Received: by 2002:a92:1f12:0:0:0:0:0 with SMTP id i18csp634351ile; Thu, 13 Feb 2020 07:06:09 -0800 (PST) X-Received: by 2002:adf:fa86:: with SMTP id h6mr21817444wrr.418.1581606369057; Thu, 13 Feb 2020 07:06:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581606369; cv=none; d=google.com; s=arc-20160816; b=VMRHvPA1jwsU3UG+Jz5rurpznWB1bKDF6o7RLSMOVX21juHft0ATeDLGyKY7Ze4sQh NhA18oVRnGGpfq3YJX5qbOtzQpYwhVuqrmWvuKE0xw7tRePV5WZL1o28GL2pVUPzA3Gj JlwRfSPDeMLP3HzCqRNdLfU2hImZjly5Su5xmvBDId6WD4CNXvWNb1UW/9GvJgk6bprb lM7Jy04iO2037sL1hAGcQb7s8vbC/+G7mL480NjfSX3j10aUiyFOXr4tFK0FiiOThxr2 MBzcczVtegPbiFMmIfVQQuoB7NLwc24aRtrCzcjohq//5UDqwPnbk9z3ddW2kMeP4uhM RtLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:dkim-signature; bh=ljdX2toI1glkUCHAbgskAX4FstAA5OW+os6LVO25kAo=; b=hGkFwtiQeJ7MR3oIffY35QQ7vsRyfrNONMhT+lVNUULssc4PFW5tw0NDIebzTy7PC6 OSN4vLVuXk4Qif6tLgWvVBjdWif0xzmW7Mk/+taQNloiHhu7u+TR9UWw5G/djxTGUYVC JyFoRmyzZGsJlD2WF3H4g4/u/xEwp3+IK6/GwNI1Y4CmwBBDTBYLnhJO3jIwlDq7cSwV E4Hh4xJ1TZj4vX8k+7IdvMUzPbFZ9gMPCxJh1RCNJzYGWnG7IPM0nPOClGhQlHget6Re 8PYoVx3YozVtIVBfmUbffEaagaf88L9JHVQYAdHn/ho2zg5X/H8UPuwXrbiXk7wcyYVp kd+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xIThK0ku; spf=pass (google.com: domain of daniel.thompson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=daniel.thompson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id l17sor1468478wrw.32.2020.02.13.07.06.08 for (Google Transport Security); Thu, 13 Feb 2020 07:06:09 -0800 (PST) Received-SPF: pass (google.com: domain of daniel.thompson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xIThK0ku; spf=pass (google.com: domain of daniel.thompson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=daniel.thompson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=gpQU1HsnP51kJIj2DGWmfnjhu79LmO6N8Yl0SVPaDhe3C5jRVWpOWZY28jR+AM/tPa cH6hSpmknl+oyCuVijM4dXrEvGxu8XnaPkYlgiYEhgX7kn0lxDfEHCD+W5T6oDgScXLV YBNjpHQIdvjsyBnnnrvVO2soFSdNi5Plr8t+yGQ88LEi2UkKVVhTSGUdFCCpKanqDzrT t5yT54FS3545nc9iSYI8D8v/803XPH7tHYyU+kgBufVeF6kLTVuMb8jH4R2VMkDkZ5L8 UaOxR1DLGLYuQUlonU9Rx48fWGCWFw9jx0ez+CpFv4JNCeqACv2VmsSZeCWiZqhogg7O g0BA== X-Gm-Message-State: APjAAAU4dmW8//YQbvs+G4W8cUnEEXs8dRA8tY3MShEI/aB5MBGFnoNM 2j5R/K8xfkrKeDAajKe45cEGY1An X-Google-Smtp-Source: APXvYqxlbxmp9sQUBchL7xCXNDeCu6p5vWmmPGNO5ZyJ0If8Armv9gfRQLVqlWf476Igqo9LNYFNbA== X-Received: by 2002:adf:9c8c:: with SMTP id d12mr21750911wre.404.1581606368580; Thu, 13 Feb 2020 07:06:08 -0800 (PST) Return-Path: 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 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(-) base-commit: bb6d3fb354c5ee8d6bde2d576eb7220ea09862b9 -- 2.23.0 Reviewed-by: Douglas Anderson 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); }