This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
mg_find can return NULL.
authorJarkko Hietaniemi <jhi@iki.fi>
Tue, 23 Jun 2015 01:46:09 +0000 (21:46 -0400)
committerJarkko Hietaniemi <jhi@iki.fi>
Sat, 27 Jun 2015 03:09:40 +0000 (23:09 -0400)
CID 104831: Dereference null return value (NULL_RETURNS)
43. dereference: Dereferencing a pointer that might be null Perl_mg_find(sv, 112) when calling Perl_magic_existspack. (The dereference is assumed on the basis of the 'nonnull' parameter attribute.)
499                magic_existspack(svret, mg_find(sv, PERL_MAGIC_tiedelem));

hv.c

diff --git a/hv.c b/hv.c
index e5bf629..f81de13 100644 (file)
--- a/hv.c
+++ b/hv.c
@@ -496,7 +496,11 @@ Perl_hv_common(pTHX_ HV *hv, SV *keysv, const char *key, STRLEN klen,
                }
                if (flags & HVhek_FREEKEY)
                    Safefree(key);
-               magic_existspack(svret, mg_find(sv, PERL_MAGIC_tiedelem));
+               {
+                  MAGIC * const mg = mg_find(sv, PERL_MAGIC_tiedelem);
+                  if (mg)
+                    magic_existspack(svret, mg);
+               }
                /* This cast somewhat evil, but I'm merely using NULL/
                   not NULL to return the boolean exists.
                   And I know hv is not NULL.  */