Fix ages old segfault on trying to expand %{lua} (RhBug:972646)

- Using the already calculated macro arg + arglen for copying the
  buffer instead of buggy local variant helps... This is as old as
  the embedded lua interpreter in rpm, close to a decade.
- Besides fixing the segfault, this actually makes it behave like
  other built-ins, evaluating to empty string when an empty arguments
  or no arguments are passed.
This commit is contained in:
Panu Matilainen 2013-06-11 11:17:21 +03:00
parent 99b40fe5ab
commit ae57958971
1 changed files with 4 additions and 5 deletions

View File

@ -1189,12 +1189,11 @@ expandMacro(MacroBuf mb, const char *src, size_t slen)
#ifdef WITH_LUA
if (STREQ("lua", f, fn)) {
rpmlua lua = NULL; /* Global state. */
const char *ls = s+sizeof("{lua:")-1;
const char *lse = se-sizeof("}")+1;
char *scriptbuf = (char *)xmalloc((lse-ls)+1);
char *scriptbuf = xmalloc(gn + 1);
char *printbuf;
memcpy(scriptbuf, ls, lse-ls);
scriptbuf[lse-ls] = '\0';
if (g != NULL && gn > 0)
memcpy(scriptbuf, g, gn);
scriptbuf[gn] = '\0';
rpmluaPushPrintBuffer(lua);
if (rpmluaRunScript(lua, scriptbuf, NULL) == -1)
rc = 1;