develooper Front page | perl.perl5.porters | Postings from December 2000

[PATCH blead] Fix segfault in gv_handler/mg_find

Thread Next
From:
Daniel Chetlin
Date:
December 24, 2000 04:05
Subject:
[PATCH blead] Fix segfault in gv_handler/mg_find
Message ID:
20001224040507.A3090@darkstar
  [~] $ perlbl -e'package Cat; my Cat @socks'
  Can't declare class for non-scalar @socks in "my" at -e line 1, at
  end of line
  Execution of -e aborted due to compilation errors.
  Segmentation fault

Ilya's change #8131 uncovered this problem, because it switches from
using gv_fetchmethod to gv_handler, but the problem has been there for a
while. The patch to gv_hanlder is the one that fixes it -- I've also
patched mg_find because I think that check should be made, but in the
specific brokenness I found, the mg_find change won't help. I leave it
to the pumpking's discretion whether to apply the mg_find fix.

attrs.t is probably not the best place to test for this, especially when
the failed test is a segfault, but I couldn't find a better spot.

P.S. I used Simon's repository browser to help pin down this problem,
specifically the blame log. Great stuff, Simon.

--- gv.c        2000/12/24 11:15:35     1.1
+++ gv.c        2000/12/24 11:18:45
@@ -1259,9 +1259,12 @@
 Perl_gv_handler(pTHX_ HV *stash, I32 id)
 {
     dTHR;
-    MAGIC *mg = mg_find((SV*)stash,'c');
+    MAGIC *mg;
     AMT *amtp;

+    if (!stash)
+        return Nullcv;
+    mg = mg_find((SV*)stash,'c');
     if (!mg) {
       do_update:
        Gv_AMupdate(stash);
--- mg.c        2000/12/24 11:30:27     1.1
+++ mg.c        2000/12/24 11:30:44
@@ -261,6 +261,8 @@
 Perl_mg_find(pTHX_ SV *sv, int type)
 {
     MAGIC* mg;
+    if (!sv)
+        return 0;
     for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic) {
        if (mg->mg_type == type)
            return mg;
--- t/op/attrs.t        2000/12/24 11:59:21     1.1
+++ t/op/attrs.t        2000/12/24 12:01:24
@@ -142,6 +142,10 @@
 mytest qr/^SCALAR package attributes may clash with future reserved
words: ["']?plugh["']? /;
 BEGIN {++$ntests}

+eval 'package Cat; my Cat @socks;';
+mytest qr/^Can't declare class for non-scalar \@socks in "my"/;
+BEGIN {++$ntests}
+
 sub X::MODIFY_CODE_ATTRIBUTES { die "$_[0]" }
 sub X::foo { 1 }
 *Y::bar = \&X::foo;
End of patch.

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About