Fixes a use-after-free bug with ARGV for "delete ARGV".
This file lists all bug fixes, changes, etc., made since the
second edition of the AWK book was published in September 2023.
+May 4, 2024
+ Fixed a use-after-free bug with ARGV for "delete ARGV".
+ Also ENVtab is no longer global. Thanks to Benjamin Sturz
+ for spotting the ARGV issue and Todd Miller for the fix.
+
+May 3, 2024:
+ Remove warnings when compiling with g++. Thanks to Arnold Robbins.
+
Apr 22, 2024:
- fixed regex engine gototab reallocation issue that was
- introduced during the Nov 24 rewrite. Thanks to Arnold Robbins.
+ Fixed regex engine gototab reallocation issue that was
+ Introduced during the Nov 24 rewrite. Thanks to Arnold Robbins.
Fixed a scan bug in split in the case the separator is a single
- character. thanks to Oguz Ismail for spotting the issue.
+ character. Thanks to Oguz Ismail for spotting the issue.
Mar 10, 2024:
- fixed use-after-free bug in fnematch due to adjbuf invalidating
- the pointers to buf. thanks to github user caffe3 for spotting
+ Fixed use-after-free bug in fnematch due to adjbuf invalidating
+ the pointers to buf. Thanks to github user caffe3 for spotting
the issue and providing a fix, and to Miguel Pineiro Jr.
for the alternative fix.
MAX_UTF_BYTES in fnematch has been replaced with awk_mb_cur_max.
-/* $OpenBSD: b.c,v 1.51 2024/04/25 18:33:53 millert Exp $ */
+/* $OpenBSD: b.c,v 1.52 2024/05/04 22:59:21 millert Exp $ */
/****************************************************************
Copyright (C) Lucent Technologies 1997
All Rights Reserved
f->gototab[state].entries[0].state = val;
f->gototab[state].inuse++;
return val;
- } else if (ch > f->gototab[state].entries[f->gototab[state].inuse-1].ch) {
+ } else if ((unsigned)ch > f->gototab[state].entries[f->gototab[state].inuse-1].ch) {
// not seen yet, insert and return
gtt *tab = & f->gototab[state];
if (tab->inuse + 1 >= tab->allocated)
* Call u8_rune with at least awk_mb_cur_max ahead in
* the buffer until EOF interferes.
*/
- if (k - j < awk_mb_cur_max) {
+ if (k - j < (int)awk_mb_cur_max) {
if (k + awk_mb_cur_max > buf + bufsize) {
char *obuf = buf;
adjbuf(&buf, &bufsize,
-/* $OpenBSD: lib.c,v 1.55 2023/11/28 20:54:38 millert Exp $ */
+/* $OpenBSD: lib.c,v 1.56 2024/05/04 22:59:21 millert Exp $ */
/****************************************************************
Copyright (C) Lucent Technologies 1997
All Rights Reserved
{
const char *os = s;
- if (!isalpha((uschar) *s) && *s != '_')
+ if (!isalpha((uschar)*s) && *s != '_')
return 0;
for ( ; *s; s++)
- if (!(isalnum((uschar) *s) || *s == '_'))
+ if (!(isalnum((uschar)*s) || *s == '_'))
break;
return *s == '=' && s > os;
}
-/* $OpenBSD: main.c,v 1.69 2024/04/25 18:33:53 millert Exp $ */
+/* $OpenBSD: main.c,v 1.70 2024/05/04 22:59:21 millert Exp $ */
/****************************************************************
Copyright (C) Lucent Technologies 1997
All Rights Reserved
THIS SOFTWARE.
****************************************************************/
-const char *version = "version 20240422";
+const char *version = "version 20240504";
#define DEBUG
#include <stdio.h>
{
extern Node *curnode;
#ifdef SA_SIGINFO
- static const char *emsg[] = {
- [0] = "Unknown error",
- [FPE_INTDIV] = "Integer divide by zero",
- [FPE_INTOVF] = "Integer overflow",
- [FPE_FLTDIV] = "Floating point divide by zero",
- [FPE_FLTOVF] = "Floating point overflow",
- [FPE_FLTUND] = "Floating point underflow",
- [FPE_FLTRES] = "Floating point inexact result",
- [FPE_FLTINV] = "Invalid Floating point operation",
- [FPE_FLTSUB] = "Subscript out of range",
- };
+ const char *mesg = NULL;
+
+ switch (si->si_code) {
+ case FPE_INTDIV:
+ mesg = "Integer divide by zero";
+ break;
+ case FPE_INTOVF:
+ mesg = "Integer overflow";
+ break;
+ case FPE_FLTDIV:
+ mesg = "Floating point divide by zero";
+ break;
+ case FPE_FLTOVF:
+ mesg = "Floating point overflow";
+ break;
+ case FPE_FLTUND:
+ mesg = "Floating point underflow";
+ break;
+ case FPE_FLTRES:
+ mesg = "Floating point inexact result";
+ break;
+ case FPE_FLTINV:
+ mesg = "Invalid Floating point operation";
+ break;
+ case FPE_FLTSUB:
+ mesg = "Subscript out of range";
+ break;
+ case 0:
+ default:
+ mesg = "Unknown error";
+ break;
+ }
#endif
dprintf(STDERR_FILENO, "floating point exception%s%s\n",
#ifdef SA_SIGINFO
- ": ", (size_t)si->si_code < sizeof(emsg) / sizeof(emsg[0]) &&
- emsg[si->si_code] ? emsg[si->si_code] : emsg[0]
+ ": ", mesg
#else
"", ""
#endif
-/* $OpenBSD: run.c,v 1.85 2024/04/25 18:33:53 millert Exp $ */
+/* $OpenBSD: run.c,v 1.86 2024/05/04 22:59:21 millert Exp $ */
/****************************************************************
Copyright (C) Lucent Technologies 1997
All Rights Reserved
return charnum;
}
-/* runetochar() adapted from rune.c in the Plan 9 distributione */
+/* runetochar() adapted from rune.c in the Plan 9 distribution */
enum
{
Cell *bltin(Node **a, int n) /* builtin functions. a[0] is type, a[1] is arg list */
{
Cell *x, *y;
- Awkfloat u;
+ Awkfloat u = 0;
int t, sz;
Awkfloat tmp;
char *buf, *fmt;
const char *start;
const char *noempty = NULL; /* empty match disallowed here */
size_t m = 0; /* match count */
- size_t whichm; /* which match to select, 0 = global */
+ size_t whichm = 0; /* which match to select, 0 = global */
int mtype; /* match type */
if (a[0] == NULL) { /* 0 => a[1] is already-compiled regexpr */
-/* $OpenBSD: tran.c,v 1.38 2023/10/30 17:52:54 millert Exp $ */
+/* $OpenBSD: tran.c,v 1.39 2024/05/04 22:59:21 millert Exp $ */
/****************************************************************
Copyright (C) Lucent Technologies 1997
All Rights Reserved
Cell *ofsloc; /* OFS */
Cell *orsloc; /* ORS */
Cell *rsloc; /* RS */
-Array *ARGVtab; /* symbol table containing ARGV[...] */
-Array *ENVtab; /* symbol table containing ENVIRON[...] */
+Cell *ARGVcell; /* cell with symbol table containing ARGV[...] */
Cell *rstartloc; /* RSTART */
Cell *rlengthloc; /* RLENGTH */
Cell *subseploc; /* SUBSEP */
void arginit(int ac, char **av) /* set up ARGV and ARGC */
{
+ Array *ap;
Cell *cp;
int i;
char temp[50];
ARGC = &setsymtab("ARGC", "", (Awkfloat) ac, NUM, symtab)->fval;
cp = setsymtab("ARGV", "", 0.0, ARR, symtab);
- ARGVtab = makesymtab(NSYMTAB); /* could be (int) ARGC as well */
+ ap = makesymtab(NSYMTAB); /* could be (int) ARGC as well */
free(cp->sval);
- cp->sval = (char *) ARGVtab;
+ cp->sval = (char *) ap;
for (i = 0; i < ac; i++) {
double result;
snprintf(temp, sizeof(temp), "%d", i);
if (is_number(*av, & result))
- setsymtab(temp, *av, result, STR|NUM, ARGVtab);
+ setsymtab(temp, *av, result, STR|NUM, ap);
else
- setsymtab(temp, *av, 0.0, STR, ARGVtab);
+ setsymtab(temp, *av, 0.0, STR, ap);
av++;
}
+ ARGVcell = cp;
}
void envinit(char **envp) /* set up ENVIRON variable */
{
+ Array *ap;
Cell *cp;
char *p;
cp = setsymtab("ENVIRON", "", 0.0, ARR, symtab);
- ENVtab = makesymtab(NSYMTAB);
+ ap = makesymtab(NSYMTAB);
free(cp->sval);
- cp->sval = (char *) ENVtab;
+ cp->sval = (char *) ap;
for ( ; *envp; envp++) {
double result;
continue;
*p++ = 0; /* split into two strings at = */
if (is_number(p, & result))
- setsymtab(*envp, p, result, STR|NUM, ENVtab);
+ setsymtab(*envp, p, result, STR|NUM, ap);
else
- setsymtab(*envp, p, 0.0, STR, ENVtab);
+ setsymtab(*envp, p, 0.0, STR, ap);
p[-1] = '='; /* restore in case env is passed down to a shell */
}
}