diff options
author | Werner Koch <[email protected]> | 2016-01-06 07:31:38 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2016-01-06 07:31:38 +0000 |
commit | 0a00115ee2049ab2357b7a14a51c7da185ffcabd (patch) | |
tree | 8ba811680a3ea2a736a8385534127c7ba5676c57 /common/t-timestuff.c | |
parent | gpg: Align notes about minimal keysize with actual checks. (diff) | |
download | gnupg-0a00115ee2049ab2357b7a14a51c7da185ffcabd.tar.gz gnupg-0a00115ee2049ab2357b7a14a51c7da185ffcabd.zip |
common: Do not deref vars in tests after a fail().
* common/t-convert.c (test_bin2hex): Turn if conditions into if-else
chains to avoid accessing unchecked data.
(test_bin2hexcolon): Ditto.
* common/t-mapstrings.c (test_map_static_macro_string): Ditto.
* common/t-stringhelp.c (test_percent_escape): Ditto.
(test_make_filename_try): Ditto.
(test_make_absfilename_try): Ditto.
* common/t-timestuff.c (test_timegm): Ditto.
--
Note that these dereference only occur after failed regression tests.
Signed-off-by: Werner Koch <[email protected]>
Diffstat (limited to 'common/t-timestuff.c')
-rw-r--r-- | common/t-timestuff.c | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/common/t-timestuff.c b/common/t-timestuff.c index cb7cd392a..a80aaff59 100644 --- a/common/t-timestuff.c +++ b/common/t-timestuff.c @@ -124,25 +124,28 @@ test_timegm (void) tp = gmtime (&now); if (!tp) fail (tidx); - tbuf = *tp; - tbuf2 = tbuf; + else + { + tbuf = *tp; + tbuf2 = tbuf; #ifdef HAVE_TIMEGM - atime = timegm (&tbuf); + atime = timegm (&tbuf); #else - atime = mktime (&tbuf); + atime = mktime (&tbuf); #endif - if (atime == (time_t)(-1)) - fail (tidx); - if (atime != now) - fail (tidx); - - tp = gmtime (&atime); - if (!tp) - fail (tidx); - if (cmp_time_s (tp, &tbuf)) - fail (tidx); - if (cmp_time_s (tp, &tbuf2)) - fail (tidx); + if (atime == (time_t)(-1)) + fail (tidx); + else if (atime != now) + fail (tidx); + + tp = gmtime (&atime); + if (!tp) + fail (tidx); + else if (cmp_time_s (tp, &tbuf)) + fail (tidx); + else if (cmp_time_s (tp, &tbuf2)) + fail (tidx); + } } } |