From 9627c47a03bfa5aa59fa59b1ef37d8fa524fd9f2 Mon Sep 17 00:00:00 2001
From: Dan Kennedy <danielk1977@gmail.com>
Date: Sat, 30 Jun 2018 20:00:35 +0000
Subject: [PATCH 0121/1009] Fix a minor problem in the code for determining
 whether or not an SQL statement is SQLITE_TOOBIG.

From https://github.com/mackyle/sqlite/commit/9627c47a03bfa5aa59fa59b1ef37d8fa524fd9f2

---
 src/alter.c    | 4 ++--
 src/tokenize.c | 7 ++++++-
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/src/alter.c b/src/alter.c
index f338e8b..2d7a5d6 100644
--- a/src/alter.c
+++ b/src/alter.c
@@ -74,7 +74,7 @@ static void renameTableFunc(
         zCsr += len;
         len = sqlite3GetToken(zCsr, &token);
       } while( token==TK_SPACE );
-      assert( len>0 );
+      assert( len>0 || !*zCsr );
     } while( token!=TK_LP && token!=TK_USING );
 
     zRet = sqlite3MPrintf(db, "%.*s\"%w\"%s", (int)(((u8*)tname.z) - zSql),
@@ -198,7 +198,7 @@ static void renameTriggerFunc(
         zCsr += len;
         len = sqlite3GetToken(zCsr, &token);
       }while( token==TK_SPACE );
-      assert( len>0 );
+      assert( len>0 || !*zCsr );
 
       /* Variable 'dist' stores the number of tokens read since the most
       ** recent TK_DOT or TK_ON. This means that when a WHEN, FOR or BEGIN 
diff --git a/src/tokenize.c b/src/tokenize.c
index 15678ed..fc5989c 100644
--- a/src/tokenize.c
+++ b/src/tokenize.c
@@ -54,11 +54,12 @@
 #define CC_TILDA     25    /* '~' */
 #define CC_DOT       26    /* '.' */
 #define CC_ILLEGAL   27    /* Illegal character */
+#define CC_NUL       28    /* 0x00 */
 
 static const unsigned char aiClass[] = {
 #ifdef SQLITE_ASCII
 /*         x0  x1  x2  x3  x4  x5  x6  x7  x8  x9  xa  xb  xc  xd  xe  xf */
-/* 0x */   27, 27, 27, 27, 27, 27, 27, 27, 27,  7,  7, 27,  7,  7, 27, 27,
+/* 0x */   28, 27, 27, 27, 27, 27, 27, 27, 27,  7,  7, 27,  7,  7, 27, 27,
 /* 1x */   27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
 /* 2x */    7, 15,  8,  5,  4, 22, 24,  8, 17, 18, 21, 20, 23, 11, 26, 16,
 /* 3x */    3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  5, 19, 12, 14, 13,  6,
@@ -532,6 +533,10 @@ int sqlite3GetToken(const unsigned char *z, int *tokenType){
       i = 1;
       break;
     }
+    case CC_NUL: {
+      *tokenType = TK_ILLEGAL;
+      return 0;
+    }
     default: {
       *tokenType = TK_ILLEGAL;
       return 1;
-- 
1.8.3.1

