From: Simon Horman <horms@verge.net.au>
To: "Dirk Müller" <dirk@dmllr.de>
Cc: kexec@lists.infradead.org
Subject: Re: [PATCH] Avoid buffer overflow on strncat usage
Date: Tue, 4 Feb 2014 17:30:53 +0900 [thread overview]
Message-ID: <20140204083053.GC30621@verge.net.au> (raw)
In-Reply-To: <CAL5wTH6B-QYbY9bcC+HuBJkk=rEEZhQsggi921YtbGNS4xUfxQ@mail.gmail.com>
On Mon, Feb 03, 2014 at 06:54:52PM +0100, Dirk Müller wrote:
> strncat() does not want the total size but the maximum length.
>
> Signed-off-by: Dirk Mueller <dmueller@suse.com>
> ---
> kexec/fs2dt.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/kexec/fs2dt.c b/kexec/fs2dt.c
> index 73c1fb9..65a8b66 100644
> --- a/kexec/fs2dt.c
> +++ b/kexec/fs2dt.c
> @@ -649,8 +649,8 @@ static void putnode(void)
> goto no_debug;
> }
> strncpy(filename, "/proc/device-tree/", MAXPATH);
> - strncat(filename, buff, MAXPATH);
> - strncat(filename, "/compatible", MAXPATH);
> + strncat(filename, buff, MAXPATH-strlen(filename)-1);
> + strncat(filename, "/compatible", MAXPATH-strlen(filename)-1);
I don't think you need the -1 as filename will have a trailing '\0'
which is not counted in the return value of strlen()
Also, could you please put a space on each side of each '-'?
Thanks
> fd = open(filename, O_RDONLY);
> if (fd == -1) {
> printf("Unable to find %s printing from
> purgatory is diabled\n",
> --
> 1.8.4.1
>
> _______________________________________________
> kexec mailing list
> kexec@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/kexec
>
_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec
next prev parent reply other threads:[~2014-02-04 8:31 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-03 17:54 [PATCH] Avoid buffer overflow on strncat usage Dirk Müller
2014-02-04 8:30 ` Simon Horman [this message]
2014-02-04 12:03 ` Dirk Müller
2014-02-04 12:37 ` Simon Horman
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=20140204083053.GC30621@verge.net.au \
--to=horms@verge.net.au \
--cc=dirk@dmllr.de \
--cc=kexec@lists.infradead.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