summaryrefslogtreecommitdiff
path: root/src/third_party/wiredtiger/src/cursor/cur_std.c
diff options
context:
space:
mode:
authorLuke Chen <luke.chen@mongodb.com>2020-01-15 05:39:47 +0000
committerevergreen <evergreen@mongodb.com>2020-01-15 05:39:47 +0000
commit44d463b0c7f6596bdd86b2d015db9f79bc434f4b (patch)
treef038f8f1daf7ce592ec9ad0621b18c800ee26771 /src/third_party/wiredtiger/src/cursor/cur_std.c
parentf22f71a0d3b10a8bfcf69d078621b240a67cf515 (diff)
downloadmongo-44d463b0c7f6596bdd86b2d015db9f79bc434f4b.tar.gz
Import wiredtiger: c6962452f2c3469c039edfcafb7702450bf14c3b from branch mongodb-4.4
ref: 5bd9fdfc0b..c6962452f2 for: 4.3.3 WT-4886 Avoid depending on particular error message text for test_bug018 WT-5003 Migrate Jenkins “wiredtiger-test-race-condition-stress-sanitizer” job to Evergreen WT-5024 Migrate Jenkins “wiredtiger-compatibility” job to Evergreen WT-5081 Add support for ASan builds in the Python test suite WT-5119 Birthmark records can be read as normal updates if reads race with checkpoints WT-5165 Add cursor copy debug mode WT-5199 Adding correctness tasks into rhel80 Evergreen build variant WT-5261 coverage-report task timed out in Evergreen WT-5334 Add testing coverage for static wt build WT-5379 Missing varargs cleanup WT-5410 WiredTiger formatted timestamp string buffer size is too small
Diffstat (limited to 'src/third_party/wiredtiger/src/cursor/cur_std.c')
-rw-r--r--src/third_party/wiredtiger/src/cursor/cur_std.c42
1 files changed, 40 insertions, 2 deletions
diff --git a/src/third_party/wiredtiger/src/cursor/cur_std.c b/src/third_party/wiredtiger/src/cursor/cur_std.c
index 7ff9273bf6d..84224560b02 100644
--- a/src/third_party/wiredtiger/src/cursor/cur_std.c
+++ b/src/third_party/wiredtiger/src/cursor/cur_std.c
@@ -228,6 +228,34 @@ __wt_cursor_kv_not_set(WT_CURSOR *cursor, bool key) WT_GCC_FUNC_ATTRIBUTE((cold)
}
/*
+ * __wt_cursor_copy_release_item --
+ * Release memory used by the key or value item in cursor copy debug mode.
+ */
+int
+__wt_cursor_copy_release_item(WT_CURSOR *cursor, WT_ITEM *item) WT_GCC_FUNC_ATTRIBUTE((cold))
+{
+ WT_DECL_ITEM(tmp);
+ WT_DECL_RET;
+ WT_SESSION_IMPL *session;
+
+ session = (WT_SESSION_IMPL *)cursor->session;
+
+ /*
+ * Whether or not we own the memory for the item, make a copy of the data and use that instead.
+ * That allows us to overwrite and free memory owned by the item, potentially uncovering
+ * programming errors related to retaining pointers to key/value memory beyond API boundaries.
+ */
+ WT_ERR(__wt_scr_alloc(session, 0, &tmp));
+ WT_ERR(__wt_buf_set(session, tmp, item->data, item->size));
+ __wt_explicit_overwrite(item->mem, item->memsize);
+ __wt_buf_free(session, item);
+ WT_ERR(__wt_buf_set(session, item, tmp->data, tmp->size));
+err:
+ __wt_scr_free(session, &tmp);
+ return (ret);
+}
+
+/*
* __wt_cursor_get_key --
* WT_CURSOR->get_key default implementation.
*/
@@ -346,6 +374,10 @@ __wt_cursor_get_keyv(WT_CURSOR *cursor, uint32_t flags, va_list ap)
if (!F_ISSET(cursor, WT_CURSTD_KEY_SET))
WT_ERR(__wt_cursor_kv_not_set(cursor, true));
+ /* Force an allocated copy when using cursor copy debug. */
+ if (F_ISSET(S2C(session), WT_CONN_DEBUG_CURSOR_COPY))
+ WT_ERR(__wt_buf_grow(session, &cursor->key, cursor->key.size));
+
if (WT_CURSOR_RECNO(cursor)) {
if (LF_ISSET(WT_CURSTD_RAW)) {
key = va_arg(ap, WT_ITEM *);
@@ -391,6 +423,7 @@ __wt_cursor_set_keyv(WT_CURSOR *cursor, uint32_t flags, va_list ap)
tmp.mem = NULL;
CURSOR_API_CALL(cursor, session, set_key, NULL);
+ WT_ERR(__cursor_copy_release(cursor));
if (F_ISSET(cursor, WT_CURSTD_KEY_SET) && WT_DATA_IN_ITEM(buf)) {
tmp = *buf;
buf->mem = NULL;
@@ -447,7 +480,7 @@ err:
* memory in the meantime, free it.
*/
if (tmp.mem != NULL) {
- if (buf->mem == NULL) {
+ if (buf->mem == NULL && !F_ISSET(S2C(session), WT_CONN_DEBUG_CURSOR_COPY)) {
buf->mem = tmp.mem;
buf->memsize = tmp.memsize;
} else
@@ -489,6 +522,10 @@ __wt_cursor_get_valuev(WT_CURSOR *cursor, va_list ap)
if (!F_ISSET(cursor, WT_CURSTD_VALUE_EXT | WT_CURSTD_VALUE_INT))
WT_ERR(__wt_cursor_kv_not_set(cursor, false));
+ /* Force an allocated copy when using cursor copy debug. */
+ if (F_ISSET(S2C(session), WT_CONN_DEBUG_CURSOR_COPY))
+ WT_ERR(__wt_buf_grow(session, &cursor->value, cursor->value.size));
+
/* Fast path some common cases. */
fmt = cursor->value_format;
if (F_ISSET(cursor, WT_CURSOR_RAW_OK) || WT_STREQ(fmt, "u")) {
@@ -538,6 +575,7 @@ __wt_cursor_set_valuev(WT_CURSOR *cursor, va_list ap)
tmp.mem = NULL;
CURSOR_API_CALL(cursor, session, set_value, NULL);
+ WT_ERR(__cursor_copy_release(cursor));
if (F_ISSET(cursor, WT_CURSTD_VALUE_SET) && WT_DATA_IN_ITEM(buf)) {
tmp = *buf;
buf->mem = NULL;
@@ -581,7 +619,7 @@ err:
* memory in the meantime, free it.
*/
if (tmp.mem != NULL) {
- if (buf->mem == NULL) {
+ if (buf->mem == NULL && !F_ISSET(S2C(session), WT_CONN_DEBUG_CURSOR_COPY)) {
buf->mem = tmp.mem;
buf->memsize = tmp.memsize;
} else