c++ - 禁止使用 __sprintf_chk()

标签 c++ c printf fortify-source

我观察到 c++ 程序使用 sprintf,其中此 sprintf 隐式调用 __sprintf_chk()。 此 __sprintf_chk() 似乎通过检查堆栈帧来检查缓冲区溢出。

为了我的研究目的,我想知道是否可以使用 __sprintf_chk() 来禁用它?

最佳答案

尝试将程序中对 sprintf 的所有调用替换为:

 sprintf(params...);

进入

 (sprintf)(params...);

这将禁用任何基于预处理器的 sprintf 更改(*仅当 sprintf 被使用类似函数的宏更改时,如 __sprintf_chk 的情况)。

对于 gcc,有选项 -fno-stack-protector -fno-mudflap。也可以是 -D_FORTIFY_SOURCE=0(对于任何 glibc)

对于 Ubuntu 和 debian,有包含安全功能列表的页面:http://wiki.debian.org/Hardeninghttps://wiki.ubuntu.com/Security/Features 此处列出了一些使用过的编译器标志 https://wiki.ubuntu.com/ToolChain/CompilerFlags

还有一篇关于 SSP (stack-protector) 和 Fortify_source (glibc) 的论文: http://www.linuxfromscratch.org/hints/downloads/files/ssp.txt

PS: the same for __fgets_chk __gets_chk __printf_chk __fprintf_chk __vprintf_chk __vfprintf_chk __vsprintf_chk __wmemcpy_chk __wmemmove_chk __wmempcpy_chk __wmemset_chk __wcscpy_chk __wcpcpy_chk __wcsncpy_chk __wcpncpy_chk __wcscat_chk __wcsncat_chk __swprintf_chk __vswprintf_chk __fwprintf_chk __wprintf_chk __vfwprintf_chk __vwprintf_chk __fgetws_chk __wcrtomb_chk __mbsrtowcs_chk __wcsrtombs_chk __mbsnrtowcs_chk __wcsnrtombs_chk __memcpy_chk __memmove_chk __mempcpy_chk __memset_chk __strcpy_chk __strncpy_chk __stpncpy_chk __strcat_chk and some others

关于c++ - 禁止使用 __sprintf_chk(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12201625/

相关文章:

c++ - <fstream> Release模式下奇怪的内存泄漏

c++ - C++ 中的 PDF 解析 (PoDoFo)

c++ - post increment 和 pre-increment 哪个更快?

c - fgets 只获取我文件的最后一行

c++ - this_thread::sleep_for 早睡

c - 如何删除字符串中的第一个条目

c++ - 使用 ffmpeg 获取文件信息,目标文件被识别为音频?

C、GTK : display stream of RGB images at < 60 fps

c - 因式分解 && 和 ||在 C

c - 如何多次将同一个变量打印到一个字符串中?