This prevents assert-crashes in the C code.
flags = luaL_checkinteger(L, 3);
if (lua_gettop(L) >= 4)
username = luaL_checkstring(L, 4);
+ lua_dict_check_key_prefix(L, path, username);
struct dict_op_settings set = {
.username = username,
dlua_pcall_yieldable_resume(L, 1);
}
+void lua_dict_check_key_prefix(lua_State *L, const char *key,
+ const char *username)
+{
+ if (str_begins(key, DICT_PATH_SHARED))
+ ;
+ else if (str_begins(key, DICT_PATH_PRIVATE)) {
+ if (username == NULL || username[0] == '\0')
+ luaL_error(L, DICT_PATH_PRIVATE" dict key prefix requires username");
+ } else {
+ luaL_error(L, "Invalid dict key prefix");
+ }
+}
+
/*
* Lookup a key in dict [-(2|3),+1,e]
*
key = luaL_checkstring(L, 2);
if (lua_gettop(L) >= 3)
username = luaL_checkstring(L, 3);
+ lua_dict_check_key_prefix(L, key, username);
struct dict_op_settings set = {
.username = username,
* 5.3 and newer.
*/
+void lua_dict_check_key_prefix(lua_State *L, const char *key,
+ const char *username);
+
void dlua_push_dict(lua_State *L, struct dict *dict);
struct dict *dlua_check_dict(lua_State *L, int idx);
} state;
lua_State *L;
+ const char *username;
};
static int lua_dict_transaction_rollback(lua_State *L);
txn = xlua_dict_txn_getptr(L, 1, NULL);
key = luaL_checkstring(L, 2);
value = luaL_checkstring(L, 3);
+ lua_dict_check_key_prefix(L, key, txn->username);
dict_set(txn->txn, key, value);
txn = xlua_dict_txn_getptr(L, 1, NULL);
key = luaL_checkstring(L, 2);
+ lua_dict_check_key_prefix(L, key, txn->username);
dict_unset(txn->txn, key);
txn->txn = dict_transaction_begin(dict, &set);
txn->state = STATE_OPEN;
txn->L = L;
+ txn->username = p_strdup(txn->pool, username);
xlua_pushdict_txn(L, txn, FALSE);