Skip to content

Commit

Permalink
WT-8248 Check for valid configuration key when using the WT_CURSOR.re…
Browse files Browse the repository at this point in the history
…configure API (#7479)

Do validation checking on WT_CURSOR.reconfigure arguments.
  • Loading branch information
keithbostic committed Jan 31, 2022
1 parent fbbdde7 commit 7ae2a80
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/cursor/cur_std.c
Expand Up @@ -1051,9 +1051,8 @@ __wt_cursor_reconfigure(WT_CURSOR *cursor, const char *config)
WT_CONFIG_ITEM cval;
WT_DECL_RET;
WT_SESSION_IMPL *session;
const char *cfg[] = {config, NULL};

CURSOR_API_CALL(cursor, session, reconfigure, NULL);
CURSOR_API_CALL_CONF(cursor, session, reconfigure, config, cfg, NULL);

/* Reconfiguration resets the cursor. */
WT_ERR(cursor->reset(cursor));
Expand Down
7 changes: 7 additions & 0 deletions src/include/api.h
Expand Up @@ -220,6 +220,13 @@
if (F_ISSET(cur, WT_CURSTD_CACHED)) \
WT_ERR(__wt_cursor_cached(cur))

#define CURSOR_API_CALL_CONF(cur, s, n, config, cfg, bt) \
(s) = CUR2S(cur); \
SESSION_API_PREPARE_CHECK(s, WT_CURSOR, n); \
API_CALL(s, WT_CURSOR, n, ((bt) == NULL) ? NULL : ((WT_BTREE *)(bt))->dhandle, config, cfg); \
if (F_ISSET(cur, WT_CURSTD_CACHED)) \
WT_ERR(__wt_cursor_cached(cur))

#define CURSOR_API_CALL_PREPARE_ALLOWED(cur, s, n, bt) \
(s) = CUR2S(cur); \
API_CALL_NOCONF(s, WT_CURSOR, n, ((bt) == NULL) ? NULL : ((WT_BTREE *)(bt))->dhandle); \
Expand Down
9 changes: 9 additions & 0 deletions test/suite/test_cursor06.py
Expand Up @@ -97,5 +97,14 @@ def test_reconfigure_readonly(self):
cursor.update()
cursor.close()

def test_reconfigure_invalid(self):
uri = self.type + self.name
self.populate(uri)
c = self.session.open_cursor(uri, None, None)
c.reconfigure("overwrite=1")
msg = '/Invalid argument/'
self.assertRaisesWithMessage(wiredtiger.WiredTigerError,
lambda: c.reconfigure("xxx=true"), msg)

if __name__ == '__main__':
wttest.run()

0 comments on commit 7ae2a80

Please sign in to comment.