Commit 410333c1 authored by Leif Walsh's avatar Leif Walsh Committed by Yoni Fogel

refs #5368 fix dbt lengths to prevent (relatively harmless) global buffer overflows


git-svn-id: file:///svn/toku/tokudb@48377 c7de825b-a66e-492c-adef-691d508d4ae1
parent a802af97
......@@ -29,7 +29,7 @@ int test_main (int argc, char * const argv[]) {
r = db->open(db, txna, "foo.db", NULL, DB_BTREE, DB_CREATE, 0666); CKERR(r);
DBT key,val;
r = db->put(db, txna, dbt_init(&key, "a", 4), dbt_init(&val, "a", 4), 0); CKERR(r);
r = db->put(db, txna, dbt_init(&key, "a", 2), dbt_init(&val, "a", 2), 0); CKERR(r);
r = txna->commit(txna, 0); CKERR(r);
}
......
......@@ -49,8 +49,8 @@ static void verify_shared_ops_fail(DB_ENV* env, DB* db) {
in_val.ulen = sizeof(in_val_data);
DBT in_keys[2];
memset(&in_keys, 0, sizeof(in_keys));
dbt_init(&key, "a", 4);
dbt_init(&val, "a", 4);
dbt_init(&key, "a", 2);
dbt_init(&val, "a", 2);
r = env->txn_begin(env, NULL, &txn, 0); CKERR(r);
r = db->put(
......@@ -242,11 +242,11 @@ int test_main (int argc, char * const argv[]) {
r = env->txn_begin(env, NULL, &txna, 0); CKERR(r);
r = env->txn_begin(env, NULL, &txnb, 0); CKERR(r);
DBT key,val;
dbt_init(&key, "a", 4);
dbt_init(&val, "a", 4);
dbt_init(&key, "a", 2);
dbt_init(&val, "a", 2);
r = db->put(db, txna, &key, &val, 0); CKERR(r);
dbt_init(&key, "b", 4);
dbt_init(&val, "b", 4);
dbt_init(&key, "b", 2);
dbt_init(&val, "b", 2);
r = db->put(db, txnb, &key, &val, 0); CKERR(r);
verify_excl_ops_fail(env,"foo.db");
r = txna->abort(txna); CKERR(r);
......@@ -254,9 +254,9 @@ int test_main (int argc, char * const argv[]) {
r = env->txn_begin(env, NULL, &txna, 0); CKERR(r);
r = env->txn_begin(env, NULL, &txnb, 0); CKERR(r);
dbt_init(&key, "a", 4);
dbt_init(&key, "a", 2);
r = db->del(db, txna, &key, DB_DELETE_ANY); CKERR(r);
dbt_init(&key, "b", 4);
dbt_init(&key, "b", 2);
r = db->del(db, txnb, &key, DB_DELETE_ANY); CKERR(r);
verify_excl_ops_fail(env,"foo.db");
r = txna->abort(txna); CKERR(r);
......@@ -265,9 +265,9 @@ int test_main (int argc, char * const argv[]) {
r = env->txn_begin(env, NULL, &txna, 0); CKERR(r);
r = env->txn_begin(env, NULL, &txnb, 0); CKERR(r);
dbt_init(&key, "a", 4);
dbt_init(&key, "a", 2);
r = db->update(db, txna, &key, &val, 0); CKERR(r);
dbt_init(&key, "b", 4);
dbt_init(&key, "b", 2);
r = db->update(db, txnb, &key, &val, 0); CKERR(r);
verify_excl_ops_fail(env,"foo.db");
r = txna->abort(txna); CKERR(r);
......@@ -282,15 +282,15 @@ int test_main (int argc, char * const argv[]) {
r = env->txn_begin(env, NULL, &txna, 0); CKERR(r);
r = env->txn_begin(env, NULL, &txnb, 0); CKERR(r);
dbt_init(&key, "a", 4);
dbt_init(&val, "a", 4);
dbt_init(&key, "a", 2);
dbt_init(&val, "a", 2);
env->put_multiple(
env, NULL, txna,
&key, &val,
1, &db, &in_key, &in_val, &flags);
CKERR(r);
dbt_init(&key, "b", 4);
dbt_init(&val, "b", 4);
dbt_init(&key, "b", 2);
dbt_init(&val, "b", 2);
env->put_multiple(
env, NULL, txnb,
&key, &val,
......@@ -303,15 +303,15 @@ int test_main (int argc, char * const argv[]) {
flags = DB_DELETE_ANY;
r = env->txn_begin(env, NULL, &txna, 0); CKERR(r);
r = env->txn_begin(env, NULL, &txnb, 0); CKERR(r);
dbt_init(&key, "a", 4);
dbt_init(&val, "a", 4);
dbt_init(&key, "a", 2);
dbt_init(&val, "a", 2);
env->del_multiple(
env, NULL, txna,
&key, &val,
1, &db, &in_key, &flags);
CKERR(r);
dbt_init(&key, "b", 4);
dbt_init(&val, "b", 4);
dbt_init(&key, "b", 2);
dbt_init(&val, "b", 2);
env->del_multiple(
env, db, txnb,
&key, &val,
......@@ -326,8 +326,8 @@ int test_main (int argc, char * const argv[]) {
memset(&in_keys, 0, sizeof(in_keys));
r = env->txn_begin(env, NULL, &txna, 0); CKERR(r);
r = env->txn_begin(env, NULL, &txnb, 0); CKERR(r);
dbt_init(&key, "a", 4);
dbt_init(&val, "a", 4);
dbt_init(&key, "a", 2);
dbt_init(&val, "a", 2);
env->update_multiple(
env, NULL, txna,
&key, &val,
......@@ -336,8 +336,8 @@ int test_main (int argc, char * const argv[]) {
2, in_keys,
1, &in_val);
CKERR(r);
dbt_init(&key, "b", 4);
dbt_init(&val, "b", 4);
dbt_init(&key, "b", 2);
dbt_init(&val, "b", 2);
env->update_multiple(
env, db, txnb,
&key, &val,
......
......@@ -30,7 +30,7 @@ int test_main (int argc, char * const argv[]) {
r = db->open(db, txna, "foo.db", NULL, DB_BTREE, DB_CREATE, 0666); CKERR(r);
DBT key,val;
r = db->put(db, txna, dbt_init(&key, "a", 4), dbt_init(&val, "a", 4), 0); CKERR(r);
r = db->put(db, txna, dbt_init(&key, "a", 2), dbt_init(&val, "a", 2), 0); CKERR(r);
r = txna->commit(txna, 0); CKERR(r);
}
......@@ -44,31 +44,31 @@ int test_main (int argc, char * const argv[]) {
//
{
DBT key,val;
r = db->put(db, txn_put, dbt_init(&key, "x", 4), dbt_init(&val, "x", 4), 0); CKERR(r);
r = db->put(db, txn_put, dbt_init(&key, "x", 2), dbt_init(&val, "x", 2), 0); CKERR(r);
dbt_init_malloc(&val);
r = db->get(db, txn_put, dbt_init(&key, "x", 4), &val, 0); CKERR(r);
r = db->get(db, txn_put, dbt_init(&key, "x", 2), &val, 0); CKERR(r);
toku_free(val.data);
dbt_init_malloc(&val);
r = db->get(db, txn_committed, dbt_init(&key, "x", 4), &val, 0); CKERR2(r, DB_NOTFOUND);
r = db->get(db, txn_committed, dbt_init(&key, "x", 2), &val, 0); CKERR2(r, DB_NOTFOUND);
toku_free(val.data);
dbt_init_malloc(&val);
r = db->get(db, txn_uncommitted, dbt_init(&key, "x", 4), &val, 0); CKERR(r);
r = db->get(db, txn_uncommitted, dbt_init(&key, "x", 2), &val, 0); CKERR(r);
toku_free(val.data);
r = db->del(db, txn_put, dbt_init(&key, "a", 4), 0); CKERR(r);
r = db->del(db, txn_put, dbt_init(&key, "a", 2), 0); CKERR(r);
dbt_init_malloc(&val);
r = db->get(db, txn_put, dbt_init(&key, "a", 4), &val, 0); CKERR2(r, DB_NOTFOUND);
r = db->get(db, txn_put, dbt_init(&key, "a", 2), &val, 0); CKERR2(r, DB_NOTFOUND);
toku_free(val.data);
dbt_init_malloc(&val);
r = db->get(db, txn_committed, dbt_init(&key, "a", 4), &val, 0); CKERR(r);
r = db->get(db, txn_committed, dbt_init(&key, "a", 2), &val, 0); CKERR(r);
toku_free(val.data);
dbt_init_malloc(&val);
r = db->get(db, txn_uncommitted, dbt_init(&key, "a", 4), &val, 0); CKERR2(r, DB_NOTFOUND);
r = db->get(db, txn_uncommitted, dbt_init(&key, "a", 2), &val, 0); CKERR2(r, DB_NOTFOUND);
toku_free(val.data);
val.data = NULL;
......@@ -97,7 +97,7 @@ int test_main (int argc, char * const argv[]) {
r = db->cursor(db, txn_committed, &cursor_committed, 0); assert(r == 0);
r = db->cursor(db, txn_uncommitted, &cursor_uncommitted, 0); assert(r == 0);
r = db->put(db, txn_put, dbt_init(&key, "y", 4), dbt_init(&val, "y", 4), 0); CKERR(r);
r = db->put(db, txn_put, dbt_init(&key, "y", 2), dbt_init(&val, "y", 2), 0); CKERR(r);
r = cursor_uncommitted->c_get(cursor_uncommitted, &curr_key, &curr_val, DB_NEXT); CKERR(r);
assert(((char *)(curr_key.data))[0] == 'x');
......
......@@ -30,7 +30,7 @@ int test_main (int argc, char * const argv[]) {
r = db->open(db, txna, "foo.db", NULL, DB_BTREE, DB_CREATE, 0666); CKERR(r);
DBT key,val;
r = db->put(db, txna, dbt_init(&key, "a", 4), dbt_init(&val, "a", 4), 0); CKERR(r);
r = db->put(db, txna, dbt_init(&key, "a", 2), dbt_init(&val, "a", 2), 0); CKERR(r);
r = txna->commit(txna, 0); CKERR(r);
}
......@@ -44,9 +44,9 @@ int test_main (int argc, char * const argv[]) {
// r = env->txn_begin(env, txna, &txnb, DB_READ_UNCOMMITTED); CKERR(r);
{
DBT key,val;
r = db->put(db, txnx, dbt_init(&key, "x", 4), dbt_init(&val, "x", 4), 0); CKERR(r);
r = db->put(db, txnx, dbt_init(&key, "x", 2), dbt_init(&val, "x", 2), 0); CKERR(r);
dbt_init_malloc(&val);
r = db->get(db, txna, dbt_init(&key, "x", 4), &val, 0); CKERR(r);
r = db->get(db, txna, dbt_init(&key, "x", 2), &val, 0); CKERR(r);
toku_free(val.data);
val.data = NULL;
}
......
......@@ -33,7 +33,7 @@ int test_main (int argc, char * const argv[]) {
r = db->open(db, txna, "foo.db", NULL, DB_BTREE, DB_CREATE, 0666); CKERR(r);
DBT key,val;
r = db->put(db, txna, dbt_init(&key, "a", 4), dbt_init(&val, "a", 4), 0); CKERR(r);
r = db->put(db, txna, dbt_init(&key, "a", 2), dbt_init(&val, "a", 2), 0); CKERR(r);
r = env->txn_begin(env, NULL, &txnb, DB_TXN_SNAPSHOT); CKERR(r);
r = env->txn_begin(env, NULL, &txnc, DB_READ_COMMITTED); CKERR(r);
......
......@@ -48,7 +48,7 @@ int test_main (int argc, char * const argv[]) {
r = db->put(
db,
put_txn,
dbt_init(&key, "a", 4),
dbt_init(&key, "a", 2),
dbt_init(&val, &data, 4),
0
);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment