ref: 759aafa007c42dce044800863455ad6048ed0ba5
parent: 88a8ca5c8de86f1f3e5b43a490e0e70c6b456072
author: Ori Bernstein <[email protected]>
date: Fri Jun 25 19:10:07 EDT 2021
rc: skip arguments to Xsrcline, Xsrcfile in codefree We weren't correctly skipping the location operators in codefree. This would mostly be work, but sometimes you'd get unlucky and have one of the argmuents mismatch, and that would lead to an invalid free. This correctly skips the args in codefree.
--- a/sys/src/cmd/rc/code.c
+++ b/sys/src/cmd/rc/code.c
@@ -181,7 +181,7 @@
emits(fnstr(c1));
if((f = curfile(runq)) != nil){
emitf(Xsrcfile);
- emits(strdup(f));
+ emits(estrdup(f));
}
emitf(Xsrcline);
emiti(runq->lexline);
@@ -486,10 +486,11 @@
|| p->f==Xrdwr
|| p->f==Xasync || p->f==Xbackq || p->f==Xcase || p->f==Xfalse
|| p->f==Xfor || p->f==Xjump
+ || p->f==Xsrcline
|| p->f==Xsubshell || p->f==Xtrue) p++;
else if(p->f==Xdup || p->f==Xpipefd) p+=2;
else if(p->f==Xpipe) p+=4;
- else if(p->f==Xglobs) free(p[1].s), p+=2;
+ else if(p->f==Xglobs || p->f==Xsrcfile) free(p[1].s), p+=2;
else if(p->f==Xword || p->f==Xdelhere) free((++p)->s);
else if(p->f==Xfn){
free(p[2].s);