Preserve macro scoping level on re-entry from Lua

When a %{lua:...} macro calls rpm.expand(), it re-enters the macro
environment at depth zero regardless of what the "calling" nesting
level was. This could lead to wrong macros getting mopped out on
complex, nested lua + native macro calls.

Store the depth in global macro context and pick up the initial value
from there to keep the nesting level increasing on when entering %{lua:...}
space.
This commit is contained in:
Panu Matilainen 2017-01-20 14:55:59 +02:00
parent f95825ef1b
commit 1767bc4fd8
1 changed files with 6 additions and 1 deletions

View File

@ -58,6 +58,7 @@ struct rpmMacroContext_s {
rpmMacroEntry *tab; /*!< Macro entry table (array of pointers). */ rpmMacroEntry *tab; /*!< Macro entry table (array of pointers). */
int n; /*!< No. of macros. */ int n; /*!< No. of macros. */
unsigned int defcnt; /*!< Non-global define tracking */ unsigned int defcnt; /*!< Non-global define tracking */
int depth; /*!< Depth tracking when recursing from Lua */
pthread_mutex_t lock; pthread_mutex_t lock;
pthread_mutexattr_t lockattr; pthread_mutexattr_t lockattr;
}; };
@ -808,13 +809,17 @@ static void doLua(MacroBuf mb, const char * f, size_t fn, const char * g, size_t
rpmlua lua = NULL; /* Global state. */ rpmlua lua = NULL; /* Global state. */
char *scriptbuf = xmalloc(gn + 1); char *scriptbuf = xmalloc(gn + 1);
char *printbuf; char *printbuf;
rpmMacroContext mc = mb->mc;
int odepth = mc->depth;
if (g != NULL && gn > 0) if (g != NULL && gn > 0)
memcpy(scriptbuf, g, gn); memcpy(scriptbuf, g, gn);
scriptbuf[gn] = '\0'; scriptbuf[gn] = '\0';
rpmluaPushPrintBuffer(lua); rpmluaPushPrintBuffer(lua);
mc->depth = mb->depth;
if (rpmluaRunScript(lua, scriptbuf, NULL) == -1) if (rpmluaRunScript(lua, scriptbuf, NULL) == -1)
mb->error = 1; mb->error = 1;
mc->depth = odepth;
printbuf = rpmluaPopPrintBuffer(lua); printbuf = rpmluaPopPrintBuffer(lua);
if (printbuf) { if (printbuf) {
mbAppendStr(mb, printbuf); mbAppendStr(mb, printbuf);
@ -1305,7 +1310,7 @@ static int doExpandMacros(rpmMacroContext mc, const char *src, char **target)
int rc = 0; int rc = 0;
mb->buf = NULL; mb->buf = NULL;
mb->depth = 0; mb->depth = mc->depth;
mb->macro_trace = print_macro_trace; mb->macro_trace = print_macro_trace;
mb->expand_trace = print_expand_trace; mb->expand_trace = print_expand_trace;
mb->mc = mc; mb->mc = mc;