从一个跨二十年的glibc bug说起

这几天调gcc 7.5.0 +glibc 2.23的交叉编译工具链,由于gcc 7.5.0的默认打开Werr,偶然发现了glibc一个隐藏了二十年的世纪大bug。

这个bug在glibc 2.0版本刚开始就引入了,但直到2.25版本才最终解决,即使按glibc-2.0.1.bin.alpha-linux.tar.gz 版本的发布时间(04-Feb-1997)到glibc-2.25.tar.bz2 的发布时间(05-Feb-2017),也持续了20年加一天。

用gcc 7.5编译的时候如果使能-Wall -Werror这2个选项(-Wall 英文说明是Enable most warning messages,表示使能大多数告警上报;-Werror表示所有告警都当错误来上报,不可忽略),会报下面的错误:

nss_nisplus/nisplus-alias.c: In function '_nss_nisplus_getaliasbyname_r': nss_nisplus/nisplus-alias.c:300:12: error: argument 1 null where non-null expected [-Werror=nonnull] char buf[strlen (name) + 9 + tablename_len]; ^~~~~~~~~~~~~ In file included from ../include/string.h:54:0, from ../sysdeps/generic/hp-timing-common.h:40, from ../sysdeps/x86_64/hp-timing.h:38, from ../include/libc-internal.h:7, from ../sysdeps/x86_64/nptl/tls.h:29, from ../sysdeps/x86_64/atomic-machine.h:20, from ../include/atomic.h:50, from nss_nisplus/nisplus-alias.c:19: ../string/string.h:394:15: note: in a call to function 'strlen' declared here extern size_t strlen (const char *__s) ^~~~~~ nss_nisplus/nisplus-alias.c:303:39: error: '%s' directive argument is null [-Werror=format-truncation=] snprintf (buf, sizeof (buf), "[name=%s],%s", name, tablename_val); ^~ cc1: all warnings being treated as errors

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zgjgwy.html