Author: ab Date: 2006-10-02 14:06:04 +0000 (Mon, 02 Oct 2006) New Revision: 19047
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=19047 Log: Reformat and simplify code a bit; add some pointer checks. Patch from Aleksey Fedoseev Modified: branches/tmp/vl-messaging/source/lib/dbwrap_msg.c Changeset: Modified: branches/tmp/vl-messaging/source/lib/dbwrap_msg.c =================================================================== --- branches/tmp/vl-messaging/source/lib/dbwrap_msg.c 2006-10-02 13:50:30 UTC (rev 19046) +++ branches/tmp/vl-messaging/source/lib/dbwrap_msg.c 2006-10-02 14:06:04 UTC (rev 19047) @@ -458,6 +458,10 @@ TDB_DATA buf; static BOOL traverse_msg_reg = False; int count = 0; + + if(fn == NULL) { + return -1; + } null_data.dsize = 0; null_data.dptr = NULL; @@ -484,7 +488,7 @@ while(ctx->record != NULL) { count++; - if(fn && fn(ctx->record->key, ctx->record->value, private_data)) { + if(fn(ctx->record->key, ctx->record->value, private_data)) { /* break the traversal */ TALLOC_FREE(ctx->record); message_deregister(MSG_DB_TRAVERSE); @@ -1105,6 +1109,8 @@ struct db_entry *database, struct db_records_list *record) { + SMB_ASSERT(record && record->key.dptr); + { char *keystr = hex_encode(NULL, (unsigned char *)record->key.dptr, record->key.dsize); @@ -1124,6 +1130,11 @@ TALLOC_FREE(li); data = msg_pack_data(NULL, database->idx, record->value); + + if(data.dptr == NULL) { + DEBUG(0, ("Can't pack data\n")); + return ; + } DEBUG(10, ("Sending fetchlock response (len %d) to %s\n", data.dsize, procid_str_static(&source))); @@ -1142,6 +1153,8 @@ static void process_db_delete(struct db_entry *database, struct db_records_list *record) { + SMB_ASSERT(record && record->key.dptr); + { char *keystr = hex_encode(NULL, (unsigned char *)record->key.dptr, record->key.dsize); @@ -1196,7 +1209,7 @@ void process_db_request(struct process_id *lockd_pid, struct process_id *src_pid, int msg_type, - char* buffer, + char *buffer, size_t len) { uint8_t idx; @@ -1210,78 +1223,79 @@ if(msg_type == MSG_DB_INIT) { /* create new database or return opened one */ process_db_init(lockd_pid, src_pid, buffer); + return; + } + + if(msg_type == MSG_DB_STORE) { + if(!msg_unpack_double_data(buffer, len, NULL, + &idx, &data1, &data2)) { + DEBUG(0, ("Can't unpack data\n")); + return ; + } } else { - if(msg_type == MSG_DB_STORE) { - if(!msg_unpack_double_data(buffer, len, NULL, - &idx, &data1, &data2)) { - DEBUG(0, ("Can't unpack data\n")); - return ; - } - } else { - data2.dsize = 0; - data2.dptr = NULL; + data2.dsize = 0; + data2.dptr = NULL; + + if(!msg_unpack_data(buffer, len, NULL, + &idx, &data1)) { + DEBUG(0, ("Can't unpack data\n")); + return ; + } + } + + /* find the database */ + dbl = find_db_by_index(idx); + if(dbl == NULL) { + DEBUG(0, ("Bad database index %d\n", idx)); + TALLOC_FREE(data1.dptr); + TALLOC_FREE(data2.dptr); + return ; + } + + if(msg_type == MSG_DB_FREE) { + + process_db_free(dbl); + + } else if(msg_type == MSG_DB_REINIT) { + + process_db_reinit(dbl); + + } else if(msg_type == MSG_DB_FETCHLOCK) { + + process_db_fetch(lockd_pid, src_pid, dbl, data1); + + } else if(msg_type == MSG_DB_TRAVERSE) { - if(!msg_unpack_data(buffer, len, NULL, - &idx, &data1)) { - DEBUG(0, ("Can't unpack data\n")); - return ; - } - } + process_db_traverse(lockd_pid, src_pid, dbl); - /* find the database */ - dbl = find_db_by_index(idx); - if(dbl == NULL) { - DEBUG(0, ("Bad database index %d\n", idx)); + } else { + + /* find the record */ + dbrl = find_record_by_key(dbl, data1); + if(dbrl == NULL) { + DEBUG(0, ("Can't find the record\n")); TALLOC_FREE(data1.dptr); TALLOC_FREE(data2.dptr); - return ; + return ; } - if(msg_type == MSG_DB_FREE) { + if(msg_type == MSG_DB_UNLOCK) { - process_db_free(dbl); - - } else if(msg_type == MSG_DB_REINIT) { - - process_db_reinit(dbl); - - } else if(msg_type == MSG_DB_FETCHLOCK) { - - process_db_fetch(lockd_pid, src_pid, dbl, data1); - - } else if(msg_type == MSG_DB_TRAVERSE) { - - process_db_traverse(lockd_pid, src_pid, dbl); - - } else { - - /* find the record */ - dbrl = find_record_by_key(dbl, data1); - if(dbrl == NULL) { - DEBUG(0, ("Can't find the record\n")); - TALLOC_FREE(data1.dptr); - TALLOC_FREE(data2.dptr); - return ; - } - - if(msg_type == MSG_DB_UNLOCK) { - - process_db_unlock(lockd_pid, dbl, dbrl); + process_db_unlock(lockd_pid, dbl, dbrl); - } else if(msg_type == MSG_DB_STORE) { + } else if(msg_type == MSG_DB_STORE) { - process_db_store(dbl, dbrl, data2); + process_db_store(dbl, dbrl, data2); - } else if(msg_type == MSG_DB_DELETE) { + } else if(msg_type == MSG_DB_DELETE) { - process_db_delete(dbl, dbrl); + process_db_delete(dbl, dbrl); - } else { - DEBUG(0, ("Bad db message type %d\n", msg_type)); - } + } else { + DEBUG(0, ("Bad db message type %d\n", msg_type)); } + } - TALLOC_FREE(data1.dptr); - TALLOC_FREE(data2.dptr); - } + TALLOC_FREE(data1.dptr); + TALLOC_FREE(data2.dptr); }
