summaryrefslogtreecommitdiff
path: root/sys/src/cmd/awk/run.c
AgeCommit message (Collapse)Author
2023-04-06awk: getline: do not access unitialized data on EOFJacob Moody
echo 'a' | awk 'BEGIN { getline l; getline l; print (s=substr(l,1,10)) " len=" length(s) }' https://github.com/onetrueawk/awk/commit/1debe1993fc852545a9215621d884be27f08a223
2023-04-06awk: dont leak memory on extra format argumentsJacob Moody
awk 'BEGIN { while(++i <= 100000) { mem = "ps | grep awk"; printf("%d", 1+2, 3+4, 5+6, 7+8, 9+0) > "/dev/null"; if(i % 10000 == 0) system(mem) }}' https://github.com/onetrueawk/awk/commit/821c502359855d0c43be8e9b08f037ecb543d310
2022-06-25awk: correct incoherent cell in assignment (thanks smj, mpinjr)Ori Bernstein
In run.c::assign(), assigning to $0 from $F, a field, where F >= 2, produces an incoherent cell. The assignment occurs in two steps, first the string value and then the float. When the string value is assigned to $0, setsval invalidates the fields. If FS hasn't changed, after getfval rebuilds the fields, NF = 1 and F >= 2, therefore $F is definitely uninitialized. The result is a float val of 0.0, producing a boolean false in the pattern expression. Coercing a string comparison gives the expected result because the incoherent cell has the correct string value, which is not empty and evaluates to true.
2022-03-12awk: fix off-by-one string buffer overflow from gsubcinap_lenrek
the bug happens when we did the fast exit thru "done" label, where we would not make sure that theres space in the buffer for the NUL terminator. instead, avoid the fast exit and always do the final adjbuf() that makes sure we have space for the NUL terminator. remove the pointless pb checks, they'r wrong (should'v been bp >= buf+bufsz) and adjbuf() already makes sure this can never happen.
2020-11-19awk: fix truncated input after fflushAnthony Martin
Before the "native" awk work, a call to the fflush function resulted in one or more calls to the APE fflush(2). Calling fflush on a stream open for reading has different behavior based on the environment: within APE, it's a no-op¹; on OpenBSD, it's an error²; in musl, it depends on whether or not the underlying file descriptor is seekable³; etc. I'm sure glibc is subtly different. Now that awk uses libbio, things are different: calling Bflush(2) on a file open for reading simply discards any data in the buffer. This explains why we're seeing truncated input. When awk attempts to read in the next record, there's nothing in the buffer and no more data to read so it gets EOF and exits normally. Note that this behavior is not documented in bio(2). It was added in the second edition but I haven't figured out why or what depends on it. The simple fix is to have awk only call Bflush on files that were opened for writing. You could argue that this is the only correct behavior according to the awk(1) manual and it is, in fact, how GNU awk behaves⁴. 1. /sys/src/ape/lib/ap/stdio/fflush.c 2. https://cvsweb.openbsd.org/src/lib/libc/stdio/fflush.c?rev=1.9 3. https://git.musl-libc.org/cgit/musl/tree/src/stdio/fflush.c 4. https://git.savannah.gnu.org/cgit/gawk.git/tree/io.c#n1492
2018-10-31awk(1): fix append operator to avoid truncating fileAlex Musolino
2017-08-12awk: allow string as exit statuscinap_lenrek
2016-12-18awk: improve random number generationcinap_lenrek
don't use rand() and scale it to 0..1, instead call native frand() which produces uniform random number. instead of seeding the rng with time(0), use truerand().
2016-08-18fix awk format printing bugs (thanks aiju)spew
2016-05-27awk: restore old buffering behaviour for printfcinap_lenrek
2016-05-01just use wait in "system" call for awk, get rid of unix dependent status ↵spew
code divisor
2016-05-01null terminate await buffer for proper tokenize callspew
2016-05-01use rc in awk, remove awk from APEDIRS in cmd mkfileben
2016-04-28fix printing a char from an empty stringben
2016-04-28fix printing a char from a string that starts with a runeben
2016-04-28fix unsigned printing for awkben
2016-04-27use Beof for awk portben
2016-04-26New libregexp and APE ported to nativeben
2012-12-10awk: fix the fixcinap_lenrek
be more carefull. have to preserve DONTFREE flag!
2012-12-10awk: prevent split(a[x], a) from freeing a[x]cinap_lenrek
the freesymtab() call frees the y argument. temporarily mark it not to be freed.
2011-03-30Import sources from 2011-03-30 iso image - libTaru Karttunen
2011-03-30Import sources from 2011-03-30 iso imageTaru Karttunen