[LTP] [PATCH v2] lib/tst_timer_test.c: fix unsigned int overflow on RHEL5.11GA

Xiao Yang yangx.jy@cn.fujitsu.com
Thu Jul 20 11:38:34 CEST 2017


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.  We add check the
array boundary to fix it.

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..c8e2d38 100644
--- a/lib/tst_timer_test.c
+++ b/lib/tst_timer_test.c
@@ -266,7 +266,7 @@ void do_timer_test(long long usec, unsigned int nsamples)
 	unsigned int discard = compute_discard(nsamples);
 	unsigned int keep_samples = nsamples - discard;
 	long long threshold = compute_threshold(usec, keep_samples);
-	unsigned int i;
+	int i;
 	int failed = 0;
 
 	tst_res(TINFO,
@@ -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 > -1; i--);
 
 	if (i < nsamples - 1) {
 		tst_res(TFAIL, "%s woken up early %u times range: [%lli,%lli]",
-- 
1.8.3.1





More information about the ltp mailing list