From ac850f407d3a70ce0eaa0fcf6187be83e03d2f1c Mon Sep 17 00:00:00 2001 From: Sandu Liviu Catalin Date: Sun, 10 Jul 2016 17:34:12 +0300 Subject: [PATCH] Improve the handle validation in pure squirrel methods of the Connection class from the SQLite module. --- modules/sqlite/Connection.cpp | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/modules/sqlite/Connection.cpp b/modules/sqlite/Connection.cpp index 08f2186a..ca07b9cc 100644 --- a/modules/sqlite/Connection.cpp +++ b/modules/sqlite/Connection.cpp @@ -370,10 +370,15 @@ SQInteger Connection::ExecF(HSQUIRRELVM vm) { return sq_throwerror(vm, "Invalid SQLite connection instance"); } - // Do we have a valid connection identifier? - else if (!(conn->m_Handle)) + // Validate the connection info + try { - return sq_throwerror(vm, "Invalid SQLite connection reference"); + SQMOD_VALIDATE_CREATED(*conn); + } + catch (const Sqrat::Exception & e) + { + // Propagate the error + return sq_throwerror(vm, e.what()); } // Attempt to retrieve the value from the stack as a string StackStrF val(vm, 2); @@ -421,10 +426,15 @@ SQInteger Connection::QueueF(HSQUIRRELVM vm) { return sq_throwerror(vm, "Invalid SQLite connection instance"); } - // Do we have a valid connection identifier? - else if (!(conn->m_Handle)) + // Validate the connection info + try { - return sq_throwerror(vm, "Invalid SQLite connection reference"); + SQMOD_VALIDATE_CREATED(*conn); + } + catch (const Sqrat::Exception & e) + { + // Propagate the error + return sq_throwerror(vm, e.what()); } // Attempt to retrieve the value from the stack as a string StackStrF val(vm, 2); @@ -465,10 +475,15 @@ SQInteger Connection::QueryF(HSQUIRRELVM vm) { return sq_throwerror(vm, "Invalid SQLite connection instance"); } - // Do we have a valid connection identifier? - else if (!(conn->m_Handle)) + // Validate the connection info + try { - return sq_throwerror(vm, "Invalid SQLite connection reference"); + SQMOD_VALIDATE_CREATED(*conn); + } + catch (const Sqrat::Exception & e) + { + // Propagate the error + return sq_throwerror(vm, e.what()); } // Attempt to retrieve the value from the stack as a string StackStrF val(vm, 2);