Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp3113514imm; Tue, 29 May 2018 00:58:35 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLXZkJhRCbGjen2m6rxLyny1oaFYFaKmSPjqiCDlmhHZCboErUxRDJGLjyL0ggULZiA/15k X-Received: by 2002:aa7:8051:: with SMTP id y17-v6mr7589740pfm.148.1527580715206; Tue, 29 May 2018 00:58:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527580715; cv=none; d=google.com; s=arc-20160816; b=Q/hymrCvDBUG37BlfcxpX/yaGdtHD8+oryF9fhwlEggpcaTzc1+fpQWn7ZZ1KvA8Tx 2zlDOwjJp5LDxoiM0jy/JMv2+l4ag9oeFsAHJvyBtwy3MJAz8ahiScd96WcK06fsr9D2 GRRHcmObv6BbxMb1i9FR7t522CuecL/+KHfyadq4hsCHmOghDUy2DVk/4nU/CQlqOMIo HK3sbA7d32WQcNHkCU5ESpkV9HrsiYjcpu1CY/VPB5ixcjVtMgNbUmNuYQ64Gyqj3wSD FE/fdBwWroZGWiroV6Yvcr7OF9xGe22RyDik2+pJ32wEyWqOl76pBESSeW92z5clzL+b dRDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=jO3Mngaxonl+CAEcEsq2xMKTEHkScl3ipeB90lEWSJ0=; b=uP/4CW0meU7r7kzvD/Qs/tAATCP56NzuJ8H4eFoDcwCh0SuXwKFmqejNGSNwUSyGcu +QCTg9WmnyhTYBmtt85lBk36NAjEU2kSzsruL+QpYqs3dqRRbK9JuC+ye1uicHanib68 Ahv8FU1xj4zXnsobIZhAIxKkF0Ze2dNc2E1aX9MQn04JOV+r0GnjDFGLNq8HsoYY5WcR 9ZCC0vDTyFIO9k1JAsSSOfCXXjkE7vgZW/rRsES5USaSo/1pYvvectHU5kY4zhN9WBu9 Zh0wX0ZQWm6Q6EPFTpZu0EKvqHsIz/aoJZeIeZ4aVqQ7nVmM0C5Z8cahFjsr+POxrp5F fU7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=lt88CPi0; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j11-v6si31190280plt.325.2018.05.29.00.58.20; Tue, 29 May 2018 00:58:35 -0700 (PDT) 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=fail header.i=@gmail.com header.s=20161025 header.b=lt88CPi0; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755076AbeE2H5s (ORCPT + 99 others); Tue, 29 May 2018 03:57:48 -0400 Received: from mail-io0-f193.google.com ([209.85.223.193]:40035 "EHLO mail-io0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754796AbeE2H5o (ORCPT ); Tue, 29 May 2018 03:57:44 -0400 Received: by mail-io0-f193.google.com with SMTP id g14-v6so16564686ioc.7 for ; Tue, 29 May 2018 00:57:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=jO3Mngaxonl+CAEcEsq2xMKTEHkScl3ipeB90lEWSJ0=; b=lt88CPi0Uy+ILWD5EA1fZzvUrdiEi/jop8jzZ+EawpzCaeTzjYIQA+0UEHnirXJnIF fiH3Kfac96EoN/H+nCJjlPF6c22dBgvrdKjWpM8S1e7dUSCAWUBoTUji4Q0RgEujaMZM ALdzzQmdB0oy7UWWzGAlPff9HnSxaElZksMIRZrQ9T4Dp3Rv/YH1uSue150+RcOzPh4t k9aAxmauR1bI/EgnmZ7g/S1mTrocCYMxJTo5lf0ZUTs/dNP+kwwzfB2x/iTJfZ3x7GE7 DhMOmh/TMUsvTQ7koD8gVUBAzH4ViQLnB3PitDHgVKYLXUA9NMPzIX2OypATCUzrkqra /UrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=jO3Mngaxonl+CAEcEsq2xMKTEHkScl3ipeB90lEWSJ0=; b=PzZniTqgENfVcuLd/VY4/azjvRaxfqrKPGHhDsUbP/RXh4lqvjqYRdFDAOEL5NnFbp aEr9K5Gf9IbSS3PUC6mVctXibYY9Kc6tRkS7pB9BQ4VxT2/CaUTTTT4t4wr/scexvD+5 kBwhTNXDJjVc5GOIeg6oPHHIzdxTnoLRiaweLrqO/XAk9ky6tQSj/5+YBhjSj+VaunJb eW//1OcmE2PoglN7oqTx/dQaJ0Fw/8vCGeZNTi3p0+kNA9ow16+fGYUJoG5JaG06BGxC xYZz1oYkxXIYDON8n/bUpHMAAy4Ij5C6bXCybgDDmv3nuSLSSURk+MKgeehhBhDfJ66I bR5Q== X-Gm-Message-State: ALKqPwdt+vB/u6IOoP4R/Tpnt499U8q/S+ZJLqwekPt9uC36JEdEHHcM qhwMv3rae9LBOkN563Zgl6/4EjkdyrAZGXhVoPQ= X-Received: by 2002:a6b:5f14:: with SMTP id t20-v6mr14403908iob.0.1527580663996; Tue, 29 May 2018 00:57:43 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a4f:7517:0:0:0:0:0 with HTTP; Tue, 29 May 2018 00:57:43 -0700 (PDT) In-Reply-To: <1527573427-16569-1-git-send-email-nick.desaulniers@gmail.com> References: <1527573427-16569-1-git-send-email-nick.desaulniers@gmail.com> From: Arnd Bergmann Date: Tue, 29 May 2018 09:57:43 +0200 X-Google-Sender-Auth: aLb772PoYN2vCver3A2QEdc7JAw Message-ID: Subject: Re: [PATCH] kdb: prefer strlcpy to strncpy To: Nick Desaulniers Cc: Jason Wessel , Daniel Thompson , Randy Dunlap , Baolin Wang , "Eric W. Biederman" , kgdb-bugreport@lists.sourceforge.net, Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, May 29, 2018 at 7:57 AM, Nick Desaulniers wrote: > Fixes stringop-truncation and stringop-overflow warnings from gcc-8. That patch description should really explain whether gcc is right or not. What's the worst thing that could happen here? I would also recommend citing the exact warning you got. > diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c > index ed5d349..b5dfff1 100644 > --- a/kernel/debug/kdb/kdb_io.c > +++ b/kernel/debug/kdb/kdb_io.c > @@ -443,7 +443,7 @@ static char *kdb_read(char *buffer, size_t bufsize) > char *kdb_getstr(char *buffer, size_t bufsize, const char *prompt) > { > if (prompt && kdb_prompt_str != prompt) > - strncpy(kdb_prompt_str, prompt, CMD_BUFLEN); > + strlcpy(kdb_prompt_str, prompt, CMD_BUFLEN); > kdb_printf(kdb_prompt_str); > kdb_nextline = 1; /* Prompt and input resets line number */ > return kdb_read(buffer, bufsize); > diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c > index e405677..c30a0d8 100644 > --- a/kernel/debug/kdb/kdb_main.c > +++ b/kernel/debug/kdb/kdb_main.c > @@ -1103,12 +1103,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); > + strlcpy(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); > + strlcpy(cmd_cur, cmd_hist[cmdptr], CMD_BUFLEN); > return 1; > } > return 0; Those three all look good. > diff --git a/kernel/debug/kdb/kdb_support.c b/kernel/debug/kdb/kdb_support.c > index 990b3cc..dcfbf8f 100644 > --- a/kernel/debug/kdb/kdb_support.c > +++ b/kernel/debug/kdb/kdb_support.c > @@ -236,7 +236,7 @@ int kallsyms_symbol_next(char *prefix_name, int flag) > > while ((name = kdb_walk_kallsyms(&pos))) { > if (strncmp(name, prefix_name, prefix_len) == 0) { > - strncpy(prefix_name, name, strlen(name)+1); > + strlcpy(prefix_name, name, prefix_len); > return 1; > } I don't know what this does, but you are changing the behavior: the previous 'strlen(name)+1' argument was the size of the source string (which makes the strncpy() behave the same as a plain strcpy()), the new one means we only copy at most as many bytes as the previous length of the destination string. Is that intended? If yes, better explain it in the patch description. Arnd