diff options
author | Jarkko Hietaniemi <jhi@iki.fi> | 2014-05-07 09:26:52 -0400 |
---|---|---|
committer | Tony Cook <tony@develop-help.com> | 2014-05-29 14:50:11 +1000 |
commit | b35b96b6f8e35207d18b15dfcdbd0d08a7c6437c (patch) | |
tree | 005d69e19363295be1dc3e30f5d0ac39c586bf68 /pp_sys.c | |
parent | 0a20f69bae04ff02616da2f0128de4e842151093 (diff) | |
download | perl-b35b96b6f8e35207d18b15dfcdbd0d08a7c6437c.tar.gz |
Uninitialized tmbuf.
Fix for Coverity perl5 CID 29088: Uninitialized scalar variable (UNINIT)
uninit_use: Using uninitialized value tmbuf.tm_year.
There is a code path that can lead to accessing uninitialized tmbuf:
when the too-small or too-large time inputs to gmtime/localtime
happen.
- make it so that the tm_year is used only on successful code path:
pp_sys.c
- add the gmtime failed / localtime failed errors to perldiag:
pod/perldiag.pod
- test those errors: t/op/time.t
Diffstat (limited to 'pp_sys.c')
-rw-r--r-- | pp_sys.c | 27 |
1 files changed, 13 insertions, 14 deletions
@@ -4485,30 +4485,29 @@ PP(pp_gmtime) } if (err == NULL) { + /* diag_listed_as: gmtime(%f) failed */ /* XXX %lld broken for quads */ Perl_ck_warner(aTHX_ packWARN(WARN_OVERFLOW), "%s(%.0" NVff ") failed", opname, when); } if (GIMME != G_ARRAY) { /* scalar context */ - SV *tsv; - /* XXX newSVpvf()'s %lld type is broken, so cheat with a double */ - double year = (double)tmbuf.tm_year + 1900; - EXTEND(SP, 1); EXTEND_MORTAL(1); if (err == NULL) RETPUSHUNDEF; - - tsv = Perl_newSVpvf(aTHX_ "%s %s %2d %02d:%02d:%02d %.0f", - dayname[tmbuf.tm_wday], - monname[tmbuf.tm_mon], - tmbuf.tm_mday, - tmbuf.tm_hour, - tmbuf.tm_min, - tmbuf.tm_sec, - year); - mPUSHs(tsv); + else { + mPUSHs(Perl_newSVpvf(aTHX_ "%s %s %2d %02d:%02d:%02d %.0f", + dayname[tmbuf.tm_wday], + monname[tmbuf.tm_mon], + tmbuf.tm_mday, + tmbuf.tm_hour, + tmbuf.tm_min, + tmbuf.tm_sec, + /* XXX newSVpvf()'s %lld type is broken, + * so cheat with a double */ + (double)tmbuf.tm_year + 1900)); + } } else { /* list context */ if ( err == NULL ) |