Software /
code /
prosody
Changeset
10359:4ef785f45aa2
util.encodings: Strictly verify that the 'strict' *prep argument is a boolean
This is to prevent mistakes like nodeprep(username:gsub("a","b")) from
unintentionally invoking strict mode.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 30 Oct 2019 16:22:44 +0100 |
parents | 10358:a77d9b3885bb |
children | 10360:64ddcbc9a328 |
files | util-src/encodings.c |
diffstat | 1 files changed, 10 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/util-src/encodings.c Mon Sep 09 22:15:04 2019 +0200 +++ b/util-src/encodings.c Wed Oct 30 16:22:44 2019 +0100 @@ -296,8 +296,11 @@ } /* strict */ - if(lua_toboolean(L, 2)) { - flags = 0; + if(!lua_isnoneornil(L, 2)) { + luaL_checktype(L, 2, LUA_TBOOLEAN); + if(lua_toboolean(L, 2)) { + flags = 0; + } } u_strFromUTF8(unprepped, 1024, &unprepped_len, input, input_len, &err); @@ -413,8 +416,11 @@ s = check_utf8(L, 1, &len); /* strict */ - if(lua_toboolean(L, 2)) { - flags = STRINGPREP_NO_UNASSIGNED; + if(!lua_isnoneornil(L, 2)) { + luaL_checktype(L, 2, LUA_TBOOLEAN); + if(lua_toboolean(L, 2)) { + flags = STRINGPREP_NO_UNASSIGNED; + } } if(s == NULL || len >= 1024 || len != strlen(s)) {