changelog shortlog tags branches changeset file revisions annotate raw help

Mercurial > hg > plan9front / sys/src/9/bcm/bootargs.c

revision 7234: fc141b91ed8a
parent 7159: 66132ebbe687
     1.1--- a/sys/src/9/bcm/bootargs.c
     1.2+++ b/sys/src/9/bcm/bootargs.c
     1.3@@ -88,34 +88,37 @@ plan9iniinit(char *s, int cmdline)
     1.4 void
     1.5 bootargsinit(void)
     1.6 {
     1.7+	static char maxmem[11];
     1.8+	char x, *e;
     1.9 	Atag *a;
    1.10-	int n;
    1.11 
    1.12-	a = (Atag*)BOOTARGS;
    1.13+	e = BOOTARGS;
    1.14+	a = (Atag*)e;
    1.15 	if(a->tag != AtagCore){
    1.16-		plan9iniinit((char*)a, 0);
    1.17+		plan9iniinit(e, 0);
    1.18 		return;
    1.19 	}
    1.20-	while(a->tag != AtagNone && a->size != 0){
    1.21+	while(a->tag != AtagNone){
    1.22+		e += a->size * sizeof(u32int);
    1.23+		if(a->size < 2 || e < (char*)a || e > &BOOTARGS[BOOTARGSLEN])
    1.24+			break;
    1.25 		switch(a->tag){
    1.26 		case AtagMem:
    1.27-			/* use only first bank */
    1.28-			if(conf.mem[0].limit == 0 && a->mem.size != 0){
    1.29-				memsize = a->mem.size;
    1.30-				conf.mem[0].base = a->mem.base;
    1.31-				conf.mem[0].limit = a->mem.base + memsize;
    1.32+			if(findconf("*maxmem") < 0){
    1.33+				snprint(maxmem, sizeof(maxmem), "%ud", a->mem.base+a->mem.size);
    1.34+				addconf("*maxmem", maxmem);
    1.35 			}
    1.36 			break;
    1.37 		case AtagCmdline:
    1.38-			n = (a->size * sizeof(u32int)) - offsetof(Atag, cmdline[0]);
    1.39-			if(a->cmdline + n < BOOTARGS + BOOTARGSLEN)
    1.40-				a->cmdline[n] = 0;
    1.41-			else
    1.42-				BOOTARGS[BOOTARGSLEN-1] = 0;
    1.43+			x = *e;
    1.44+			*e = 0;
    1.45 			plan9iniinit(a->cmdline, 1);
    1.46+			*e = x;
    1.47 			break;
    1.48 		}
    1.49-		a = (Atag*)((u32int*)a + a->size);
    1.50+		if(e > &BOOTARGS[BOOTARGSLEN-8])
    1.51+			break;
    1.52+		a = (Atag*)e;
    1.53 	}
    1.54 }
    1.55 
    1.56@@ -164,6 +167,7 @@ writeconf(void)
    1.57 	if(n >= BOOTARGSLEN)
    1.58 		error("kernel configuration too large");
    1.59 	memmove(BOOTARGS, p, n);
    1.60+	memset(BOOTARGS+n, 0, BOOTARGSLEN-n);
    1.61 	poperror();
    1.62 	free(p);
    1.63 }