Subject: | A possible NULL pointer derefence in sha1() |
A compiler warns:
gcc -c -D_REENTRANT -D_GNU_SOURCE -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fwrapv -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -g -DVERSION=\"2.13\" -DXS_VERSION=\"2.13\" -fPIC "-I/usr/lib64/perl5/CORE" SHA1.c
In file included from /usr/lib64/perl5/CORE/perl.h:2525,
from SHA1.xs:6:
SHA1.xs: In function ‘XS_Digest__SHA1_sha1’:
/usr/lib64/perl5/CORE/handy.h:501:23: warning: null argument where non-null required (argument 1) [-Wnonnull]
501 | #define strEQ(s1,s2) (strcmp(s1,s2) == 0)
| ^~~~~~
SHA1.xs:576:27: note: in expansion of macro ‘strEQ’
576 | if (SvOBJECT(sv) && strEQ(HvNAME(SvSTASH(sv)), "Digest::SHA1"))
| ^~~~~
That's because HvNAME() can return NULL if the stash argument is not a stash. Then the NULL pointer would be passed to strEQ() that is basically strcmp(3) that crashes on a NULL pointer.