]> granicus.if.org Git - python/commitdiff
Issue #6697: Check that _PyUnicode_AsString() result is not NULL in _sqlite
authorVictor Stinner <victor.stinner@haypocalc.com>
Wed, 19 May 2010 01:27:23 +0000 (01:27 +0000)
committerVictor Stinner <victor.stinner@haypocalc.com>
Wed, 19 May 2010 01:27:23 +0000 (01:27 +0000)
Strip also some trailing spaces

Modules/_sqlite/connection.c
Modules/_sqlite/cursor.c
Modules/_sqlite/row.c
Modules/_sqlite/statement.c

index 88d6b40e3edd74d2ff45f5f46d96431bb8b2b3ee..184bdeef93aac68e9be99eae2d37f8b8b209b422 100644 (file)
@@ -3,7 +3,7 @@
  * Copyright (C) 2004-2010 Gerhard Häring <gh@ghaering.de>
  *
  * This file is part of pysqlite.
- * 
+ *
  * This software is provided 'as-is', without any express or implied
  * warranty.  In no event will the authors be held liable for any damages
  * arising from the use of this software.
@@ -495,7 +495,9 @@ void _pysqlite_set_result(sqlite3_context* context, PyObject* py_val)
     } else if (PyFloat_Check(py_val)) {
         sqlite3_result_double(context, PyFloat_AsDouble(py_val));
     } else if (PyUnicode_Check(py_val)) {
-        sqlite3_result_text(context, _PyUnicode_AsString(py_val), -1, SQLITE_TRANSIENT);
+        char *str = _PyUnicode_AsString(py_val);
+        if (str != NULL)
+            sqlite3_result_text(context, str, -1, SQLITE_TRANSIENT);
     } else if (PyObject_CheckBuffer(py_val)) {
         if (PyObject_AsCharBuffer(py_val, &buffer, &buflen) != 0) {
             PyErr_SetString(PyExc_ValueError, "could not convert BLOB to buffer");
@@ -892,7 +894,7 @@ static int _progress_handler(void* user_arg)
         }
 
         /* abort query if error occurred */
-        rc = 1; 
+        rc = 1;
     } else {
         rc = (int)PyObject_IsTrue(ret);
         Py_DECREF(ret);
index 543111261d9c9976216898cbd261716ae6944905..97908a3093961d6f4cd22862b7f4445901f698d0 100644 (file)
@@ -368,7 +368,7 @@ PyObject* _pysqlite_fetch_one_row(pysqlite_Cursor* self)
                         }
                         PyOS_snprintf(buf, sizeof(buf) - 1, "Could not decode to UTF-8 column '%s' with text '%s'",
                                      colname , val_str);
-                        buf_bytes = PyByteArray_FromStringAndSize(buf, strlen(buf)); 
+                        buf_bytes = PyByteArray_FromStringAndSize(buf, strlen(buf));
                         if (!buf_bytes) {
                             PyErr_SetString(pysqlite_OperationalError, "Could not decode to UTF-8");
                         } else {
@@ -533,7 +533,7 @@ PyObject* _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject*
     }
 
     operation_cstr = _PyUnicode_AsStringAndSize(operation, &operation_len);
-    if (operation == NULL)
+    if (operation_cstr == NULL)
         goto error;
 
     /* reset description and rowcount */
index 0aa78f4b5dcfe56cb53e68bd658fe818e9a2b5e6..54a89e11d98474f460dea7633d834d33a879f91e 100644 (file)
@@ -83,6 +83,8 @@ PyObject* pysqlite_row_subscript(pysqlite_Row* self, PyObject* idx)
         return item;
     } else if (PyUnicode_Check(idx)) {
         key = _PyUnicode_AsString(idx);
+        if (key == NULL)
+            return NULL;
 
         nitems = PyTuple_Size(self->description);
 
index 48e039bd4054e2e5bb87c1fcb4a7085ae977713b..c04029003cb629ebd0dfd38eb7be81baeb13e381 100644 (file)
@@ -130,7 +130,10 @@ int pysqlite_statement_bind_parameter(pysqlite_Statement* self, int pos, PyObjec
             break;
         case TYPE_UNICODE:
             string = _PyUnicode_AsString(parameter);
-            rc = sqlite3_bind_text(self->st, pos, string, -1, SQLITE_TRANSIENT);
+            if (string != NULL)
+                rc = sqlite3_bind_text(self->st, pos, string, -1, SQLITE_TRANSIENT);
+            else
+                rc = -1;
             break;
         case TYPE_BUFFER:
             if (PyObject_AsCharBuffer(parameter, &buffer, &buflen) == 0) {