From 1f018686505adb9073095e0deef66c17296d02e0 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Mon, 26 Sep 2022 18:36:55 +0300 Subject: [PATCH 40/40] Split freeciv_tolua.patch to logical patches See osdn #45733 Signed-off-by: Marko Lindqvist --- dependencies/tolua-5.2/Makefile.am | 8 +- dependencies/tolua-5.2/Version.txt | 7 +- ...a_tolua_open-prototype-before-needed.patch | 21 +++++ .../freeciv-patch/02-fix-use-after-free.patch | 13 +++ ...03-tolua_bnd_takeownership-prototype.patch | 11 +++ .../04-include-tolua_event.patch | 12 +++ ...generated-code-fix-null-dereferences.patch | 27 +++++++ dependencies/tolua-5.2/freeciv_tolua.patch | 81 ------------------- 8 files changed, 94 insertions(+), 86 deletions(-) create mode 100644 dependencies/tolua-5.2/freeciv-patch/01-tolua_tolua_open-prototype-before-needed.patch create mode 100644 dependencies/tolua-5.2/freeciv-patch/02-fix-use-after-free.patch create mode 100644 dependencies/tolua-5.2/freeciv-patch/03-tolua_bnd_takeownership-prototype.patch create mode 100644 dependencies/tolua-5.2/freeciv-patch/04-include-tolua_event.patch create mode 100644 dependencies/tolua-5.2/freeciv-patch/05-generated-code-fix-null-dereferences.patch delete mode 100644 dependencies/tolua-5.2/freeciv_tolua.patch diff --git a/dependencies/tolua-5.2/Makefile.am b/dependencies/tolua-5.2/Makefile.am index b08dab9e57..b4e41470df 100644 --- a/dependencies/tolua-5.2/Makefile.am +++ b/dependencies/tolua-5.2/Makefile.am @@ -2,5 +2,9 @@ SUBDIRS = src EXTRA_DIST = README \ Version.txt \ - freeciv_tolua.patch \ - include/tolua.h + include/tolua.h \ + freeciv-patch/01-tolua_tolua_open-prototype-before-needed.patch \ + freeciv-patch/02-fix-use-after-free.patch \ + freeciv-patch/03-tolua_bnd_takeownership-prototype.patch \ + freeciv-patch/04-include-tolua_event.patch \ + freeciv-patch/05-generated-code-fix-null-dereferences.patch diff --git a/dependencies/tolua-5.2/Version.txt b/dependencies/tolua-5.2/Version.txt index 1716bba470..d5b45cf21b 100644 --- a/dependencies/tolua-5.2/Version.txt +++ b/dependencies/tolua-5.2/Version.txt @@ -3,6 +3,7 @@ Not entire tolua distribution directory hierarchy is included here, and some files needed for Freeciv usage have been added. Changes applied to included tolua source files are included in -freeciv_tolua.patch -Changes to toluabind.c are not included in the patch - one needs -to regenerate that file after applying the patch. +patches in freeciv-patch -directory. + +Changes to toluabind.c are not included in the patches - one needs +to regenerate that file after applying them. diff --git a/dependencies/tolua-5.2/freeciv-patch/01-tolua_tolua_open-prototype-before-needed.patch b/dependencies/tolua-5.2/freeciv-patch/01-tolua_tolua_open-prototype-before-needed.patch new file mode 100644 index 0000000000..2ee3c1fc98 --- /dev/null +++ b/dependencies/tolua-5.2/freeciv-patch/01-tolua_tolua_open-prototype-before-needed.patch @@ -0,0 +1,21 @@ +diff -Nurd tolua-5.2/src/bin/tolua.c tolua-5.2/src/bin/tolua.c +--- tolua-5.2/src/bin/tolua.c 2022-09-26 18:11:41.769267668 +0300 ++++ tolua-5.2/src/bin/tolua.c 2020-02-22 14:33:47.775736302 +0200 +@@ -22,6 +22,9 @@ + #include + #include + ++#ifndef LUA_SOURCE ++int tolua_tolua_open(lua_State *L); ++#endif + + static void help (void) + { +@@ -106,7 +109,6 @@ + + #ifndef LUA_SOURCE + { +- int tolua_tolua_open (lua_State* L); + tolua_tolua_open(L); + } + #else diff --git a/dependencies/tolua-5.2/freeciv-patch/02-fix-use-after-free.patch b/dependencies/tolua-5.2/freeciv-patch/02-fix-use-after-free.patch new file mode 100644 index 0000000000..a6fb35794c --- /dev/null +++ b/dependencies/tolua-5.2/freeciv-patch/02-fix-use-after-free.patch @@ -0,0 +1,13 @@ +diff -Nurd tolua-5.2/src/lib/tolua_event.c tolua-5.2/src/lib/tolua_event.c +--- tolua-5.2/src/lib/tolua_event.c 2022-09-26 18:17:40.544835582 +0300 ++++ tolua-5.2/src/lib/tolua_event.c 2022-08-29 15:10:32.145383356 +0300 +@@ -393,8 +393,8 @@ + } + else if (lua_isuserdata(L,-1) && *((void**)lua_touserdata(L,-1))==NULL) { + /* free object */ +- free(u); + tolua_release(L,u); /* unmap from tolua tables */ ++ free(u); + } + } + lua_settop(L,top); diff --git a/dependencies/tolua-5.2/freeciv-patch/03-tolua_bnd_takeownership-prototype.patch b/dependencies/tolua-5.2/freeciv-patch/03-tolua_bnd_takeownership-prototype.patch new file mode 100644 index 0000000000..e431bd41bd --- /dev/null +++ b/dependencies/tolua-5.2/freeciv-patch/03-tolua_bnd_takeownership-prototype.patch @@ -0,0 +1,11 @@ +diff -Nurd tolua-5.2/src/lib/tolua_map.c tolua-5.2/src/lib/tolua_map.c +--- tolua-5.2/src/lib/tolua_map.c 2022-09-26 18:19:26.145867532 +0300 ++++ tolua-5.2/src/lib/tolua_map.c 2020-02-22 14:33:47.779735894 +0200 +@@ -21,6 +21,7 @@ + #include + #include + ++int tolua_bnd_takeownership(lua_State *L); + + static char toluaname[128] = "tolua."; + static const char* TOLUANAME (const char* n) diff --git a/dependencies/tolua-5.2/freeciv-patch/04-include-tolua_event.patch b/dependencies/tolua-5.2/freeciv-patch/04-include-tolua_event.patch new file mode 100644 index 0000000000..543d6f6fd6 --- /dev/null +++ b/dependencies/tolua-5.2/freeciv-patch/04-include-tolua_event.patch @@ -0,0 +1,12 @@ +diff -Nurd tolua-5.2/src/lib/tolua_event.c tolua-5.2/src/lib/tolua_event.c +--- tolua-5.2/src/lib/tolua_event.c 2022-09-26 18:20:52.710709210 +0300 ++++ tolua-5.2/src/lib/tolua_event.c 2022-09-26 18:18:49.593511033 +0300 +@@ -18,6 +18,8 @@ + + #include "tolua.h" + ++#include "tolua_event.h" ++ + /* Store at peer + * It stores, creating the corresponding table if needed, + * the pair key/value in the corresponding peer table diff --git a/dependencies/tolua-5.2/freeciv-patch/05-generated-code-fix-null-dereferences.patch b/dependencies/tolua-5.2/freeciv-patch/05-generated-code-fix-null-dereferences.patch new file mode 100644 index 0000000000..bb59af4599 --- /dev/null +++ b/dependencies/tolua-5.2/freeciv-patch/05-generated-code-fix-null-dereferences.patch @@ -0,0 +1,27 @@ +diff -Nurd tolua-5.2/src/bin/lua/variable.lua tolua-5.2/src/bin/lua/variable.lua +--- tolua-5.2/src/bin/lua/variable.lua 2022-09-26 18:23:47.772402128 +0300 ++++ tolua-5.2/src/bin/lua/variable.lua 2022-08-29 15:10:32.145383356 +0300 +@@ -116,7 +116,10 @@ + -- check self value + if class and static==nil then + output('#ifndef TOLUA_RELEASE\n') +- output(' if (!self) tolua_error(tolua_S,"invalid \'self\' in accessing variable \''..self.name..'\'",NULL);'); ++ output(' if (!self) {\n') ++ output(' tolua_error(tolua_S,"invalid \'self\' in accessing variable \''..self.name..'\'",NULL);\n') ++ output(' return 0;\n') ++ output(' }\n') + output('#endif\n') + end + +@@ -163,7 +166,10 @@ + output('#ifndef TOLUA_RELEASE\n') + output(' tolua_Error tolua_err;') + if class and static==nil then +- output(' if (!self) tolua_error(tolua_S,"invalid \'self\' in accessing variable \''..self.name..'\'",NULL);'); ++ output(' if (!self) {\n') ++ output(' tolua_error(tolua_S,"invalid \'self\' in accessing variable \''..self.name..'\'",NULL);\n') ++ output(' return 0;\n') ++ output(' }\n') + elseif static then + _,_,self.mod = strfind(self.mod,'^%s*static%s%s*(.*)') + end diff --git a/dependencies/tolua-5.2/freeciv_tolua.patch b/dependencies/tolua-5.2/freeciv_tolua.patch deleted file mode 100644 index eb9f0144d0..0000000000 --- a/dependencies/tolua-5.2/freeciv_tolua.patch +++ /dev/null @@ -1,81 +0,0 @@ -diff -Nurd tolua-5.2/src/bin/lua/variable.lua tolua-5.2/src/bin/lua/variable.lua ---- tolua-5.2/src/bin/lua/variable.lua 2022-06-19 14:00:07.051434219 +0300 -+++ tolua-5.2/src/bin/lua/variable.lua 2022-06-19 14:01:07.411765219 +0300 -@@ -116,7 +116,10 @@ - -- check self value - if class and static==nil then - output('#ifndef TOLUA_RELEASE\n') -- output(' if (!self) tolua_error(tolua_S,"invalid \'self\' in accessing variable \''..self.name..'\'",NULL);'); -+ output(' if (!self) {\n') -+ output(' tolua_error(tolua_S,"invalid \'self\' in accessing variable \''..self.name..'\'",NULL);\n') -+ output(' return 0;\n') -+ output(' }\n') - output('#endif\n') - end - -@@ -163,7 +166,10 @@ - output('#ifndef TOLUA_RELEASE\n') - output(' tolua_Error tolua_err;') - if class and static==nil then -- output(' if (!self) tolua_error(tolua_S,"invalid \'self\' in accessing variable \''..self.name..'\'",NULL);'); -+ output(' if (!self) {\n') -+ output(' tolua_error(tolua_S,"invalid \'self\' in accessing variable \''..self.name..'\'",NULL);\n') -+ output(' return 0;\n') -+ output(' }\n') - elseif static then - _,_,self.mod = strfind(self.mod,'^%s*static%s%s*(.*)') - end -diff -Nurd tolua-5.2/src/bin/tolua.c tolua-5.2/src/bin/tolua.c ---- tolua-5.2/src/bin/tolua.c 2022-06-19 14:00:07.051434219 +0300 -+++ tolua-5.2/src/bin/tolua.c 2020-02-22 14:33:47.775736302 +0200 -@@ -22,6 +22,9 @@ - #include - #include - -+#ifndef LUA_SOURCE -+int tolua_tolua_open(lua_State *L); -+#endif - - static void help (void) - { -@@ -106,7 +109,6 @@ - - #ifndef LUA_SOURCE - { -- int tolua_tolua_open (lua_State* L); - tolua_tolua_open(L); - } - #else -diff -Nurd tolua-5.2/src/lib/tolua_event.c tolua-5.2/src/lib/tolua_event.c ---- tolua-5.2/src/lib/tolua_event.c 2022-06-19 14:00:07.051434219 +0300 -+++ tolua-5.2/src/lib/tolua_event.c 2022-03-19 10:33:00.694585520 +0200 -@@ -18,6 +18,8 @@ - - #include "tolua.h" - -+#include "tolua_event.h" -+ - /* Store at peer - * It stores, creating the corresponding table if needed, - * the pair key/value in the corresponding peer table -@@ -391,8 +393,8 @@ - } - else if (lua_isuserdata(L,-1) && *((void**)lua_touserdata(L,-1))==NULL) { - /* free object */ -- free(u); - tolua_release(L,u); /* unmap from tolua tables */ -+ free(u); - } - } - lua_settop(L,top); -diff -Nurd tolua-5.2/src/lib/tolua_map.c tolua-5.2/src/lib/tolua_map.c ---- tolua-5.2/src/lib/tolua_map.c 2022-06-19 14:00:07.051434219 +0300 -+++ tolua-5.2/src/lib/tolua_map.c 2020-02-22 14:33:47.779735894 +0200 -@@ -21,6 +21,7 @@ - #include - #include - -+int tolua_bnd_takeownership(lua_State *L); - - static char toluaname[128] = "tolua."; - static const char* TOLUANAME (const char* n) -- 2.35.1