diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2021-11-01 18:28:25 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2021-11-01 18:28:25 +0000 |
commit | 984e0e1ed7b4c4ec151a54d86b917b7d4459b6c1 (patch) | |
tree | 9d73a1708bd8cc3690f80c469c9994d56c1e46ad /usr.bin/awk/run.c | |
parent | 039479a556ce591fe08ea49b12d63100c7e7232a (diff) |
awkgetline: do not access unitialized data on EOF
getrec() returns 0 on EOF and leaves the contents of buf unchanged.
From https://github.com/onetrueawk/awk/pull/134
Diffstat (limited to 'usr.bin/awk/run.c')
-rw-r--r-- | usr.bin/awk/run.c | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/usr.bin/awk/run.c b/usr.bin/awk/run.c index d7570bcb31f..128a7eaead6 100644 --- a/usr.bin/awk/run.c +++ b/usr.bin/awk/run.c @@ -1,4 +1,4 @@ -/* $OpenBSD: run.c,v 1.69 2020/12/09 20:00:11 millert Exp $ */ +/* $OpenBSD: run.c,v 1.70 2021/11/01 18:28:24 millert Exp $ */ /**************************************************************** Copyright (C) Lucent Technologies 1997 All Rights Reserved @@ -448,13 +448,15 @@ Cell *awkgetline(Node **a, int n) /* get next line from specific input */ n = getrec(&record, &recsize, true); else { /* getline var */ n = getrec(&buf, &bufsize, false); - x = execute(a[0]); - setsval(x, buf); - if (is_number(x->sval, & result)) { - x->fval = result; - x->tval |= NUM; + if (n > 0) { + x = execute(a[0]); + setsval(x, buf); + if (is_number(x->sval, & result)) { + x->fval = result; + x->tval |= NUM; + } + tempfree(x); } - tempfree(x); } } setfval(r, (Awkfloat) n); |