Apparent i386 alloca.S bug (was: adsl/pppoe no longer connecting on 5.1)

From: Tim Robbins <tjr_at_FreeBSD.ORG>
Date: Thu, 12 Jun 2003 18:29:44 +1000
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);
}
Received on Wed Jun 11 2003 - 23:36:51 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:37:11 UTC