From: Cyril Hrubis <chrubis@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH] lib/tst_timer_test.c: fix unsigned int overflow on RHEL5.11GA
Date: Wed, 19 Jul 2017 14:15:57 +0200 [thread overview]
Message-ID: <20170719121557.GG1015@rei.lan> (raw)
In-Reply-To: <1500274437-26154-1-git-send-email-yangx.jy@cn.fujitsu.com>
Hi!
> On RHEL5.11GA, pselect01 gets signal SIGSEGV due to unsigned int
> overflow when all members of the samples array are less than usec
> in do_timer_test(). all tests which apply timer measurement library
> could trigger this issue on RHEL5.11GA regularly.
Ah righ, I've forgotten to add check for the array boundary there as
well.
> Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
> ---
> lib/tst_timer_test.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/lib/tst_timer_test.c b/lib/tst_timer_test.c
> index f30ad73..178e232 100644
> --- a/lib/tst_timer_test.c
> +++ b/lib/tst_timer_test.c
> @@ -295,9 +295,9 @@ void do_timer_test(long long usec, unsigned int nsamples)
> i, samples[0], samples[i-1]);
> }
>
> - for (i = nsamples - 1; samples[i] < usec; i--);
> + for (i = nsamples - 1; i < nsamples && samples[i] < usec; i--);
But this does not seem right, we are decrementing i, hence we should
check that i > 0, otherwise we overflow anyway. With i < nsamples we
will break the cycle after the overflow, which is wrong and works only
by accident (since i is unsigned we overflow to UINT_MAX if we decrement
0).
This should be the correct patch to fix the problem:
diff --git a/lib/tst_timer_test.c b/lib/tst_timer_test.c
index f30ad73dc..0b675f78d 100644
--- a/lib/tst_timer_test.c
+++ b/lib/tst_timer_test.c
@@ -295,7 +295,7 @@ void do_timer_test(long long usec, unsigned int nsamples)
i, samples[0], samples[i-1]);
}
- for (i = nsamples - 1; samples[i] < usec; i--);
+ for (i = nsamples - 1; samples[i] < usec && i > 0; i--);
if (i < nsamples - 1) {
tst_res(TFAIL, "%s woken up early %u times range: [%lli,%lli]",
--
Cyril Hrubis
chrubis@suse.cz
next prev parent reply other threads:[~2017-07-19 12:15 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-17 6:53 [LTP] [PATCH] lib/tst_timer_test.c: fix unsigned int overflow on RHEL5.11GA Xiao Yang
2017-07-19 12:15 ` Cyril Hrubis [this message]
2017-07-20 2:21 ` Xiao Yang
2017-07-20 9:13 ` Cyril Hrubis
2017-07-20 9:25 ` Xiao Yang
2017-07-20 9:38 ` [LTP] [PATCH v2] " Xiao Yang
2017-07-20 11:29 ` Cyril Hrubis
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=20170719121557.GG1015@rei.lan \
--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