Skip to content

Commit

Permalink
Check for valid base64 before decoding (#9904)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lejo1 authored and SmallJoker committed May 22, 2020
1 parent 7ab0c06 commit e79bc40
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion doc/lua_api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5449,7 +5449,7 @@ Misc.
* Example: `minetest.rgba(10, 20, 30, 40)`, returns `"#0A141E28"`
* `minetest.encode_base64(string)`: returns string encoded in base64
* Encodes a string in base64.
* `minetest.decode_base64(string)`: returns string
* `minetest.decode_base64(string)`: returns string or nil for invalid base64
* Decodes a string encoded in base64.
* `minetest.is_protected(pos, name)`: returns boolean
* Returning `true` restricts the player `name` from modifying (i.e. digging,
Expand Down
8 changes: 6 additions & 2 deletions src/script/lua_api/l_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,13 @@ int ModApiUtil::l_decode_base64(lua_State *L)
NO_MAP_LOCK_REQUIRED;

size_t size;
const char *data = luaL_checklstring(L, 1, &size);
const char *d = luaL_checklstring(L, 1, &size);
const std::string data = std::string(d, size);

if (!base64_is_valid(data))
return 0;

std::string out = base64_decode(std::string(data, size));
std::string out = base64_decode(data);

lua_pushlstring(L, out.data(), out.size());
return 1;
Expand Down

0 comments on commit e79bc40

Please sign in to comment.