diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-05-10 06:59:01 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-05-10 06:59:01 +0000 |
commit | 23e292701dcd1304a5aaa9a74819934677226ca5 (patch) | |
tree | 2f0c920c523fb8dc557305c9ed0cb31abc75484b | |
parent | 4675583d5e39937489e726fa0f8b62753e89e9fc (diff) | |
parent | 2591b9c58663d594be6db5830ac7d404301f71d6 (diff) | |
download | one-true-awk-android13-mainline-extservices-release.tar.gz |
Snap for 8564071 from 2591b9c58663d594be6db5830ac7d404301f71d6 to mainline-extservices-releaseaml_ext_331814220aml_ext_331412000aml_ext_331312000aml_ext_331112010aml_ext_331012020android13-mainline-extservices-release
Change-Id: Ice5b80f7b278fe5a650797c88cd7b28b07da85ec
-rw-r--r-- | FIXES | 32 | ||||
-rw-r--r-- | METADATA | 8 | ||||
-rw-r--r-- | README.md | 13 | ||||
-rw-r--r-- | b.c | 11 | ||||
-rw-r--r-- | bugs-fixed/getline-corruption.awk | 5 | ||||
-rw-r--r-- | bugs-fixed/getline-corruption.in | 1 | ||||
-rw-r--r-- | bugs-fixed/getline-corruption.ok | 1 | ||||
-rw-r--r-- | lib.c | 4 | ||||
-rw-r--r-- | main.c | 8 | ||||
-rw-r--r-- | run.c | 51 | ||||
-rwxr-xr-x | testdir/T.misc | 25 |
11 files changed, 119 insertions, 40 deletions
@@ -25,6 +25,38 @@ THIS SOFTWARE. This file lists all bug fixes, changes, etc., made since the AWK book was sent to the printers in August, 1987. +December 8, 2021: + The error handling in closefile and closeall was mangled. Long + standing warnings had been made fatal and some fatal errors went + undetected. Thanks to Miguel Pineiro Jr. <mpj@pineiro.cc>. + +Nov 03, 2021: + getline accesses uninitialized data after getrec() + returns 0 on EOF and leaves the contents of buf unchanged. + Thanks to Volodymyr Gubarkov, and Todd C Miller. + +Oct 12, 2021: + The fix for #83 changed the code to insert 2 chars, but the + call to adjbuf just above it only allows for 1 char. This can + cause a heap buffer overflow. + +July 27, 2021: + As per IEEE Std 1003.1-2008, -F "str" is now consistent with + -v FS="str" when str is null. Thanks to Warner Losh. + +July 24, 2021: + Fix readrec's definition of a record. This fixes an issue + with NetBSD's RS regular expression support that can cause + an infinite read loop. Thanks to Miguel Pineiro Jr. + + Fix regular expression RS ^-anchoring. RS ^-anchoring needs to + know if it is reading the first record of a file. This change + restores a missing line that was overlooked when porting NetBSD's + RS regex functionality. Thanks to Miguel Pineiro Jr. + + Fix size computation in replace_repeat() for special case + REPEAT_WITH_Q. Thanks to Todd C. Miller. + February 15, 2021: Small fix so that awk will compile again with g++. Thanks to Arnold Robbins. @@ -5,11 +5,11 @@ third_party { type: GIT value: "https://github.com/onetrueawk/awk.git" } - version: "c0f4e97e4561ff42544e92512bbaf3d7d1f6a671" + version: "075624a72ab15649f255a3a1dabfd7cb7766a7d7" license_type: NOTICE last_upgrade_date { - year: 2021 - month: 4 - day: 1 + year: 2022 + month: 3 + day: 7 } } @@ -35,7 +35,7 @@ in `FIXES`. If you distribute this code further, please please please distribute `FIXES` with it. If you find errors, please report them -to bwk@cs.princeton.edu. +to the current maintainer, ozan.yigit@gmail.com. Please _also_ open an issue in the GitHub issue tracker, to make it easy to track issues. Thanks. @@ -90,7 +90,7 @@ move this to some place like `/usr/bin/awk`. If your system does not have `yacc` or `bison` (the GNU equivalent), you need to install one of them first. -NOTE: This version uses ANSI C (C 99), as you should also. We have +NOTE: This version uses ISO/IEC C99, as you should also. We have compiled this without any changes using `gcc -Wall` and/or local C compilers on a variety of systems, but new systems or compilers may raise some new complaint; reports of difficulties are @@ -107,13 +107,18 @@ astonishly slow. If `awk` seems slow, you might try fixing that. More generally, turning on optimization can significantly improve `awk`'s speed, perhaps by 1/3 for highest levels. +## A Note About Releases + +We don't usually do releases. + ## A Note About Maintenance -NOTICE! Maintenance of this program is on a ``best effort'' +NOTICE! Maintenance of this program is on a ''best effort'' basis. We try to get to issues and pull requests as quickly as we can. Unfortunately, however, keeping this program going is not at the top of our priority list. #### Last Updated -Fri Dec 25 16:53:34 EST 2020 +Sun 23 Jan 2022 03:48:01 PM EST + @@ -935,7 +935,7 @@ replace_repeat(const uschar *reptok, int reptoklen, const uschar *atom, if (special_case == REPEAT_PLUS_APPENDED) { size++; /* for the final + */ } else if (special_case == REPEAT_WITH_Q) { - size += init_q + (atomlen+1)* n_q_reps; + size += init_q + (atomlen+1)* (n_q_reps-init_q); } else if (special_case == REPEAT_ZERO) { size += 2; /* just a null ERE: () */ } @@ -964,11 +964,8 @@ replace_repeat(const uschar *reptok, int reptoklen, const uschar *atom, } } memcpy(&buf[j], reptok+reptoklen, suffix_length); - if (special_case == REPEAT_ZERO) { - buf[j+suffix_length] = '\0'; - } else { - buf[size] = '\0'; - } + j += suffix_length; + buf[j] = '\0'; /* free old basestr */ if (firstbasestr != basestr) { if (basestr) @@ -1104,7 +1101,7 @@ rescan: * program to track each string's length. */ for (i = 1; i <= UCHAR_MAX; i++) { - if (!adjbuf((char **) &buf, &bufsz, bp-buf+1, 100, (char **) &bp, "relex2")) + if (!adjbuf((char **) &buf, &bufsz, bp-buf+2, 100, (char **) &bp, "relex2")) FATAL("out of space for reg expr %.10s...", lastre); if (cc->cc_func(i)) { /* escape backslash */ diff --git a/bugs-fixed/getline-corruption.awk b/bugs-fixed/getline-corruption.awk new file mode 100644 index 0000000..461e551 --- /dev/null +++ b/bugs-fixed/getline-corruption.awk @@ -0,0 +1,5 @@ +BEGIN { + getline l + getline l + print (s=substr(l,1,10)) " len=" length(s) +} diff --git a/bugs-fixed/getline-corruption.in b/bugs-fixed/getline-corruption.in new file mode 100644 index 0000000..7898192 --- /dev/null +++ b/bugs-fixed/getline-corruption.in @@ -0,0 +1 @@ +a diff --git a/bugs-fixed/getline-corruption.ok b/bugs-fixed/getline-corruption.ok new file mode 100644 index 0000000..3efb545 --- /dev/null +++ b/bugs-fixed/getline-corruption.ok @@ -0,0 +1 @@ +a len=1 @@ -176,6 +176,7 @@ int getrec(char **pbuf, int *pbufsize, bool isrecord) /* get next input record * infile = stdin; else if ((infile = fopen(file, "r")) == NULL) FATAL("can't open file %s", file); + innew = true; setfval(fnrloc, 0.0); } c = readrec(&buf, &bufsize, infile, innew); @@ -241,6 +242,7 @@ int readrec(char **pbuf, int *pbufsize, FILE *inf, bool newflag) /* read one rec } if (found) setptr(patbeg, '\0'); + isrec = (found == 0 && *buf == '\0') ? false : true; } else { if ((sep = *rs) == 0) { sep = '\n'; @@ -270,10 +272,10 @@ int readrec(char **pbuf, int *pbufsize, FILE *inf, bool newflag) /* read one rec if (!adjbuf(&buf, &bufsize, 1+rr-buf, recsize, &rr, "readrec 3")) FATAL("input record `%.30s...' too long", buf); *rr = 0; + isrec = (c == EOF && rr == buf) ? false : true; } *pbuf = buf; *pbufsize = bufsize; - isrec = *buf || !feof(inf); DPRINTF("readrec saw <%s>, returns %d\n", buf, isrec); return isrec; } @@ -22,7 +22,7 @@ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ****************************************************************/ -const char *version = "version 20210215"; +const char *version = "version 20211208"; #define DEBUG #include <stdio.h> @@ -91,9 +91,7 @@ setfs(char *p) /* wart: t=>\t */ if (p[0] == 't' && p[1] == '\0') return "\t"; - else if (p[0] != '\0') - return p; - return NULL; + return p; } static char * @@ -169,8 +167,6 @@ int main(int argc, char *argv[]) break; case 'F': /* set field separator */ fs = setfs(getarg(&argc, &argv, "no field separator")); - if (fs == NULL) - WARNING("field separator FS is empty"); break; case 'v': /* -v a=1 to be done NOW. one -v for each */ vn = getarg(&argc, &argv, "no variable name"); @@ -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); @@ -1858,8 +1860,8 @@ const char *filename(FILE *fp) return "???"; } - Cell *closefile(Node **a, int n) - { +Cell *closefile(Node **a, int n) +{ Cell *x; size_t i; bool stat; @@ -1870,8 +1872,15 @@ const char *filename(FILE *fp) for (i = 0; i < nfiles; i++) { if (!files[i].fname || strcmp(x->sval, files[i].fname) != 0) continue; - if (ferror(files[i].fp)) - FATAL("i/o error occurred on %s", files[i].fname); + if (files[i].mode == GT || files[i].mode == '|') + fflush(files[i].fp); + if (ferror(files[i].fp)) { + if ((files[i].mode == GT && files[i].fp != stderr) + || files[i].mode == '|') + FATAL("write error on %s", files[i].fname); + else + WARNING("i/o error occurred on %s", files[i].fname); + } if (files[i].fp == stdin || files[i].fp == stdout || files[i].fp == stderr) stat = freopen("/dev/null", "r+", files[i].fp) == NULL; @@ -1880,7 +1889,7 @@ const char *filename(FILE *fp) else stat = fclose(files[i].fp) == EOF; if (stat) - FATAL("i/o error occurred closing %s", files[i].fname); + WARNING("i/o error occurred closing %s", files[i].fname); if (i > 2) /* don't do /dev/std... */ xfree(files[i].fname); files[i].fname = NULL; /* watch out for ref thru this */ @@ -1891,7 +1900,7 @@ const char *filename(FILE *fp) x = gettemp(); setfval(x, (Awkfloat) (stat ? -1 : 0)); return(x); - } +} void closeall(void) { @@ -1901,18 +1910,24 @@ void closeall(void) for (i = 0; i < nfiles; i++) { if (! files[i].fp) continue; - if (ferror(files[i].fp)) - FATAL( "i/o error occurred on %s", files[i].fname ); - if (files[i].fp == stdin) + if (files[i].mode == GT || files[i].mode == '|') + fflush(files[i].fp); + if (ferror(files[i].fp)) { + if ((files[i].mode == GT && files[i].fp != stderr) + || files[i].mode == '|') + FATAL("write error on %s", files[i].fname); + else + WARNING("i/o error occurred on %s", files[i].fname); + } + if (files[i].fp == stdin || files[i].fp == stdout || + files[i].fp == stderr) continue; if (files[i].mode == '|' || files[i].mode == LE) stat = pclose(files[i].fp) == -1; - else if (files[i].fp == stdout || files[i].fp == stderr) - stat = fflush(files[i].fp) == EOF; else stat = fclose(files[i].fp) == EOF; if (stat) - FATAL( "i/o error occurred while closing %s", files[i].fname ); + WARNING("i/o error occurred while closing %s", files[i].fname); } } diff --git a/testdir/T.misc b/testdir/T.misc index dff57db..ad34ab8 100755 --- a/testdir/T.misc +++ b/testdir/T.misc @@ -186,6 +186,13 @@ BEGIN { RS = "" }' >foo1 $awk 'END {print NR}' foo1 | grep 4 >/dev/null || echo 'BAD: T.misc abcdef fails' +# Test for RS regex matching an empty record at EOF +echo a | $awk 1 RS='a\n' > foo1 +cat << \EOF > foo2 + +EOF +diff foo1 foo2 || echo 'BAD: T.misc RS regex matching an empty record at EOF fails' + # Test for RS regex being reapplied echo aaa1a2a | $awk 1 RS='^a' >foo1 cat << \EOF > foo2 @@ -195,6 +202,24 @@ aa1a2a EOF diff foo1 foo2 || echo 'BAD: T.misc ^regex reapplied fails' +# ^-anchored RS matching should be active at the start of each input file +tee foo1 foo2 >foo3 << \EOF +aaa +EOF +$awk 1 RS='^a' foo1 foo2 foo3 >foo4 +cat << \EOF > foo5 + +aa + + +aa + + +aa + +EOF +diff foo4 foo5 || echo 'BAD: T.misc ^RS matches the start of every input file fails' + # The following should not produce a warning about changing a constant # nor about a curdled tempcell list $awk 'function f(x) { x = 2 } |