Author: arichardson
Date: Mon Sep 21 19:03:07 2020
New Revision: 365968
URL: https://svnweb.freebsd.org/changeset/base/365968

Log:
  awk: Fix subobject out-of-bounds access
  
  When matching a regex with ^, it would attempt to access
  gototab[NSTATES][NCHARS+2], and therefore access the state for the \002
  character instead. This change is required to run awk under CHERI (with
  sub-object bounds) and when running with UBSan instrumentation.
  
  This was committed upstream as 
https://github.com/onetrueawk/awk/commit/cbf924342b63a095a4c6842280c3085b1b63ae45
  
  Found by:     CHERI (with subobject bounds enabled)
  Obtained from:        CheriBSD
  Reviewed By:  imp
  Differential Revision: https://reviews.freebsd.org/D26509

Modified:
  head/contrib/one-true-awk/awk.h
  head/contrib/one-true-awk/b.c

Modified: head/contrib/one-true-awk/awk.h
==============================================================================
--- head/contrib/one-true-awk/awk.h     Mon Sep 21 18:34:13 2020        
(r365967)
+++ head/contrib/one-true-awk/awk.h     Mon Sep 21 19:03:07 2020        
(r365968)
@@ -218,6 +218,8 @@ extern      int     pairstack[], paircnt;
 #define NCHARS (256+3)         /* 256 handles 8-bit chars; 128 does 7-bit */
                                /* watch out in match(), etc. */
 #define NSTATES        32
+#define        HAT     (NCHARS+2)      /* matches ^ in regular expr */
+                               /* NCHARS is 2**n */
 
 typedef struct rrow {
        long    ltype;  /* long avoids pointer warnings on 64-bit */
@@ -230,7 +232,7 @@ typedef struct rrow {
 } rrow;
 
 typedef struct fa {
-       uschar  gototab[NSTATES][NCHARS];
+       uschar  gototab[NSTATES][HAT + 1];
        uschar  out[NSTATES];
        uschar  *restr;
        int     *posns[NSTATES];

Modified: head/contrib/one-true-awk/b.c
==============================================================================
--- head/contrib/one-true-awk/b.c       Mon Sep 21 18:34:13 2020        
(r365967)
+++ head/contrib/one-true-awk/b.c       Mon Sep 21 19:03:07 2020        
(r365968)
@@ -37,8 +37,6 @@ __FBSDID("$FreeBSD$");
 #include "awk.h"
 #include "ytab.h"
 
-#define        HAT     (NCHARS+2)      /* matches ^ in regular expr */
-                               /* NCHARS is 2**n */
 #define MAXLIN 22
 
 #define type(v)                (v)->nobj       /* badly overloaded here */
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to