考虑这段 C 代码:
int main(int argc, char *argv[])
{
char ***map = malloc(sizeof(char *) * 4);
char *a[] = { "hello", "world" };
char *b[] = { "foo", "bar" };
char *c[] = { "test", "last" };
map[0] = a;
map[1] = b;
map[2] = c;
char *p = NULL;
int offset = 30; // buffer exploited!
p = **map + offset;
if (!p)
puts("err"); // not detected?
else
printf("%p %s\n", p, p);
return 0;
}
如何(高效安全)获取map的上界地址,避免bufferoverflow错误,因为如果我char **p = map[random_offset];
直接访问最终会导致运行时错误