From c12cd325b0c1e5bcd4411384c65567a7590d42f8 Mon Sep 17 00:00:00 2001 From: millert Date: Mon, 1 Nov 2021 18:28:24 +0000 Subject: [PATCH] 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 --- usr.bin/awk/run.c | 16 +++++++++------- 1 file 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); -- 2.20.1