From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 8B8EB24FB9 for ; Mon, 21 Jan 2019 21:13:01 -0500 (EST) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id g1VxIMjqsoZW for ; Mon, 21 Jan 2019 21:13:01 -0500 (EST) Received: from smtpng1.m.smailru.net (smtpng1.m.smailru.net [94.100.181.251]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id 4493B24E49 for ; Mon, 21 Jan 2019 21:13:01 -0500 (EST) From: Alexander Turenko Subject: [tarantool-patches] [PATCH v2 1/3] lua-yaml: verify arguments count Date: Tue, 22 Jan 2019 05:12:52 +0300 Message-Id: <58ccdb031d0befd0e80d50a4684f5e7a59182062.1548123025.git.alexander.turenko@tarantool.org> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-help: List-unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-subscribe: List-owner: List-post: List-archive: To: Vladislav Shpilevoy Cc: AKhatskevich , tarantool-patches@freelists.org From: AKhatskevich Added arguments count check for yaml.encode() and decode.decode() functions. Without these checks the functions could read garbage outside of a Lua stack when called w/o arguments. --- third_party/lua-yaml/lyaml.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/third_party/lua-yaml/lyaml.cc b/third_party/lua-yaml/lyaml.cc index c6d118a79..9b07992d8 100644 --- a/third_party/lua-yaml/lyaml.cc +++ b/third_party/lua-yaml/lyaml.cc @@ -400,7 +400,8 @@ static void load(struct lua_yaml_loader *loader) { */ static int l_load(lua_State *L) { struct lua_yaml_loader loader; - if (! lua_isstring(L, 1)) { + int top = lua_gettop(L); + if (!(top == 1 || top == 2) || !lua_isstring(L, 1)) { usage_error: return luaL_error(L, "Usage: yaml.decode(document, "\ "[{tag_only = boolean}])"); @@ -416,7 +417,7 @@ usage_error: return luaL_error(L, OOM_ERRMSG); yaml_parser_set_input_string(&loader.parser, (yaml_char_t *) document, len); bool tag_only; - if (lua_gettop(L) > 1) { + if (lua_gettop(L) == 2) { if (! lua_istable(L, 2)) goto usage_error; lua_getfield(L, 2, "tag_only"); @@ -794,7 +795,7 @@ error: static int l_dump(lua_State *L) { struct luaL_serializer *serializer = luaL_checkserializer(L); int top = lua_gettop(L); - if (top > 2) { + if (!(top == 1 || top == 2)) { usage_error: return luaL_error(L, "Usage: encode(object, {tag_prefix = , "\ "tag_handle = })"); -- 2.20.1