linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Laight <David.Laight@ACULAB.COM>
To: 'Josh Poimboeuf' <jpoimboe@redhat.com>,
	Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: kbuild test robot <lkp@intel.com>,
	Michal Januszewski <spock@gentoo.org>,
	Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>,
	"kbuild-all@01.org" <kbuild-all@01.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: RE: include/linux/string.h:246:9: warning: '__builtin_strncpy' output truncated before terminating nul copying 4 bytes from a string of the same length
Date: Wed, 6 Jun 2018 15:34:43 +0000	[thread overview]
Message-ID: <968a69b2aeb34ffb9d2fb01731ac9247@AcuMS.aculab.com> (raw)
In-Reply-To: <20180605153003.epf37ivdbewv256i@treble>

From: Josh Poimboeuf
> Sent: 05 June 2018 16:30
...
> What about just changing it to a memcpy?  Seems like that would be
> cleaner anyway, since the whole point of strncpy is to add the
> terminating NULL, which isn't need here.

Not really, the point of strncpy is to copy strings that might
not be '\0' terminated and to zero fill the target buffer.

Unfortunately strncpy() has often been used with the assumption
that it always terminates the target string - which isn't true.

Unfortunately you can't always replace strncpy with strlcpy or
snprintf because both those require the source string be '\0'
terminated - which isn't a requirement for strncpy.

This warning on __builtin_strncpy() seems ott to me.
The only fix is to audit the code and replace at least some of
the strncpy() with really_strncpy().

	David


      parent reply	other threads:[~2018-06-06 15:33 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-29  1:35 include/linux/string.h:246:9: warning: '__builtin_strncpy' output truncated before terminating nul copying 4 bytes from a string of the same length kbuild test robot
2018-06-05 15:19 ` Andy Shevchenko
2018-06-05 15:30   ` Josh Poimboeuf
2018-06-05 15:31     ` Andy Shevchenko
2018-06-06 15:34     ` David Laight [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=968a69b2aeb34ffb9d2fb01731ac9247@AcuMS.aculab.com \
    --to=david.laight@aculab.com \
    --cc=acme@redhat.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=b.zolnierkie@samsung.com \
    --cc=jpoimboe@redhat.com \
    --cc=kbuild-all@01.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lkp@intel.com \
    --cc=spock@gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).