Apparent i386 alloca.S bug (was: adsl/pppoe no longer connecting on
5.1)
Tim Robbins
tjr at FreeBSD.ORG
Thu Jun 12 01:36:51 PDT 2003
Here's a test program for the i386 alloca() bug. Compile with -std=gnu89 (or
no -std option) and it works fine. Compile with -std=c99 or -std=c89 and it
breaks like this:
corruption: 05 should be 0xcc at offset 0
corruption: 00 should be 0xcc at offset 1
corruption: 00 should be 0xcc at offset 2
corruption: 00 should be 0xcc at offset 3
Interestingly, gcc -std=c89 on FreeBSD 4.8 doesn't trigger the bug.
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define NUMBYTES 511
static void
somefunc(int a, int b, int c, int d, int e)
{
}
int
main(int argc, char *argv[])
{
char *s;
int i;
int failed;
s = alloca(NUMBYTES);
memset(s, 0xcc, NUMBYTES);
somefunc(1, 2, 3, 4, 5);
failed = 0;
for (i = 0; i < NUMBYTES; i++) {
if ((unsigned char)s[i] != 0xcc) {
printf("corruption: %02x should be 0xcc at offset %d\n",
(unsigned char)s[i], i);
failed = 1;
}
}
exit(failed);
}
More information about the freebsd-current
mailing list