[Python-checkins] python/dist/src/Modules _bsddb.c,1.3,1.4
greg@users.sourceforge.net
greg@users.sourceforge.net
Thu, 16 Jan 2003 23:53:01 -0800
Update of /cvsroot/python/python/dist/src/Modules
In directory sc8-pr-cvs1:/tmp/cvs-serv5715/extsrc
Modified Files:
_bsddb.c
Log Message:
bugfix: disallow use of DB_TXN after commit() or abort(), prevents a
coredump or segmentation violation.
Sourceforge patch ID 664896:
http://sourceforge.net/tracker/index.php?func=detail&aid=664896&group_id=13900&atid=313900
The bug was reported on the pybsddb-users mailing list.
Index: _bsddb.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/_bsddb.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** _bsddb.c 30 Dec 2002 20:53:52 -0000 1.3
--- _bsddb.c 17 Jan 2003 07:52:59 -0000 1.4
***************
*** 86,90 ****
#define DBVER (DB_VERSION_MAJOR * 10 + DB_VERSION_MINOR)
! #define PY_BSDDB_VERSION "4.1.1"
static char *rcs_id = "$Id$";
--- 86,90 ----
#define DBVER (DB_VERSION_MAJOR * 10 + DB_VERSION_MINOR)
! #define PY_BSDDB_VERSION "4.1.2"
static char *rcs_id = "$Id$";
***************
*** 466,469 ****
--- 466,470 ----
if (errObj != NULL) {
+ /* FIXME this needs proper bounds checking on errTxt */
strcpy(errTxt, db_strerror(err));
if (_db_errmsg[0]) {
***************
*** 3723,3735 ****
{
int flags=0, err;
if (!PyArg_ParseTuple(args, "|i:commit", &flags))
return NULL;
MYDB_BEGIN_ALLOW_THREADS;
#if (DBVER >= 40)
! err = self->txn->commit(self->txn, flags);
#else
! err = txn_commit(self->txn, flags);
#endif
MYDB_END_ALLOW_THREADS;
--- 3724,3744 ----
{
int flags=0, err;
+ DB_TXN *txn;
if (!PyArg_ParseTuple(args, "|i:commit", &flags))
return NULL;
+ if (!self->txn) {
+ PyErr_SetObject(DBError, Py_BuildValue("(is)", 0,
+ "DBTxn must not be used after txn_commit or txn_abort"));
+ return NULL;
+ }
+ txn = self->txn;
+ self->txn = NULL; /* this DB_TXN is no longer valid after this call */
MYDB_BEGIN_ALLOW_THREADS;
#if (DBVER >= 40)
! err = txn->commit(txn, flags);
#else
! err = txn_commit(txn, flags);
#endif
MYDB_END_ALLOW_THREADS;
***************
*** 3755,3758 ****
--- 3764,3772 ----
}
+ if (!self->txn) {
+ PyErr_SetObject(DBError, Py_BuildValue("(is)", 0,
+ "DBTxn must not be used after txn_commit or txn_abort"));
+ return NULL;
+ }
MYDB_BEGIN_ALLOW_THREADS;
#if (DBVER >= 40)
***************
*** 3770,3773 ****
--- 3784,3792 ----
return NULL;
+ if (!self->txn) {
+ PyErr_SetObject(DBError, Py_BuildValue("(is)", 0,
+ "DBTxn must not be used after txn_commit or txn_abort"));
+ return NULL;
+ }
MYDB_BEGIN_ALLOW_THREADS;
err = txn_prepare(self->txn);
***************
*** 3783,3795 ****
{
int err;
if (!PyArg_ParseTuple(args, ":abort"))
return NULL;
MYDB_BEGIN_ALLOW_THREADS;
#if (DBVER >= 40)
! err = self->txn->abort(self->txn);
#else
! err = txn_abort(self->txn);
#endif
MYDB_END_ALLOW_THREADS;
--- 3802,3822 ----
{
int err;
+ DB_TXN *txn;
if (!PyArg_ParseTuple(args, ":abort"))
return NULL;
+ if (!self->txn) {
+ PyErr_SetObject(DBError, Py_BuildValue("(is)", 0,
+ "DBTxn must not be used after txn_commit or txn_abort"));
+ return NULL;
+ }
+ txn = self->txn;
+ self->txn = NULL; /* this DB_TXN is no longer valid after this call */
MYDB_BEGIN_ALLOW_THREADS;
#if (DBVER >= 40)
! err = txn->abort(txn);
#else
! err = txn_abort(txn);
#endif
MYDB_END_ALLOW_THREADS;
***************
*** 3807,3810 ****
--- 3834,3842 ----
return NULL;
+ if (!self->txn) {
+ PyErr_SetObject(DBError, Py_BuildValue("(is)", 0,
+ "DBTxn must not be used after txn_commit or txn_abort"));
+ return NULL;
+ }
MYDB_BEGIN_ALLOW_THREADS;
#if (DBVER >= 40)