C 通过链接器脚本插入库函数:其他函数导致segfault
我目前正在使用C 通过链接器脚本插入库函数:其他函数导致segfault,c,linux,printf,ld,ld-preload,C,Linux,Printf,Ld,Ld Preload,我目前正在使用LD_PRELOAD技巧,并且正在使用链接器版本脚本。我的MCVE代码包含在下面 #define _GNU_SOURCE #include <dlfcn.h> #include <stdio.h> #include <stdarg.h> #include <string.h> #include <unistd.h> #define BUFFER_SIZE (1024) int __printf__(const
LD_PRELOAD
技巧,并且正在使用链接器版本脚本。我的MCVE代码包含在下面
#define _GNU_SOURCE
#include <dlfcn.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <unistd.h>
#define BUFFER_SIZE (1024)
int __printf__(const char *fmt, ...)
{
char buf[BUFFER_SIZE] = { 0 };
int ret;
int len;
va_list args;
va_start(args, fmt);
vsnprintf(buf, BUFFER_SIZE - 1, fmt, args);
#if 1
//typeof(vsnprintf) *real_func = dlsym(RTLD_NEXT, "vsnprintf");
//(*real_func)(buf, BUFFER_SIZE - 1, fmt, args);
#endif
len = strlen(buf);
ret = write(STDOUT_FILENO, buf, len);
va_end(args);
return ret;
}
asm(".symver __printf__, __printf_chk@GLIBC_2.3.4");
是什么导致了这次事故
谢谢。您已经覆盖了glibc内部函数
\uuu printf\u chk
,但是该函数没有与printf匹配的原型。它的原型是:
int __printf_chk(int flag, const char * format, ...);
因此,请确保您自己的\uuuu printf\uuu
函数也具有该原型。
这里有一个关于\u printf\u chk
int __printf_chk(int flag, const char * format, ...);