From: Andrew Morton <akpm@linux-foundation.org>
To: Kees Cook <keescook@chromium.org>
Cc: linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org,
linux-acpi@vger.kernel.org, linux-s390@vger.kernel.org,
devel@driverdev.osuosl.org,
user-mode-linux-devel@lists.sourceforge.net
Subject: Re: [PATCH] clean up scary strncpy(dst, src, strlen(src)) uses
Date: Wed, 5 Jun 2013 16:48:04 -0700 [thread overview]
Message-ID: <20130605164804.8071867d28c1f20cad8d7d2a@linux-foundation.org> (raw)
In-Reply-To: <20130531161807.GA9536@www.outflux.net>
On Fri, 31 May 2013 09:18:07 -0700 Kees Cook <keescook@chromium.org> wrote:
> Fix various weird constructions of strncpy(dst, src, strlen(src)). Length
> limits should be about the space available in the destination, not
> repurposed as a method to either always include or always exclude
> a trailing NULL byte. Either the NULL should always be copied
> (using strlcpy), or it should not be copied (using something like
> memcpy). Readable code should not depend on the weird behavior of strncpy
> when it hits the length limit. Better to avoid the anti-pattern entirely.
>
> ...
>
> --- a/Documentation/accounting/getdelays.c
> +++ b/Documentation/accounting/getdelays.c
> @@ -23,6 +23,7 @@
> #include <sys/socket.h>
> #include <sys/wait.h>
> #include <signal.h>
> +#include <bsd/string.h>
>
> #include <linux/genetlink.h>
> #include <linux/taskstats.h>
> @@ -299,7 +300,7 @@ int main(int argc, char *argv[])
> break;
> case 'C':
> containerset = 1;
> - strncpy(containerpath, optarg, strlen(optarg) + 1);
> + strlcpy(containerpath, optarg, sizeof(containerpath));
> break;
> case 'w':
> logfile = strdup(optarg);
Documentation/accounting/getdelays.c:26:24: fatal error: bsd/string.h: No such file or directory
I'll revert this part.
next prev parent reply other threads:[~2013-06-05 23:48 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-05-31 16:18 [PATCH] clean up scary strncpy(dst, src, strlen(src)) uses Kees Cook
2013-05-31 17:11 ` Greg KH
2013-06-01 19:54 ` Rafael J. Wysocki
2013-06-05 23:48 ` Andrew Morton [this message]
2013-06-06 0:11 ` Kees Cook
2013-06-06 7:08 ` Geert Uytterhoeven
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=20130605164804.8071867d28c1f20cad8d7d2a@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=devel@driverdev.osuosl.org \
--cc=keescook@chromium.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=user-mode-linux-devel@lists.sourceforge.net \
/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