From: Cyril Hrubis <chrubis@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v2] Fix buffer overflow in print_result() function
Date: Wed, 8 Nov 2017 15:55:47 +0100 [thread overview]
Message-ID: <20171108145547.GA8343@rei> (raw)
In-Reply-To: <20171107161042.12825-1-vkabatov@redhat.com>
Hi!
> diff --git a/lib/tst_test.c b/lib/tst_test.c
> index c8baf2a43..b43fb35f7 100644
> --- a/lib/tst_test.c
> +++ b/lib/tst_test.c
> @@ -227,13 +227,18 @@ static void print_result(const char *file, const int lineno, int ttype,
> size -= ret;
>
> ret = vsnprintf(str, size, fmt, va);
> - str += ret;
> - size -= ret;
> -
> - if (str_errno) {
> + str += MIN(ret, size - 2);
> + size -= MIN(ret, size - 2);
> + if (ret >= size - 2) {
We modify the size before this condition, so the warning was triggered
even for string that were half of the size of the buffer.
So I've changed the code to save the size-2 into a variable before we
modify it so that we can use it in the condition.
> + tst_res_(file, lineno, TWARN,
> + "Next message is too long and truncated:");
> + } else if (str_errno) {
> ret = snprintf(str, size, ": %s", str_errno);
> - str += ret;
> - size -= ret;
> + str += MIN(ret, size - 2);
> + size -= MIN(ret, size - 2);
> + if (ret >= size - 2)
> + tst_res_(file, lineno, TWARN,
> + "Next message is too long and truncated:");
And here as well.
I've also added a testcase and pushed, thanks.
--
Cyril Hrubis
chrubis@suse.cz
prev parent reply other threads:[~2017-11-08 14:55 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-07 16:10 [LTP] [PATCH v2] Fix buffer overflow in print_result() function vkabatov
2017-11-08 14:55 ` Cyril Hrubis [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=20171108145547.GA8343@rei \
--to=chrubis@suse.cz \
--cc=ltp@lists.linux.it \
/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