kselftest: vDSO: Fix accumulation of uninitialized ret when CLOCK_REALTIME is undefined
Subsystems (3)
PATCH 1/1 kselftest: vDSO: Fix accumulation of uninitialized ret when CLOCK_REALTIME is undefined
In the unlikely case that CLOCK_REALTIME is not defined, variable ret is not initialized and further accumulation of return values to ret can leave ret in an undefined state. Fix this by initialized ret to zero and changing the assignment of ret to an accumulation for the CLOCK_REALTIME case.
--- tools/testing/selftests/vDSO/vdso_test_clock_getres.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/vDSO/vdso_test_clock_getres.c +2 -2
@@ -84,12 +84,12 @@ static inline int vdso_test_clock(unsigned int clock_id)int main (int argc,char **argv) { -int ret; +int ret =0 ;#if _POSIX_TIMERS >0 #ifdef CLOCK_REALTIME - ret =vdso_test_clock (CLOCK_REALTIME ); + ret +=vdso_test_clock (CLOCK_REALTIME );#endif #ifdef CLOCK_BOOTTIME
Signature · 1 line
2.30.2
Hi Colin,
Quoted 5 lines · Colin Ian King
In the unlikely case that
CLOCK_REALTIMEis not defined, variable ret is not initialized and further accumulation of return values to ret can leave ret in an undefined state. Fix this by initialized ret to zero and changing the assignment of ret to an accumulation for theCLOCK_REALTIMEcase.
I was wondering how did you find this.
Apart that:
Quoted 25 lines
Fixes 03f55c7952c9 ("kselftest: Extend vDSO selftest to clock_getres")Signed-off-by Colin Ian King <[email protected]>--- tools/testing/selftests/vDSO/vdso_test_clock_getres.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)tools/testing/selftests/vDSO/vdso_test_clock_getres.c +2
-2@@ -84,12 +84,12 @@ static inline int vdso_test_clock(unsigned int clock_id)int main (int argc,char **argv) { -int ret; +int ret =0 ;#if _POSIX_TIMERS >0 #ifdef CLOCK_REALTIME - ret =vdso_test_clock (CLOCK_REALTIME ); + ret +=vdso_test_clock (CLOCK_REALTIME );#endif #ifdef CLOCK_BOOTTIME
Signature · 2 lines
Regards, Vincenzo
Quoted 10 lines · Vincenzo Frascino
Hi Colin,
Quoted 5 lines · Colin Ian King
In the unlikely case that
CLOCK_REALTIMEis not defined, variable ret is not initialized and further accumulation of return values to ret can leave ret in an undefined state. Fix this by initialized ret to zero and changing the assignment of ret to an accumulation for theCLOCK_REALTIMEcase.I was wondering how did you find this.
I used cppcheck --force --enable=all, this examines the #if defined() paths.
Quoted 31 lines
Apart that:
Reviewed-by Vincenzo Frascino <[email protected]>Quoted 25 lines
Fixes 03f55c7952c9 ("kselftest: Extend vDSO selftest to clock_getres")Signed-off-by Colin Ian King <[email protected]>--- tools/testing/selftests/vDSO/vdso_test_clock_getres.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)tools/testing/selftests/vDSO/vdso_test_clock_getres.c +2
-2@@ -84,12 +84,12 @@ static inline int vdso_test_clock(unsigned int clock_id)int main (int argc,char **argv) { -int ret; +int ret =0 ;#if _POSIX_TIMERS >0 #ifdef CLOCK_REALTIME - ret =vdso_test_clock (CLOCK_REALTIME ); + ret +=vdso_test_clock (CLOCK_REALTIME );#endif #ifdef CLOCK_BOOTTIME
Shuah Khan
maintainerQuoted 10 lines · Colin King (gmail)
Quoted 9 lines · Vincenzo Frascino
Hi Colin,
Quoted 5 lines · Colin Ian King
In the unlikely case that
CLOCK_REALTIMEis not defined, variable ret is not initialized and further accumulation of return values to ret can leave ret in an undefined state. Fix this by initialized ret to zero and changing the assignment of ret to an accumulation for theCLOCK_REALTIMEcase.
Quoted 9 lines
Quoted 1 line
I was wondering how did you find this.
I used cppcheck --force --enable=all, this examines the #if
defined()paths.Quoted 5 lines
Apart that:
Reviewed-by Vincenzo Frascino <[email protected]>
Applied to linux-kselftest next
thanks,
-- Shuah