This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
avoid using uninitialized memory in require version check
authorGurusamy Sarathy <gsar@cpan.org>
Mon, 24 Apr 2000 08:08:59 +0000 (08:08 +0000)
committerGurusamy Sarathy <gsar@cpan.org>
Mon, 24 Apr 2000 08:08:59 +0000 (08:08 +0000)
p4raw-id: //depot/perl@5924

pp_ctl.c
universal.c

index 7a2eb20..e77901d 100644 (file)
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -2916,8 +2916,8 @@ PP(pp_require)
 
     sv = POPs;
     if (SvNIOKp(sv)) {
-       UV rev, ver, sver;
-       if (SvPOKp(sv)) {               /* require v5.6.1 */
+       if (SvPOK(sv) && SvNOK(sv)) {           /* require v5.6.1 */
+           UV rev = 0, ver = 0, sver = 0;
            I32 len;
            U8 *s = (U8*)SvPVX(sv);
            U8 *end = (U8*)SvPVX(sv) + SvCUR(sv);
@@ -2929,14 +2929,8 @@ PP(pp_require)
                    s += len;
                    if (s < end)
                        sver = utf8_to_uv(s, &len);
-                   else
-                       sver = 0;
                }
-               else
-                   ver = 0;
            }
-           else
-               rev = 0;
            if (PERL_REVISION < rev
                || (PERL_REVISION == rev
                    && (PERL_VERSION < ver
@@ -2947,6 +2941,7 @@ PP(pp_require)
                    "v%d.%d.%d, stopped", rev, ver, sver, PERL_REVISION,
                    PERL_VERSION, PERL_SUBVERSION);
            }
+           RETPUSHYES;
        }
        else if (!SvPOKp(sv)) {                 /* require 5.005_03 */
            if ((NV)PERL_REVISION + ((NV)PERL_VERSION/(NV)1000)
@@ -2975,8 +2970,8 @@ PP(pp_require)
                        PERL_SUBVERSION);
                }
            }
+           RETPUSHYES;
        }
-       RETPUSHYES;
     }
     name = SvPV(sv, len);
     if (!(name && len > 0 && *name))
index 9adc42d..6c555a1 100644 (file)
@@ -262,7 +262,7 @@ XS(XS_UNIVERSAL_VERSION)
                    break;
            }
            if (len) {
-               if (SvNIOKp(req) && SvPOK(req)) {
+               if (SvNOK(req) && SvPOK(req)) {
                    /* they said C<use Foo v1.2.3> and $Foo::VERSION
                     * doesn't look like a float: do string compare */
                    if (sv_cmp(req,sv) == 1) {
@@ -283,7 +283,7 @@ XS(XS_UNIVERSAL_VERSION)
        /* if we get here, we're looking for a numeric comparison,
         * so force the required version into a float, even if they
         * said C<use Foo v1.2.3> */
-       if (SvNIOKp(req) && SvPOK(req)) {
+       if (SvNOK(req) && SvPOK(req)) {
            NV n = SvNV(req);
            req = sv_newmortal();
            sv_setnv(req, n);