[tarantool-patches] [PATCH 3/3] sql: report errors in EphemeralGetMaxId

AKhatskevich avkhatskevich at tarantool.org
Thu Mar 29 13:17:52 MSK 2018


In case of error in `tarantoolSqlite3EphemeralGetMaxId` it was creating
diag string and silently continue working. It was a huge luck that
non-valid output of the function did not lead to crashes.

After the fix, it was found that some opcodes in `select.c` were using
wrong registers. These were fixed too, but they still have bugs. For
more information see #3297.

Related to #3297
---
 src/box/sql.c        | 3 ++-
 src/box/sql/select.c | 6 +++---
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/src/box/sql.c b/src/box/sql.c
index 98bcd93ca..31ceacb53 100644
--- a/src/box/sql.c
+++ b/src/box/sql.c
@@ -1744,7 +1744,8 @@ int tarantoolSqlite3EphemeralGetMaxId(BtCursor *pCur, uint32_t fieldno,
 		*max_id = 0;
 		return SQLITE_OK;
 	}
-	tuple_field_u64(tuple, fieldno, max_id);
+	if (tuple_field_u64(tuple, fieldno, max_id) == -1)
+		return SQL_TARANTOOL_ERROR;
 
 	return SQLITE_OK;
 }
diff --git a/src/box/sql/select.c b/src/box/sql/select.c
index a76286f23..c91685f7f 100644
--- a/src/box/sql/select.c
+++ b/src/box/sql/select.c
@@ -1025,7 +1025,7 @@ selectInnerLoop(Parse * pParse,		/* The parser context */
 				/* Last column is required for ID. */
 				int regCopy = sqlite3GetTempRange(pParse, nResultCol + 1);
 				sqlite3VdbeAddOp3(v, OP_NextIdEphemeral, iParm,
-						  0, regCopy + nResultCol);
+						  nResultCol, regCopy + nResultCol);
 				/* Positioning ID column to be last in inserted tuple.
 				 * NextId -> regCopy + n + 1
 				 * Copy [regResult, regResult + n] -> [regCopy, regCopy + n]
@@ -1504,7 +1504,7 @@ generateSortTail(Parse * pParse,	/* Parsing context */
 	case SRT_Table:
 	case SRT_EphemTab: {
 			int regCopy = sqlite3GetTempRange(pParse,  nColumn);
-			sqlite3VdbeAddOp3(v, OP_NextIdEphemeral, iParm, 0, regTupleid);
+			sqlite3VdbeAddOp3(v, OP_NextIdEphemeral, iParm, nColumn, regTupleid);
 			sqlite3VdbeAddOp3(v, OP_Copy, regRow, regCopy, nSortData - 1);
 			sqlite3VdbeAddOp3(v, OP_MakeRecord, regCopy, nColumn + 1, regRow);
 			sqlite3VdbeAddOp2(v, OP_IdxInsert, iParm, regRow);
@@ -2957,7 +2957,7 @@ generateOutputSubroutine(Parse * pParse,	/* Parsing context */
 			int regRec = sqlite3GetTempReg(pParse);
 			int regCopy = sqlite3GetTempRange(pParse, pIn->nSdst + 1);
 			sqlite3VdbeAddOp3(v, OP_NextIdEphemeral, pDest->iSDParm,
-					  0, regCopy + pIn->nSdst);
+					  pIn->nSdst, regCopy + pIn->nSdst);
 			sqlite3VdbeAddOp3(v, OP_Copy, pIn->iSdst, regCopy,
 					  pIn->nSdst - 1);
 			sqlite3VdbeAddOp3(v, OP_MakeRecord, regCopy,
-- 
2.14.1





More information about the Tarantool-patches mailing list