From: Michael Meffie Date: Mon, 6 Nov 2017 22:37:46 +0000 (-0500) Subject: tests: fix out of bounds access in the rx-event test X-Git-Tag: upstream/1.8.0_pre3^2~7 X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=42993b3a33d53a6e16337d2ebe15539d0febdef1;p=packages%2Fo%2Fopenafs.git tests: fix out of bounds access in the rx-event test Use the NUMEVENTS symbol which defines the array size instead of an incorrect hard coded number when checking if a second event can be added to be fired at the same time. This fixes a potential out of bounds access of the event test array. Also update the comment which incorrectly mentions the incorrect number of events in the test. Reviewed-on: https://gerrit.openafs.org/12762 Reviewed-by: Benjamin Kaduk Tested-by: BuildBot (cherry picked from commit 50a3eb7b7ee94bffaadc98429bd404164e89ec7f) Change-Id: I7a975e7498c1c7416a800c9294c97ee4de4fd57a Reviewed-on: https://gerrit.openafs.org/12779 Tested-by: BuildBot Reviewed-by: Michael Meffie Reviewed-by: Benjamin Kaduk --- diff --git a/tests/rx/event-t.c b/tests/rx/event-t.c index bc07fd34b..9c2b8e15e 100644 --- a/tests/rx/event-t.c +++ b/tests/rx/event-t.c @@ -144,7 +144,7 @@ main(void) ok(pthread_create(&handler, NULL, eventHandler, NULL) == 0, "Created handler thread"); - /* Add 1000 random events to fire over the next 3 seconds, but front-loaded + /* Add a number of random events to fire over the next 3 seconds, but front-loaded * a bit so that we can exercise the cancel/fire race path. */ for (counter = 0; counter < NUMEVENTS; counter++) { @@ -160,7 +160,7 @@ main(void) = rxevent_Post(&eventTime, &now, eventSub, &events[counter], NULL, 0); /* A 10% chance that we will schedule another event at the same time */ - if (counter!=999 && random() % 10 == 0) { + if (counter < (NUMEVENTS - 1) && random() % 10 == 0) { counter++; events[counter].event = rxevent_Post(&eventTime, &now, eventSub, &events[counter],