From 932bfb38a146388be8639db9af49134640b7e486 Mon Sep 17 00:00:00 2001 From: vms Date: Mon, 12 Apr 2021 14:45:55 +0300 Subject: [PATCH] final preparation --- sqlite3.wit | 2 +- src/legacy.c | 2 +- src/main.c | 5 ++--- src/sqliteInt.h | 2 ++ src/wrapper.c | 11 +++++++++++ 5 files changed, 17 insertions(+), 5 deletions(-) diff --git a/sqlite3.wit b/sqlite3.wit index 3425838..b726881 100644 --- a/sqlite3.wit +++ b/sqlite3.wit @@ -1,4 +1,4 @@ -(@interface it_version "0.19.0" +(@interface it_version "0.19.0") ;; Types (@interface type (func diff --git a/src/legacy.c b/src/legacy.c index a4437cb..b931790 100644 --- a/src/legacy.c +++ b/src/legacy.c @@ -35,7 +35,7 @@ void sqlite3_exec_( sqlite3_callback xCallback, /* Invoke this callback routine */ void *pArg /* First argument to xCallback() */ ) __EXPORT_NAME(sqlite3_exec) { - zSql[zSql_len] = '\x00'; + zSql = handle_input_string(zSql, zSql_len); char *pzErrMsg = 0; const int ret_code = sqlite3_exec(db, zSql, xCallback, pArg, &pzErrMsg); diff --git a/src/main.c b/src/main.c index 18e568a..aed5dc8 100644 --- a/src/main.c +++ b/src/main.c @@ -3443,9 +3443,8 @@ void sqlite3_open_v2_( char *zVfs, /* Name of VFS module to use */ int zVfs_len ) __EXPORT_NAME(sqlite3_open_v2) { - // this strings were allocated by the allocate function that allocates 1 byte more for null character - filename[filename_len] = '\x00'; - zVfs[zVfs_len] = '\x00'; + filename = handle_input_string(filename, filename_len); + zVfs = handle_input_string(zVfs, zVfs_len); sqlite3 *ppDb; diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 07d7b43..64261f9 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -4913,6 +4913,8 @@ void add_object_to_release(void *object); void set_result_ptr(void *ptr); void set_result_size(int size); + +char *handle_input_string(char *str, int len); #endif #endif /* SQLITEINT_H */ diff --git a/src/wrapper.c b/src/wrapper.c index 0a2a787..9ff30d8 100644 --- a/src/wrapper.c +++ b/src/wrapper.c @@ -43,6 +43,17 @@ void *get_result_ptr() { return RESULT_PTR; } +char *handle_input_string(char *str, int len) { + if (len == 0) { + free(str); + return NULL; + } + + // this strings are supposed to be allocated by the allocate function, which allocates 1 byte more for null character + str[len] = '\x00'; + return str; +} + int main() { // the main purpose of this empty main is to initialize WASI subsystem return 0;