Skip to content

Commit e79bc40

Browse files
Lejo1SmallJoker
authored andcommittedMay 22, 2020
Check for valid base64 before decoding (#9904)
1 parent 7ab0c06 commit e79bc40

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed
 

‎doc/lua_api.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -5449,7 +5449,7 @@ Misc.
54495449
* Example: `minetest.rgba(10, 20, 30, 40)`, returns `"#0A141E28"`
54505450
* `minetest.encode_base64(string)`: returns string encoded in base64
54515451
* Encodes a string in base64.
5452-
* `minetest.decode_base64(string)`: returns string
5452+
* `minetest.decode_base64(string)`: returns string or nil for invalid base64
54535453
* Decodes a string encoded in base64.
54545454
* `minetest.is_protected(pos, name)`: returns boolean
54555455
* Returning `true` restricts the player `name` from modifying (i.e. digging,

‎src/script/lua_api/l_util.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,13 @@ int ModApiUtil::l_decode_base64(lua_State *L)
318318
NO_MAP_LOCK_REQUIRED;
319319

320320
size_t size;
321-
const char *data = luaL_checklstring(L, 1, &size);
321+
const char *d = luaL_checklstring(L, 1, &size);
322+
const std::string data = std::string(d, size);
323+
324+
if (!base64_is_valid(data))
325+
return 0;
322326

323-
std::string out = base64_decode(std::string(data, size));
327+
std::string out = base64_decode(data);
324328

325329
lua_pushlstring(L, out.data(), out.size());
326330
return 1;

0 commit comments

Comments
 (0)
Please sign in to comment.