acme: validate address range, when writing to addr

Report an "address out of order" error instead of crashing, e.g. when
running

	9 echo -n '#3,#2'  | 9p write acme/$winid/addr
	9 echo -n 'dot=addr' | 9p write acme/$winid/ctl

or

	9 echo -n '0/yyy/,0/xxx/' | 9p write acme/$winid/addr
	9 echo -n 'dot=addr'      | 9p write acme/$winid/ctl

with `acme/$winid/body`

	xxx yyy
This commit is contained in:
Alexander Ben Nasrallah 2020-03-24 20:46:00 +01:00
parent d0d440860f
commit 5270568e3c
2 changed files with 8 additions and 1 deletions

View file

@ -205,6 +205,8 @@ address(uint showerr, Text *t, Range lim, Range ar, void *a, uint q0, uint q1, i
r.q1 = nr.q1; r.q1 = nr.q1;
} }
*qp = q; *qp = q;
if (r.q0 > r.q1)
*evalp = FALSE;
return r; return r;
case '+': case '+':
case '-': case '-':

View file

@ -21,6 +21,7 @@ char Edel[] = "deleted window";
char Ebadctl[] = "ill-formed control message"; char Ebadctl[] = "ill-formed control message";
char Ebadaddr[] = "bad address syntax"; char Ebadaddr[] = "bad address syntax";
char Eaddr[] = "address out of range"; char Eaddr[] = "address out of range";
char Eaddrord[] = "address out of order";
char Einuse[] = "already in use"; char Einuse[] = "already in use";
char Ebadevent[] = "bad event syntax"; char Ebadevent[] = "bad event syntax";
extern char Eperm[]; extern char Eperm[];
@ -493,7 +494,11 @@ xfidwrite(Xfid *x)
break; break;
} }
if(!eval){ if(!eval){
respond(x, &fc, Eaddr); if (a.q0 > a.q1) {
respond(x, &fc, Eaddrord);
} else {
respond(x, &fc, Eaddr);
}
break; break;
} }
w->addr = a; w->addr = a;