From a8e88332a394f4a4c3e43b496738008fba39d39f Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 16 Jul 2012 19:03:40 +1000 Subject: pytdb: Check for errors parsing strings into TDB_DATA The call to PyStringAsString() can raise an exception, and we want to return that rather than following a NULL pointer later. Andrew Bartlett --- lib/tdb/pytdb.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'lib/tdb/pytdb.c') diff --git a/lib/tdb/pytdb.c b/lib/tdb/pytdb.c index 48927522f3..ca1c847fb5 100644 --- a/lib/tdb/pytdb.c +++ b/lib/tdb/pytdb.c @@ -189,6 +189,8 @@ static PyObject *obj_get(PyTdbObject *self, PyObject *args) return NULL; key = PyString_AsTDB_DATA(py_key); + if (!key.dptr) + return NULL; return PyString_FromTDB_DATA(tdb_fetch(self->ctx, key)); } @@ -202,7 +204,11 @@ static PyObject *obj_append(PyTdbObject *self, PyObject *args) return NULL; key = PyString_AsTDB_DATA(py_key); + if (!key.dptr) + return NULL; data = PyString_AsTDB_DATA(py_data); + if (!data.dptr) + return NULL; ret = tdb_append(self->ctx, key, data); PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx); @@ -222,6 +228,8 @@ static PyObject *obj_nextkey(PyTdbObject *self, PyObject *args) return NULL; key = PyString_AsTDB_DATA(py_key); + if (!key.dptr) + return NULL; return PyString_FromTDB_DATA(tdb_nextkey(self->ctx, key)); } @@ -235,6 +243,8 @@ static PyObject *obj_delete(PyTdbObject *self, PyObject *args) return NULL; key = PyString_AsTDB_DATA(py_key); + if (!key.dptr) + return NULL; ret = tdb_delete(self->ctx, key); PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx); Py_RETURN_NONE; @@ -249,6 +259,8 @@ static PyObject *obj_has_key(PyTdbObject *self, PyObject *args) return NULL; key = PyString_AsTDB_DATA(py_key); + if (!key.dptr) + return NULL; ret = tdb_exists(self->ctx, key); if (ret != TDB_ERR_NOEXIST) { PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx); @@ -268,7 +280,11 @@ static PyObject *obj_store(PyTdbObject *self, PyObject *args) return NULL; key = PyString_AsTDB_DATA(py_key); + if (!key.dptr) + return NULL; value = PyString_AsTDB_DATA(py_value); + if (!value.dptr) + return NULL; ret = tdb_store(self->ctx, key, value, flag); PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx); -- cgit