aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTodd C. Miller <Todd.Miller@sudo.ws>2021-11-01 11:58:54 -0600
committerTodd C. Miller <Todd.Miller@sudo.ws>2021-11-01 12:03:32 -0600
commit1debe1993fc852545a9215621d884be27f08a223 (patch)
tree6187063343ced031fd9c81cc33d4e7a193d073ab
parent275a80ff33ef2782f27c4fd720b65645c89e2bbb (diff)
downloadone-true-awk-1debe1993fc852545a9215621d884be27f08a223.tar.gz
awkgetline: do not access unitialized data on EOF
getrec() returns 0 on EOF and leaves the contents of buf unchanged. Fixes #133.
-rw-r--r--run.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/run.c b/run.c
index da4f555..3ad9ecf 100644
--- a/run.c
+++ b/run.c
@@ -447,13 +447,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);