summaryrefslogtreecommitdiff
path: root/backport-Simplify-rpm_print-fixing-a-Lua-stack-leak-as-a-bonu.patch
diff options
context:
space:
mode:
authorCoprDistGit <infra@openeuler.org>2023-09-10 03:05:12 +0000
committerCoprDistGit <infra@openeuler.org>2023-09-10 03:05:12 +0000
commit2bc2b430bc4c1a9a0bfd1c01da68bd53bf7da052 (patch)
treea2af4fd609c7decacbf0ea11926ea338596fb179 /backport-Simplify-rpm_print-fixing-a-Lua-stack-leak-as-a-bonu.patch
parent0ae9f87336a3d78d8fbc0a1e5c75cba5f9cf8597 (diff)
automatic import of rpm
Diffstat (limited to 'backport-Simplify-rpm_print-fixing-a-Lua-stack-leak-as-a-bonu.patch')
-rw-r--r--backport-Simplify-rpm_print-fixing-a-Lua-stack-leak-as-a-bonu.patch39
1 files changed, 39 insertions, 0 deletions
diff --git a/backport-Simplify-rpm_print-fixing-a-Lua-stack-leak-as-a-bonu.patch b/backport-Simplify-rpm_print-fixing-a-Lua-stack-leak-as-a-bonu.patch
new file mode 100644
index 0000000..c0f0968
--- /dev/null
+++ b/backport-Simplify-rpm_print-fixing-a-Lua-stack-leak-as-a-bonu.patch
@@ -0,0 +1,39 @@
+From d41143cb5f6d88eb6e8bd999ad5ea2992bfb10f7 Mon Sep 17 00:00:00 2001
+From: Panu Matilainen <pmatilai@redhat.com>
+Date: Thu, 18 Nov 2021 13:38:20 +0200
+Subject: [PATCH] Simplify rpm_print(), fixing a Lua stack leak as a bonus
+
+Rather than laborously call tostring() in Lua, use the C-side equivalent
+of luaL_tostring(). This was new as of Lua 5.2, which explains why the
+original version from 2004 did things the hard way.
+
+Also fixes a stack leak from not popping "tostring" function after use.
+---
+ rpmio/rpmlua.c | 9 +--------
+ 1 file changed, 1 insertion(+), 8 deletions(-)
+
+diff --git a/rpmio/rpmlua.c b/rpmio/rpmlua.c
+index 6ad9119..7402307 100644
+--- a/rpmio/rpmlua.c
++++ b/rpmio/rpmlua.c
+@@ -688,16 +688,9 @@ static int rpm_print (lua_State *L)
+ int n = lua_gettop(L); /* number of arguments */
+ int i;
+ if (!lua) return 0;
+- lua_getglobal(L, "tostring");
+ for (i = 1; i <= n; i++) {
+- const char *s;
+ size_t sl;
+- lua_pushvalue(L, -1); /* function to be called */
+- lua_pushvalue(L, i); /* value to print */
+- lua_call(L, 1, 1);
+- s = lua_tolstring(L, -1, &sl); /* get result */
+- if (s == NULL)
+- return luaL_error(L, "`tostring' must return a string to `print'");
++ const char *s = luaL_tolstring(L, i, &sl);
+ if (lua->printbuf) {
+ rpmluapb prbuf = lua->printbuf;
+ if (prbuf->used+sl+1 > prbuf->alloced) {
+--
+1.8.3.1
+