summaryrefslogtreecommitdiff
path: root/test/thread
diff options
context:
space:
mode:
authorKeith Bostic <keith.bostic@mongodb.com>2017-03-24 08:16:21 -0400
committerGitHub <noreply@github.com>2017-03-24 08:16:21 -0400
commit1ceddd4a972bf220db9585739e9fcb283d618da4 (patch)
tree131dbb5b03a9cd4ac7951aec8d6edeafcd59fc75 /test/thread
parent56fa32f25a0745b049789f31e7dd5128be9525a0 (diff)
downloadmongo-1ceddd4a972bf220db9585739e9fcb283d618da4.tar.gz
WT-3136 bug fix: WiredTiger doesn't check sprintf calls for error return (#3340)
* WT-3136 bug fix: WiredTiger doesn't check sprintf calls for error return Make a pass through the source base to check sprintf, snprintf, vsprintf and vsnprintf calls for errors. * A WiredTiger key is a uint64_t. Use sizeof(), don't hard-wire buffer sizes into the code. * More (u_int) vs. (uint64_t) fixes. * Use CONFIG_APPEND instead of FORMAT_APPEND, it makes more sense. * revert part of 4475ae9, there's an explicit allocation of the size of the buffer. * MVSC complaints: test\format\config.c(765): warning C4018: '<': signed/unsigned mismatch test\format\config.c(765): warning C4018: '>': signed/unsigned mismatch * Change Windows testing shim to correctly use __wt_snprintf * Change Windows test shim to use the __wt_XXX functions * MSDN's _vscprintf API returns the number of characters excluding the termininating nul byte, return that value.
Diffstat (limited to 'test/thread')
-rw-r--r--test/thread/file.c35
-rw-r--r--test/thread/rw.c41
-rw-r--r--test/thread/stats.c3
-rw-r--r--test/thread/t.c8
4 files changed, 47 insertions, 40 deletions
diff --git a/test/thread/file.c b/test/thread/file.c
index 81ec6ad44f8..7a7d16c4cd6 100644
--- a/test/thread/file.c
+++ b/test/thread/file.c
@@ -33,20 +33,18 @@ file_create(const char *name)
{
WT_SESSION *session;
int ret;
- char *p, *end, config[128];
+ char config[128];
if ((ret = conn->open_session(conn, NULL, NULL, &session)) != 0)
testutil_die(ret, "conn.session");
- p = config;
- end = config + sizeof(config);
- p += snprintf(p, (size_t)(end - p),
+ testutil_check(__wt_snprintf(config, sizeof(config),
"key_format=%s,"
"internal_page_max=%d,"
- "leaf_page_max=%d,",
- ftype == ROW ? "u" : "r", 16 * 1024, 128 * 1024);
- if (ftype == FIX)
- (void)snprintf(p, (size_t)(end - p), ",value_format=3t");
+ "leaf_page_max=%d,"
+ "%s",
+ ftype == ROW ? "u" : "r", 16 * 1024, 128 * 1024,
+ ftype == FIX ? ",value_format=3t" : ""));
if ((ret = session->create(session, name, config)) != 0)
if (ret != EEXIST)
@@ -62,9 +60,10 @@ load(const char *name)
WT_CURSOR *cursor;
WT_ITEM *key, _key, *value, _value;
WT_SESSION *session;
- char keybuf[64], valuebuf[64];
- u_int keyno;
+ uint64_t keyno;
+ size_t len;
int ret;
+ char keybuf[64], valuebuf[64];
file_create(name);
@@ -79,18 +78,22 @@ load(const char *name)
value = &_value;
for (keyno = 1; keyno <= nkeys; ++keyno) {
if (ftype == ROW) {
+ testutil_check(__wt_snprintf_len_set(
+ keybuf, sizeof(keybuf),
+ &len, "%017" PRIu64, keyno));
key->data = keybuf;
- key->size = (uint32_t)
- snprintf(keybuf, sizeof(keybuf), "%017u", keyno);
+ key->size = (uint32_t)len;
cursor->set_key(cursor, key);
} else
- cursor->set_key(cursor, (uint32_t)keyno);
- value->data = valuebuf;
+ cursor->set_key(cursor, keyno);
if (ftype == FIX)
cursor->set_value(cursor, 0x01);
else {
- value->size = (uint32_t)
- snprintf(valuebuf, sizeof(valuebuf), "%37u", keyno);
+ testutil_check(__wt_snprintf_len_set(
+ valuebuf, sizeof(valuebuf),
+ &len, "%37" PRIu64, keyno));
+ value->data = valuebuf;
+ value->size = (uint32_t)len;
cursor->set_value(cursor, value);
}
if ((ret = cursor->insert(cursor)) != 0)
diff --git a/test/thread/rw.c b/test/thread/rw.c
index c6107a06c49..e8a2650ca51 100644
--- a/test/thread/rw.c
+++ b/test/thread/rw.c
@@ -66,7 +66,8 @@ rw_start(u_int readers, u_int writers)
for (i = 0; i < writers; ++i) {
if (i == 0 || multiple_files) {
run_info[i].name = dmalloc(64);
- snprintf(run_info[i].name, 64, FNAME, i);
+ testutil_check(__wt_snprintf(
+ run_info[i].name, 64, FNAME, i));
/* Vary by orders of magnitude */
if (vary_nops)
@@ -88,8 +89,8 @@ rw_start(u_int readers, u_int writers)
run_info[offset].name = dmalloc(64);
/* Have readers read from tables with writes. */
name_index = i % writers;
- snprintf(
- run_info[offset].name, 64, FNAME, name_index);
+ testutil_check(__wt_snprintf(
+ run_info[offset].name, 64, FNAME, name_index));
/* Vary by orders of magnitude */
if (vary_nops)
@@ -158,7 +159,8 @@ static inline void
reader_op(WT_SESSION *session, WT_CURSOR *cursor, INFO *s)
{
WT_ITEM *key, _key;
- u_int keyno;
+ size_t len;
+ uint64_t keyno;
int ret;
char keybuf[64];
@@ -166,17 +168,18 @@ reader_op(WT_SESSION *session, WT_CURSOR *cursor, INFO *s)
keyno = __wt_random(&s->rnd) % nkeys + 1;
if (ftype == ROW) {
+ testutil_check(__wt_snprintf_len_set(
+ keybuf, sizeof(keybuf), &len, "%017" PRIu64, keyno));
key->data = keybuf;
- key->size = (uint32_t)
- snprintf(keybuf, sizeof(keybuf), "%017u", keyno);
+ key->size = (uint32_t)len;
cursor->set_key(cursor, key);
} else
- cursor->set_key(cursor, (uint32_t)keyno);
+ cursor->set_key(cursor, keyno);
if ((ret = cursor->search(cursor)) != 0 && ret != WT_NOTFOUND)
testutil_die(ret, "cursor.search");
if (log_print)
testutil_check(session->log_printf(session,
- "Reader Thread %p key %017u", pthread_self(), keyno));
+ "Reader Thread %p key %017" PRIu64, pthread_self(), keyno));
}
/*
@@ -195,7 +198,7 @@ reader(void *arg)
id = (int)(uintptr_t)arg;
s = &run_info[id];
- __wt_thread_id(tid, sizeof(tid));
+ testutil_check(__wt_thread_id(tid, sizeof(tid)));
__wt_random_init(&s->rnd);
printf(" read thread %2d starting: tid: %s, file: %s\n",
@@ -242,7 +245,8 @@ static inline void
writer_op(WT_SESSION *session, WT_CURSOR *cursor, INFO *s)
{
WT_ITEM *key, _key, *value, _value;
- u_int keyno;
+ uint64_t keyno;
+ size_t len;
int ret;
char keybuf[64], valuebuf[64];
@@ -251,12 +255,13 @@ writer_op(WT_SESSION *session, WT_CURSOR *cursor, INFO *s)
keyno = __wt_random(&s->rnd) % nkeys + 1;
if (ftype == ROW) {
+ testutil_check(__wt_snprintf_len_set(
+ keybuf, sizeof(keybuf), &len, "%017" PRIu64, keyno));
key->data = keybuf;
- key->size = (uint32_t)
- snprintf(keybuf, sizeof(keybuf), "%017u", keyno);
+ key->size = (uint32_t)len;
cursor->set_key(cursor, key);
} else
- cursor->set_key(cursor, (uint32_t)keyno);
+ cursor->set_key(cursor, keyno);
if (keyno % 5 == 0) {
++s->remove;
if ((ret =
@@ -268,8 +273,10 @@ writer_op(WT_SESSION *session, WT_CURSOR *cursor, INFO *s)
if (ftype == FIX)
cursor->set_value(cursor, 0x10);
else {
- value->size = (uint32_t)snprintf(
- valuebuf, sizeof(valuebuf), "XXX %37u", keyno);
+ testutil_check(__wt_snprintf_len_set(
+ valuebuf, sizeof(valuebuf),
+ &len, "XXX %37" PRIu64, keyno));
+ value->size = (uint32_t)len;
cursor->set_value(cursor, value);
}
if ((ret = cursor->update(cursor)) != 0)
@@ -277,7 +284,7 @@ writer_op(WT_SESSION *session, WT_CURSOR *cursor, INFO *s)
}
if (log_print)
testutil_check(session->log_printf(session,
- "Writer Thread %p key %017u", pthread_self(), keyno));
+ "Writer Thread %p key %017" PRIu64, pthread_self(), keyno));
}
/*
@@ -296,7 +303,7 @@ writer(void *arg)
id = (int)(uintptr_t)arg;
s = &run_info[id];
- __wt_thread_id(tid, sizeof(tid));
+ testutil_check(__wt_thread_id(tid, sizeof(tid)));
__wt_random_init(&s->rnd);
printf("write thread %2d starting: tid: %s, file: %s\n",
diff --git a/test/thread/stats.c b/test/thread/stats.c
index 67a2c02719b..839d65e8a4d 100644
--- a/test/thread/stats.c
+++ b/test/thread/stats.c
@@ -65,7 +65,8 @@ stats(void)
/* File statistics. */
if (!multiple_files) {
- (void)snprintf(name, sizeof(name), "statistics:" FNAME, 0);
+ testutil_check(__wt_snprintf(
+ name, sizeof(name), "statistics:" FNAME, 0));
if ((ret = session->open_cursor(
session, name, NULL, NULL, &cursor)) != 0)
testutil_die(ret, "session.open_cursor");
diff --git a/test/thread/t.c b/test/thread/t.c
index 9dfd02bdad2..d2ed4c74bb7 100644
--- a/test/thread/t.c
+++ b/test/thread/t.c
@@ -185,19 +185,15 @@ wt_connect(char *config_open)
};
int ret;
char config[512];
- size_t print_count;
testutil_clean_work_dir(home);
testutil_make_work_dir(home);
- print_count = (size_t)snprintf(config, sizeof(config),
+ testutil_check(__wt_snprintf(config, sizeof(config),
"create,statistics=(all),error_prefix=\"%s\",%s%s",
progname,
config_open == NULL ? "" : ",",
- config_open == NULL ? "" : config_open);
-
- if (print_count >= sizeof(config))
- testutil_die(EINVAL, "Config string too long");
+ config_open == NULL ? "" : config_open));
if ((ret = wiredtiger_open(home, &event_handler, config, &conn)) != 0)
testutil_die(ret, "wiredtiger_open");