Bug 745384 - Handle null parameters passed to sqlitebridge. r=gcp
☠☠ backed out by 972986c4f75e ☠ ☠
authorWes Johnston <wjohnston@mozilla.com>
Wed, 24 Oct 2012 10:53:14 -0700
changeset 111273 e28405983f87a25459ec3af29590bb096869796e
parent 111272 5e9f725c9eb5193c120c4a0c8f41f24350757e4e
child 111274 67db046bd148781238131d518f1008620677eb49
push idunknown
push userunknown
push dateunknown
reviewersgcp
bugs745384
milestone19.0a1
Bug 745384 - Handle null parameters passed to sqlitebridge. r=gcp
mozglue/android/SQLiteBridge.cpp
mozglue/android/SQLiteBridge.h
--- a/mozglue/android/SQLiteBridge.cpp
+++ b/mozglue/android/SQLiteBridge.cpp
@@ -21,16 +21,17 @@
 
 #define SQLITE_WRAPPER_INT(name) name ## _t f_ ## name;
 
 SQLITE_WRAPPER_INT(sqlite3_open)
 SQLITE_WRAPPER_INT(sqlite3_errmsg)
 SQLITE_WRAPPER_INT(sqlite3_prepare_v2)
 SQLITE_WRAPPER_INT(sqlite3_bind_parameter_count)
 SQLITE_WRAPPER_INT(sqlite3_bind_text)
+SQLITE_WRAPPER_INT(sqlite3_bind_null)
 SQLITE_WRAPPER_INT(sqlite3_step)
 SQLITE_WRAPPER_INT(sqlite3_column_count)
 SQLITE_WRAPPER_INT(sqlite3_finalize)
 SQLITE_WRAPPER_INT(sqlite3_close)
 SQLITE_WRAPPER_INT(sqlite3_column_name)
 SQLITE_WRAPPER_INT(sqlite3_column_type)
 SQLITE_WRAPPER_INT(sqlite3_column_blob)
 SQLITE_WRAPPER_INT(sqlite3_column_bytes)
@@ -247,16 +248,24 @@ sqliteInternalCall(JNIEnv* jenv,
         goto error_close;
     }
 
     if (jParams != NULL) {
         // Bind parameters, if any
         if (numPars > 0) {
             for (int i = 0; i < numPars; i++) {
                 jobject jObjectParam = jenv->GetObjectArrayElement(jParams, i);
+                if (jObjectParam == NULL) {
+                  rc = f_sqlite3_bind_null(ppStmt, i + 1);
+                  if (rc != SQLITE_OK) {
+                      asprintf(&errorMsg, "Error binding null query parameter");
+                      goto error_close;
+                  }
+                  continue;
+                }
                 // IsInstanceOf or isAssignableFrom? String is final, so IsInstanceOf
                 // should be OK.
                 jboolean isString = jenv->IsInstanceOf(jObjectParam, stringClass);
                 if (isString != JNI_TRUE) {
                     asprintf(&errorMsg, "Parameter is not of String type");
                     goto error_close;
                 }
                 jstring jStringParam = (jstring)jObjectParam;
--- a/mozglue/android/SQLiteBridge.h
+++ b/mozglue/android/SQLiteBridge.h
@@ -13,16 +13,17 @@ void setup_sqlite_functions(void *sqlite
 typedef return_type (*name ## _t)(args);  \
 extern name ## _t f_ ## name;
 
 SQLITE_WRAPPER(sqlite3_open, int, const char*, sqlite3**)
 SQLITE_WRAPPER(sqlite3_errmsg, const char*, sqlite3*)
 SQLITE_WRAPPER(sqlite3_prepare_v2, int, sqlite3*, const char*, int, sqlite3_stmt**, const char**)
 SQLITE_WRAPPER(sqlite3_bind_parameter_count, int, sqlite3_stmt*)
 SQLITE_WRAPPER(sqlite3_bind_text, int, sqlite3_stmt*, int, const char*, int, void(*)(void*))
+SQLITE_WRAPPER(sqlite3_bind_null, int, sqlite3_stmt*, int)
 SQLITE_WRAPPER(sqlite3_step, int, sqlite3_stmt*)
 SQLITE_WRAPPER(sqlite3_column_count, int, sqlite3_stmt*)
 SQLITE_WRAPPER(sqlite3_finalize, int, sqlite3_stmt*)
 SQLITE_WRAPPER(sqlite3_close, int, sqlite3*)
 SQLITE_WRAPPER(sqlite3_column_name, const char*, sqlite3_stmt*, int)
 SQLITE_WRAPPER(sqlite3_column_type, int, sqlite3_stmt*, int)
 SQLITE_WRAPPER(sqlite3_column_blob, const void*, sqlite3_stmt*, int)
 SQLITE_WRAPPER(sqlite3_column_bytes, int, sqlite3_stmt*, int)