diff options
| author | Edwin Mons <edwin.mons@isode.com> | 2014-05-23 12:52:30 (GMT) |
|---|---|---|
| committer | Swift Review <review@swift.im> | 2014-06-08 09:32:50 (GMT) |
| commit | eb6fdb866e5ffd467ad0f08fb4bcc50a5af37a22 (patch) | |
| tree | bd30aec78656a0d9b49775e4070f3f428dd94cb6 | |
| parent | 58396750ef7639701b3cd2c5c48f7e867ccfd8c7 (diff) | |
| download | swift-contrib-eb6fdb866e5ffd467ad0f08fb4bcc50a5af37a22.zip swift-contrib-eb6fdb866e5ffd467ad0f08fb4bcc50a5af37a22.tar.bz2 | |
Fix crash in Sluift DOMElementConvertor
DOMElementConvertor crashed because the stack wasn't large enough for
deeper nested element trees. Calling lua_checkstack grows the stack if
there's need for it. Normally Lua does this for you, but the
DOMElementConverter can spend quite some time in non-Lua space.
Change-Id: I23e563d49191b1db1204d2f6fa7d30e2e9d05c1f
| -rw-r--r-- | Sluift/ElementConvertors/DOMElementConvertor.cpp | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/Sluift/ElementConvertors/DOMElementConvertor.cpp b/Sluift/ElementConvertors/DOMElementConvertor.cpp index fb1f658..784fcfd 100644 --- a/Sluift/ElementConvertors/DOMElementConvertor.cpp +++ b/Sluift/ElementConvertors/DOMElementConvertor.cpp @@ -3,113 +3,115 @@ * Licensed under the GNU General Public License. * See the COPYING file for more information. */ #include <Sluift/ElementConvertors/DOMElementConvertor.h> #include <iostream> #include <boost/smart_ptr/make_shared.hpp> #include <lua.hpp> #include <Swiften/Base/foreach.h> #include <Swiften/Elements/RawXMLPayload.h> #include <Swiften/Serializer/PayloadSerializer.h> #include <Sluift/Lua/Check.h> #include <Sluift/Lua/LuaUtils.h> #include <Swiften/Parser/XMLParserClient.h> #include <Swiften/Parser/XMLParser.h> #include <Swiften/Parser/AttributeMap.h> #include <Swiften/Parser/Attribute.h> #include <Swiften/Serializer/XML/XMLElement.h> #include <Swiften/Serializer/XML/XMLTextNode.h> #include <Swiften/Serializer/XML/XMLRawTextNode.h> #include <Sluift/Lua/Debug.h> using namespace Swift; namespace { class ParserClient : public XMLParserClient { public: ParserClient(lua_State* L) : L(L), currentIndex(1) { } virtual void handleStartElement( const std::string& element, const std::string& ns, const AttributeMap& attributes) SWIFTEN_OVERRIDE { + lua_checkstack(L, 6); lua_pushnumber(L, currentIndex); lua_newtable(L); lua_pushstring(L, element.c_str()); lua_setfield(L, -2, "tag"); if (!ns.empty()) { lua_pushstring(L, ns.c_str()); lua_setfield(L, -2, "ns"); } if (!attributes.getEntries().empty()) { lua_newtable(L); int i = 1; foreach(const AttributeMap::Entry& entry, attributes.getEntries()) { lua_pushnumber(L, i); lua_newtable(L); lua_pushstring(L, entry.getAttribute().getName().c_str()); lua_setfield(L, -2, "name"); if (!entry.getAttribute().getNamespace().empty()) { lua_pushstring(L, entry.getAttribute().getNamespace().c_str()); lua_setfield(L, -2, "ns"); } lua_pushstring(L, entry.getValue().c_str()); lua_setfield(L, -2, "value"); lua_settable(L, -3); ++i; } lua_setfield(L, -2, "attributes"); } indexStack.push_back(currentIndex); currentIndex = 1; lua_newtable(L); } virtual void handleEndElement( const std::string&, const std::string&) SWIFTEN_OVERRIDE { lua_setfield(L, -2, "children"); lua_settable(L, -3); currentIndex = indexStack.back(); indexStack.pop_back(); currentIndex++; } virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE { + lua_checkstack(L, 2); lua_pushnumber(L, currentIndex); lua_pushstring(L, data.c_str()); lua_settable(L, -3); currentIndex++; } private: lua_State* L; std::vector<int> indexStack; int currentIndex; }; std::string serializeElement(lua_State* L) { std::string tag; lua_getfield(L, -1, "tag"); if (lua_isstring(L, -1)) { tag = lua_tostring(L, -1); } lua_pop(L, 1); std::string ns; lua_getfield(L, -1, "ns"); if (lua_isstring(L, -1)) { ns = lua_tostring(L, -1); } lua_pop(L, 1); XMLElement element(tag, ns); lua_getfield(L, -1, "attributes"); if (lua_istable(L, -1)) { int index = Lua::absoluteOffset(L, -1); for (lua_pushnil(L); lua_next(L, index) != 0; ) { if (lua_istable(L, -1)) { std::string attributeName; |
Swift