git: 9front

Download patch

ref: 43f9ae6b32007c8c0583b3cda3af92f8a92dab9d
parent: 6e30db6303c72892a1177b3880bd1f3bdef57487
author: Ori Bernstein <ori@eigenstate.org>
date: Wed May 13 04:42:00 EDT 2020

fix yacc crash with absolute paths

When passing an absolute file path to yacc, we would skip
initializing inpath, leaving it null. This would cause Bopen
to die. We would similarly fail to report an error if we tried
to get the current working directory, and then die when
constructing inpath.

This fixes both cases.

--- a/sys/src/cmd/yacc.c
+++ b/sys/src/cmd/yacc.c
@@ -1185,7 +1185,7 @@
 	long c, t;
 	int i, j, lev, ty, ytab, *p;
 	int vflag, dflag, stem;
-	char actnm[8], *stemc, *s, dirbuf[128];
+	char actnm[8], *stemc, dirbuf[512];
 
 	ytab = 0;
 	vflag = 0;
@@ -1230,16 +1230,14 @@
 	Blethal(faction, nil);
 	if(argc < 1)
 		error("no input file");
+
+	dirbuf[0] = '\0';
 	infile = argv[0];
-	if(infile[0] != '/' && getwd(dirbuf, sizeof dirbuf)!=nil){
-		i = strlen(infile)+1+strlen(dirbuf)+1+10;
-		s = malloc(i);
-		if(s != nil){
-			snprint(s, i, "%s/%s", dirbuf, infile);
-			cleanname(s);
-			inpath = s;
-		}
-	}
+	if(infile[0] != '/' && getwd(dirbuf, sizeof dirbuf)==nil)
+		error("cannot get cwd");
+	inpath = smprint("%s/%s", dirbuf, infile);
+	cleanname(inpath);
+
 	finput = Bopen(inpath, OREAD);
 	if(finput == 0)
 		error("cannot open '%s'", argv[0]);
--