我在bss中使用静态指针溢出的w00w00练习。我将缓冲区和缓冲区指针放入静态结构中以强制溢出指针。否则,它将指针置于缓冲区之前并且不会发生溢出。
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#define BUFSIZE 16
#define ADDRLEN 4 /* # of bytes in an address */
int main()
{
u_long diff;
struct buf {
char buf[BUFSIZE];
char *bufptr ;
} ;
static struct buf a;
a.bufptr = a.buf, diff = (u_long)a.buf - (u_long)&a.bufptr;
printf("bufptr (%p) = %p, buf = %p, diff = 0x%x (%d) bytes\n",
&a.bufptr,a.bufptr, a.buf, diff, diff);
memset(a.buf, 'A', (u_int)(diff + ADDRLEN));
printf("bufptr (%p) = %p, buf = %p, diff = 0x%x (%d) bytes\n",
&a.bufptr, a.bufptr, a.buf, diff, diff);
return 0;
}
当我使用AddressSanitizer
时,我正在收到此错误==27643==ERROR: AddressSanitizer: negative-size-param: (size=-12)
SUMMARY: AddressSanitizer: negative-size-param ??:0 __asan_memset
==27643==ABORTING
是否有标志或方法强制溢出?
修改 我发现了问题。差异结果是-16。 我生气它看起来像这样
diff = (u_long)&a.bufptr - (u_long)a.buf
现在它工作正常。
答案 0 :(得分:0)