From: walter harms <wharms@bfs.de>
To: kernel-janitors@vger.kernel.org
Subject: Re: [PATCH v2] arch: s390: appldata: using strncpy() and strnlen() instead of sprintf()
Date: Mon, 27 May 2013 16:53:43 +0000 [thread overview]
Message-ID: <51A38F97.4050804@bfs.de> (raw)
In-Reply-To: <51A32D81.2010105@asianux.com>
Am 27.05.2013 11:55, schrieb Chen Gang:
>
> 'buf[2]' is 2 bytes length, and sprintf() will append '\0' at the end
> of string "?\n", so original implementation is memory overflow.
>
> Need use strncpy() and strnlen() instead of sprintf().
>
>
> Signed-off-by: Chen Gang <gang.chen@asianux.com>
> ---
> arch/s390/appldata/appldata_base.c | 7 +++++--
> 1 files changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/arch/s390/appldata/appldata_base.c b/arch/s390/appldata/appldata_base.c
> index bae0f40..87a2209 100644
> --- a/arch/s390/appldata/appldata_base.c
> +++ b/arch/s390/appldata/appldata_base.c
> @@ -212,7 +212,9 @@ appldata_timer_handler(ctl_table *ctl, int write,
> return 0;
> }
> if (!write) {
> - len = sprintf(buf, appldata_timer_active ? "1\n" : "0\n");
> + strncpy(buf, appldata_timer_active ? "1\n" : "0\n",
> + ARRAY_SIZE(buf));
an other way would be
buf[]="0\n";
if (appldata_timer_active) buf[0]='1';
> + len = strnlen(buf, ARRAY_SIZE(buf));
can len ever change ?
re,
wh
> if (len > *lenp)
> len = *lenp;
> if (copy_to_user(buffer, buf, len))
> @@ -317,7 +319,8 @@ appldata_generic_handler(ctl_table *ctl, int write,
> return 0;
> }
> if (!write) {
> - len = sprintf(buf, ops->active ? "1\n" : "0\n");
> + strncpy(buf, ops->active ? "1\n" : "0\n", ARRAY_SIZE(buf));
> + len = strnlen(buf, ARRAY_SIZE(buf));
> if (len > *lenp)
> len = *lenp;
> if (copy_to_user(buffer, buf, len)) {
next prev parent reply other threads:[~2013-05-27 16:53 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <51A2CC07.5010100@asianux.com>
2013-05-27 8:34 ` [PATCH] arch: s390: appldata: using strncpy() instead of sprintf() Geert Uytterhoeven
2013-05-27 9:06 ` Chen Gang
2013-05-27 9:43 ` [PATCH] arch: s390: include: asm: typo issue for the redundency comma, found by cross compiling Chen Gang
2013-05-27 9:55 ` [PATCH v2] arch: s390: appldata: using strncpy() and strnlen() instead of sprintf() Chen Gang
2013-05-27 16:23 ` Gerald Schaefer
2013-05-28 4:58 ` Chen Gang
2013-05-27 16:53 ` walter harms [this message]
2013-05-28 5:12 ` Chen Gang
2013-05-28 10:22 ` David Howells
2013-05-28 11:03 ` Chen Gang
2013-05-28 12:17 ` David Howells
2013-05-28 16:03 ` Gerald Schaefer
2013-05-29 1:40 ` Chen Gang
2013-05-29 1:28 ` Chen Gang
2013-05-29 6:30 ` Dan Carpenter
2013-05-29 7:29 ` Chen Gang
2013-05-29 7:47 ` Chen Gang
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=51A38F97.4050804@bfs.de \
--to=wharms@bfs.de \
--cc=kernel-janitors@vger.kernel.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