Subject: | Wrong nlmsgerr length check |
My compiler reports these warnings:
Building Socket-Netlink
test-3075-0.c: In function 'main':
test-3075-0.c:5:7: warning: unused variable 'ctrl' [-Wunused-variable]
int ctrl = CTRL_CMD_NEWMCAST_GRP;
^~~~
gcc -I/usr/lib64/perl5/CORE -DVERSION="0.04" -DXS_VERSION="0.04" -fPIC -c -D_REENTRANT -D_GNU_SOURCE -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fwrapv -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -g -o lib/Socket/Netlink.o lib/Socket/Netlink.c
lib/Socket/Netlink.xs: In function 'XS_Socket__Netlink_unpack_nlmsgerr':
lib/Socket/Netlink.xs:195:20: warning: comparison of constant '20ul' with boolean expression is always false [-Wbool-compare]
if(!SvCUR(msg) == sizeof(nlmsgerr))
^~
lib/Socket/Netlink.xs:195:20: warning: logical not is only applied to the left hand side of comparison [-Wlogical-not-parentheses]
ExtUtils::Mkbootstrap::Mkbootstrap('blib/arch/auto/Socket/Netlink/Netlink.bs')
gcc -shared -Wl,-z,relro -L/usr/local/lib -fstack-protector-strong -lperl -o blib/arch/auto/Socket/Netlink/Netlink.so lib/Socket/Netlink.o
Especially the lib/Socket/Netlink.xs:195 is troublesome. The code is:
if(!SvPOK(msg))
croak("Expected a string message");
→ if(!SvCUR(msg) == sizeof(nlmsgerr))
croak("Expected %d bytes of message", sizeof(nlmsgerr));
I think the string length comparison is wrong. Correct one should be:
if(SvCUR(msg) != sizeof(nlmsgerr))