Remove size limit when expanding macros

This removes a seemingly undocumented, and not even well defined, limit
on the size of a macro expansion when parsing a spec file.

[lkardos@redhat.com: created new funtion expandMacrosU() (Unlimited)
instead of modifying expandMacros() in order not to change API/ABI]

Signed-off-by: Lubos Kardos <lkardos@redhat.com>
This commit is contained in:
Tom Hughes 2015-11-17 17:36:16 +00:00 committed by Lubos Kardos
parent 36a681d107
commit 61838b0fda
5 changed files with 43 additions and 8 deletions

View File

@ -1631,11 +1631,13 @@ static rpmRC readFilesManifest(rpmSpec spec, Package pkg, const char *path)
while (fgets(buf, sizeof(buf), fd)) { while (fgets(buf, sizeof(buf), fd)) {
if (handleComments(buf)) if (handleComments(buf))
continue; continue;
if (expandMacros(spec, spec->macros, buf, sizeof(buf))) { char *expanded = expandMacrosU(spec, spec->macros, buf);
if (expanded == NULL) {
rpmlog(RPMLOG_ERR, _("line: %s\n"), buf); rpmlog(RPMLOG_ERR, _("line: %s\n"), buf);
goto exit; goto exit;
} }
argvAdd(&(pkg->fileList), buf); argvAdd(&(pkg->fileList), expanded);
free(expanded);
nlines++; nlines++;
} }

View File

@ -132,11 +132,13 @@ static rpmRC addFileToTag(rpmSpec spec, const char * file,
} }
while (fgets(buf, sizeof(buf), f)) { while (fgets(buf, sizeof(buf), f)) {
if (expandMacros(spec, spec->macros, buf, sizeof(buf))) { char *expanded = expandMacrosU(spec, spec->macros, buf);
if (expanded == NULL) {
rpmlog(RPMLOG_ERR, _("%s: line: %s\n"), fn, buf); rpmlog(RPMLOG_ERR, _("%s: line: %s\n"), fn, buf);
goto exit; goto exit;
} }
appendStringBuf(sb, buf); appendStringBuf(sb, expanded);
free(expanded);
} }
headerPutString(h, tag, getStringBuf(sb)); headerPutString(h, tag, getStringBuf(sb));
rc = RPMRC_OK; rc = RPMRC_OK;

View File

@ -180,13 +180,15 @@ static int expandMacrosInSpecBuf(rpmSpec spec, int strip)
if (lbuf[0] == '#') if (lbuf[0] == '#')
isComment = 1; isComment = 1;
lbuf = xstrdup(spec->lbuf); lbuf = spec->lbuf;
rc = expandMacros(spec, spec->macros, spec->lbuf, spec->lbufSize); spec->lbuf = expandMacrosU(spec, spec->macros, lbuf);
if (rc) { if (spec->lbuf == NULL) {
rpmlog(RPMLOG_ERR, _("line %d: %s\n"), rpmlog(RPMLOG_ERR, _("line %d: %s\n"),
spec->lineNum, spec->lbuf); spec->lineNum, lbuf);
goto exit; goto exit;
} else {
spec->lbufSize = strlen(spec->lbuf) + 1;
} }
if (strip & STRIP_COMMENTS && isComment) { if (strip & STRIP_COMMENTS && isComment) {

View File

@ -1471,6 +1471,23 @@ int expandMacros(void * spec, rpmMacroContext mc, char * sbuf, size_t slen)
return rc; return rc;
} }
char *expandMacrosU(void * spec, rpmMacroContext mc, char * sbuf)
{
char *target = NULL;
int rc;
mc = rpmmctxAcquire(mc);
rc = doExpandMacros(mc, sbuf, &target);
rpmmctxRelease(mc);
if (rc) {
free(target);
target = NULL;
}
return target;
}
void void
rpmDumpMacroTable(rpmMacroContext mc, FILE * fp) rpmDumpMacroTable(rpmMacroContext mc, FILE * fp)
{ {

View File

@ -65,6 +65,18 @@ int expandMacros (void * spec, rpmMacroContext mc,
char * sbuf, char * sbuf,
size_t slen); size_t slen);
/** \ingroup rpmmacro
* Expand macro into buffer.
* @deprecated Use rpmExpand().
* @todo Eliminate from API.
* @param spec cookie (unused)
* @param mc macro context (NULL uses global context).
* @retval sbuf input macro to expand
* @return macro expansion (malloc'ed) or NULL on failure
*/
char *expandMacrosU (void * spec, rpmMacroContext mc,
char * sbuf);
/** \ingroup rpmmacro /** \ingroup rpmmacro
* Add macro to context. * Add macro to context.
* @deprecated Use rpmDefineMacro(). * @deprecated Use rpmDefineMacro().