string_copying.7 UB in reference implementation stpecpy

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

I recently stumbled upon the `string_copying.7` manpage and while
reading it found some issues.

Specifically the implementation of stpecpy has the following code:

if(src[strlen(src)] != '\0') raise(SIGSEGV);

By definition a string in C is null-terminated. Calling strlen on
something not-a-string is undefined behaviour. It seems that this is
undefined behaviour to catch undefined behaviour?

Aside: gcc 12 compiles away the above on higher optimization levels.

Kind regards,

Simon de Vlieger




[Index of Archives]     [Kernel Documentation]     [Netdev]     [Linux Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux