From 2084a9dcdb6fa7cd335dca7fef7328ebee65a5d1 Mon Sep 17 00:00:00 2001 From: Dan Kennedy Date: Fri, 25 Jan 2019 17:26:59 +0000 Subject: [PATCH 0842/1009] Fix a segfault that could follow an OOM when querying a table that has one or more columns with default values "true" or "false". https://github.com/mackyle/sqlite/commit/2084a9dcdb6fa7cd335dca7fef7328ebee65a5d1 --- src/vdbemem.c | 8 +++++--- test/insertfault.test | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 test/insertfault.test diff --git a/src/vdbemem.c b/src/vdbemem.c index 8493df7..8d9e44b 100644 --- a/src/vdbemem.c +++ b/src/vdbemem.c @@ -1530,9 +1530,11 @@ static int valueFromExpr( } #endif else if( op==TK_TRUEFALSE ){ - pVal = valueNew(db, pCtx); - pVal->flags = MEM_Int; - pVal->u.i = pExpr->u.zToken[4]==0; + pVal = valueNew(db, pCtx); + if( pVal ){ + pVal->flags = MEM_Int; + pVal->u.i = pExpr->u.zToken[4]==0; + } } *ppVal = pVal; diff --git a/test/insertfault.test b/test/insertfault.test new file mode 100644 index 0000000..53849a1 --- /dev/null +++ b/test/insertfault.test @@ -0,0 +1,36 @@ +# 2019-01-26 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# Test cases for INSERT + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix insertfault + +do_execsql_test 1.0 { + CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c, d DEFAULT true); + INSERT INTO t1 DEFAULT VALUES; + SELECT * FROM t1; +} {1 {} {} 1} +faultsim_save_and_close + +breakpoint +do_faultsim_test 1 -faults oom* -prep { + faultsim_restore_and_reopen + db eval { SELECT * FROM sqlite_master } +} -body { + execsql { SELECT * FROM t1 } +} -test { + faultsim_test_result {0 {1 {} {} 1}} +} + + +finish_test -- 1.8.3.1