bss中的静态指针溢出
static pointer overflow in bss
我正在使用 w00w00 练习处理 bss 中的静态指针溢出。我将缓冲区和缓冲区指针放入静态结构中以强制溢出指针。否则,它将指针放在缓冲区之前,并且不会发生溢出。
#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
现在它工作正常。
尝试大于结构大小但又不足以被解释为负值的大小:
memset(a.buf, 'A', 1024);
还请确保使用 -fno-common
进行编译,如 Asan FAQ 中所述。
我正在使用 w00w00 练习处理 bss 中的静态指针溢出。我将缓冲区和缓冲区指针放入静态结构中以强制溢出指针。否则,它将指针放在缓冲区之前,并且不会发生溢出。
#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
现在它工作正常。
尝试大于结构大小但又不足以被解释为负值的大小:
memset(a.buf, 'A', 1024);
还请确保使用 -fno-common
进行编译,如 Asan FAQ 中所述。