diff options
author | Ori Bernstein <ori@eigenstate.org> | 2020-05-13 08:42:00 -0700 |
---|---|---|
committer | Ori Bernstein <ori@eigenstate.org> | 2020-05-13 08:42:00 -0700 |
commit | d332f8a9b5d4437e7d8d0946bb03c13d7fe8a236 (patch) | |
tree | cc59bc8ba224bd0072f505e9fc06aaa520750f38 /sys/src/cmd | |
parent | 1c4c82277ea368739af6a4666ae530bbcfae71cb (diff) |
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.
Diffstat (limited to 'sys/src/cmd')
-rw-r--r-- | sys/src/cmd/yacc.c | 18 |
1 files changed, 8 insertions, 10 deletions
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]); |