此功能通常只是错误报告程序。来自glibc的示例代码是:
extern char **__libc_argv attribute_hidden;
void
__attribute__ ((noreturn))
__fortify_fail (msg)
const char *msg;
{
/* The loop is added only to keep gcc happy. */
while (1)
__libc_message (2, "*** %s ***: %s terminated\n",
msg, __libc_argv[0] ?: "<unknown>");
}
libc_hidden_def (__fortify_fail)
Run Code Online (Sandbox Code Playgroud)
它可能在这里和那里被称为要加强来源的地方。“设防”本身只是几个运行时检查。openat来自的函数的示例用法io/openat.c是:
int
__openat_2 (fd, file, oflag)
int fd;
const char *file;
int oflag;
{
if (oflag & O_CREAT)
__fortify_fail ("invalid openat call: O_CREAT without mode");
return __openat (fd, file, oflag);
}
Run Code Online (Sandbox Code Playgroud)
没有设防,O_CREAT没有模式是可以接受的(这种情况仍然高度可疑,这是合法的)。
考虑一下__fortify_failprintf + abort。
开启心灵感应,您可能会建议用户在用户代码中使用libc时遇到一些问题。/lib/x86_64-linux-gnu/libc.so.6(+0xebdf0)[0x7f75d3576df0]是libc内部某个运行时检查失败pd[0x49b5c0]的地方,也是libc错误地从中调用的地方。