git: 9front

Download patch

ref: 892a8f2fda1d6f7c689a8a1e3d07082ccace014f
parent: 54dc58d73f213b67cb67e9084f106c8f46a982e6
author: Ori Bernstein <ori@eigenstate.org>
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);
--