From d332f8a9b5d4437e7d8d0946bb03c13d7fe8a236 Mon Sep 17 00:00:00 2001 From: Ori Bernstein Date: Wed, 13 May 2020 08:42:00 -0700 Subject: 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. --- sys/src/cmd/yacc.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'sys/src/cmd/yacc.c') diff --git a/sys/src/cmd/yacc.c b/sys/src/cmd/yacc.c index 997c2aac7..6d90c643c 100644 --- a/sys/src/cmd/yacc.c +++ b/sys/src/cmd/yacc.c @@ -1185,7 +1185,7 @@ setup(int argc, char *argv[]) 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 @@ setup(int argc, char *argv[]) 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]); -- cgit v1.2.3