1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-24 21:34:56 +03:00

More checks for passing NULL tdb contexts to tdb functions.

(This used to be commit 7faa70d254)
This commit is contained in:
Tim Potter 2000-02-16 22:57:57 +00:00
parent 8b45838ffc
commit 590d92c77a

View File

@ -597,6 +597,13 @@ int tdb_update(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf)
tdb_off rec_ptr;
int ret = -1;
if (tdb == NULL) {
#ifdef TDB_DEBUG
printf("tdb_update() called with null context\n");
#endif
return -1;
}
/* find which hash bucket it is in */
hash = tdb_hash(&key);
@ -634,6 +641,13 @@ TDB_DATA tdb_fetch(TDB_CONTEXT *tdb, TDB_DATA key)
struct list_struct rec;
TDB_DATA ret = null_data;
if (tdb == NULL) {
#ifdef TDB_DEBUG
printf("tdb_fetch() called with null context\n");
#endif
return null_data;
}
/* find which hash bucket it is in */
hash = tdb_hash(&key);
@ -687,6 +701,13 @@ int tdb_traverse(TDB_CONTEXT *tdb, int (*fn)(TDB_CONTEXT *tdb, TDB_DATA key, TDB
char *data;
TDB_DATA key, dbuf;
if (tdb == NULL) {
#ifdef TDB_DEBUG
printf("tdb_traverse() called with null context\n");
#endif
return -1;
}
/* loop over all hash chains */
for (h = 0; h < tdb->header.hash_size; h++) {
tdb_lock(tdb, BUCKET(h));
@ -749,6 +770,13 @@ TDB_DATA tdb_firstkey(TDB_CONTEXT *tdb)
unsigned hash;
TDB_DATA ret;
if (tdb == NULL) {
#ifdef TDB_DEBUG
printf("tdb_firstkey() called with null context\n");
#endif
return null_data;
}
/* look for a non-empty hash chain */
for (hash = 0, rec_ptr = 0;
hash < tdb->header.hash_size;
@ -794,6 +822,13 @@ TDB_DATA tdb_nextkey(TDB_CONTEXT *tdb, TDB_DATA key)
struct list_struct rec;
TDB_DATA ret;
if (tdb == NULL) {
#ifdef TDB_DEBUG
printf("tdb_nextkey() called with null context\n");
#endif
return null_data;
}
/* find which hash bucket it is in */
hash = tdb_hash(&key);
hbucket = BUCKET(hash);
@ -842,6 +877,13 @@ int tdb_delete(TDB_CONTEXT *tdb, TDB_DATA key)
struct list_struct rec, lastrec;
char *data = NULL;
if (tdb == NULL) {
#ifdef TDB_DEBUG
printf("tdb_delete() called with null context\n");
#endif
return -1;
}
/* find which hash bucket it is in */
hash = tdb_hash(&key);
@ -940,6 +982,13 @@ int tdb_store(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf, int flag)
tdb_off rec_ptr, offset;
char *p = NULL;
if (tdb == NULL) {
#ifdef TDB_DEBUG
printf("tdb_store() called with null context\n");
#endif
return -1;
}
/* find which hash bucket it is in */
hash = tdb_hash(&key);
@ -1136,12 +1185,26 @@ int tdb_close(TDB_CONTEXT *tdb)
/* lock the database. If we already have it locked then don't do anything */
int tdb_writelock(TDB_CONTEXT *tdb)
{
if (tdb == NULL) {
#ifdef TDB_DEBUG
printf("tdb_writelock() called with null context\n");
#endif
return -1;
}
return tdb_lock(tdb, -1);
}
/* unlock the database. */
int tdb_writeunlock(TDB_CONTEXT *tdb)
{
if (tdb == NULL) {
#ifdef TDB_DEBUG
printf("tdb_writeunlock() called with null context\n");
#endif
return -1;
}
return tdb_unlock(tdb, -1);
}
@ -1149,6 +1212,13 @@ int tdb_writeunlock(TDB_CONTEXT *tdb)
contention - it cannot guarantee how many records will be locked */
int tdb_lockchain(TDB_CONTEXT *tdb, TDB_DATA key)
{
if (tdb == NULL) {
#ifdef TDB_DEBUG
printf("tdb_lockchain() called with null context\n");
#endif
return -1;
}
return tdb_lock(tdb, BUCKET(tdb_hash(&key)));
}
@ -1156,5 +1226,12 @@ int tdb_lockchain(TDB_CONTEXT *tdb, TDB_DATA key)
/* unlock one hash chain */
int tdb_unlockchain(TDB_CONTEXT *tdb, TDB_DATA key)
{
if (tdb == NULL) {
#ifdef TDB_DEBUG
printf("tdb_unlockchain() called with null context\n");
#endif
return -1;
}
return tdb_unlock(tdb, BUCKET(tdb_hash(&key)));
}