Lubos Kardos fbda20
From 61838b0fdacb71a881baac164043b8e40ddfbec5 Mon Sep 17 00:00:00 2001
Lubos Kardos fbda20
From: Tom Hughes <tom@compton.nu>
Lubos Kardos fbda20
Date: Tue, 17 Nov 2015 17:36:16 +0000
Lubos Kardos fbda20
Subject: [PATCH] Remove size limit when expanding macros
Lubos Kardos fbda20
Lubos Kardos fbda20
This removes a seemingly undocumented, and not even well defined, limit
Lubos Kardos fbda20
on the size of a macro expansion when parsing a spec file.
Lubos Kardos fbda20
Lubos Kardos fbda20
[lkardos@redhat.com: created new funtion expandMacrosU() (Unlimited)
Lubos Kardos fbda20
instead of modifying expandMacros() in order not to change API/ABI]
Lubos Kardos fbda20
Lubos Kardos fbda20
Signed-off-by: Lubos Kardos <lkardos@redhat.com>
Lubos Kardos fbda20
---
Lubos Kardos fbda20
 build/files.c     |  6 ++++--
Lubos Kardos fbda20
 build/pack.c      |  6 ++++--
Lubos Kardos fbda20
 build/parseSpec.c | 10 ++++++----
Lubos Kardos fbda20
 rpmio/macro.c     | 17 +++++++++++++++++
Lubos Kardos fbda20
 rpmio/rpmmacro.h  | 12 ++++++++++++
Lubos Kardos fbda20
 5 files changed, 43 insertions(+), 8 deletions(-)
Lubos Kardos fbda20
Lubos Kardos fbda20
diff --git a/build/files.c b/build/files.c
Lubos Kardos fbda20
index ea595b9..2fc434e 100644
Lubos Kardos fbda20
--- a/build/files.c
Lubos Kardos fbda20
+++ b/build/files.c
Lubos Kardos fbda20
@@ -1631,11 +1631,13 @@ static rpmRC readFilesManifest(rpmSpec spec, Package pkg, const char *path)
Lubos Kardos fbda20
     while (fgets(buf, sizeof(buf), fd)) {
Lubos Kardos fbda20
 	if (handleComments(buf))
Lubos Kardos fbda20
 	    continue;
Lubos Kardos fbda20
-	if (expandMacros(spec, spec->macros, buf, sizeof(buf))) {
Lubos Kardos fbda20
+	char *expanded = expandMacrosU(spec, spec->macros, buf);
Lubos Kardos fbda20
+	if (expanded == NULL) {
Lubos Kardos fbda20
 	    rpmlog(RPMLOG_ERR, _("line: %s\n"), buf);
Lubos Kardos fbda20
 	    goto exit;
Lubos Kardos fbda20
 	}
Lubos Kardos fbda20
-	argvAdd(&(pkg->fileList), buf);
Lubos Kardos fbda20
+	argvAdd(&(pkg->fileList), expanded);
Lubos Kardos fbda20
+	free(expanded);
Lubos Kardos fbda20
 	nlines++;
Lubos Kardos fbda20
     }
Lubos Kardos fbda20
 
Lubos Kardos fbda20
diff --git a/build/pack.c b/build/pack.c
Lubos Kardos fbda20
index 213d85e..6ffe450 100644
Lubos Kardos fbda20
--- a/build/pack.c
Lubos Kardos fbda20
+++ b/build/pack.c
Lubos Kardos fbda20
@@ -132,11 +132,13 @@ static rpmRC addFileToTag(rpmSpec spec, const char * file,
Lubos Kardos fbda20
     }
Lubos Kardos fbda20
 
Lubos Kardos fbda20
     while (fgets(buf, sizeof(buf), f)) {
Lubos Kardos fbda20
-	if (expandMacros(spec, spec->macros, buf, sizeof(buf))) {
Lubos Kardos fbda20
+	char *expanded = expandMacrosU(spec, spec->macros, buf);
Lubos Kardos fbda20
+	if (expanded == NULL) {
Lubos Kardos fbda20
 	    rpmlog(RPMLOG_ERR, _("%s: line: %s\n"), fn, buf);
Lubos Kardos fbda20
 	    goto exit;
Lubos Kardos fbda20
 	}
Lubos Kardos fbda20
-	appendStringBuf(sb, buf);
Lubos Kardos fbda20
+	appendStringBuf(sb, expanded);
Lubos Kardos fbda20
+	free(expanded);
Lubos Kardos fbda20
     }
Lubos Kardos fbda20
     headerPutString(h, tag, getStringBuf(sb));
Lubos Kardos fbda20
     rc = RPMRC_OK;
Lubos Kardos fbda20
diff --git a/build/parseSpec.c b/build/parseSpec.c
Lubos Kardos fbda20
index edc3d00..610e371 100644
Lubos Kardos fbda20
--- a/build/parseSpec.c
Lubos Kardos fbda20
+++ b/build/parseSpec.c
Lubos Kardos fbda20
@@ -180,13 +180,15 @@ static int expandMacrosInSpecBuf(rpmSpec spec, int strip)
Lubos Kardos fbda20
     if (lbuf[0] == '#')
Lubos Kardos fbda20
 	isComment = 1;
Lubos Kardos fbda20
 
Lubos Kardos fbda20
-    lbuf = xstrdup(spec->lbuf);
Lubos Kardos fbda20
+    lbuf = spec->lbuf;
Lubos Kardos fbda20
 
Lubos Kardos fbda20
-    rc = expandMacros(spec, spec->macros, spec->lbuf, spec->lbufSize);
Lubos Kardos fbda20
-    if (rc) {
Lubos Kardos fbda20
+    spec->lbuf = expandMacrosU(spec, spec->macros, lbuf);
Lubos Kardos fbda20
+    if (spec->lbuf == NULL) {
Lubos Kardos fbda20
 	rpmlog(RPMLOG_ERR, _("line %d: %s\n"),
Lubos Kardos fbda20
-		spec->lineNum, spec->lbuf);
Lubos Kardos fbda20
+		spec->lineNum, lbuf);
Lubos Kardos fbda20
 	goto exit;
Lubos Kardos fbda20
+    } else {
Lubos Kardos fbda20
+	spec->lbufSize = strlen(spec->lbuf) + 1;
Lubos Kardos fbda20
     }
Lubos Kardos fbda20
 
Lubos Kardos fbda20
     if (strip & STRIP_COMMENTS && isComment) {
Lubos Kardos fbda20
diff --git a/rpmio/macro.c b/rpmio/macro.c
Lubos Kardos fbda20
index 4b3c41b..4c8934e 100644
Lubos Kardos fbda20
--- a/rpmio/macro.c
Lubos Kardos fbda20
+++ b/rpmio/macro.c
Lubos Kardos fbda20
@@ -1471,6 +1471,23 @@ int expandMacros(void * spec, rpmMacroContext mc, char * sbuf, size_t slen)
Lubos Kardos fbda20
     return rc;
Lubos Kardos fbda20
 }
Lubos Kardos fbda20
 
Lubos Kardos fbda20
+char *expandMacrosU(void * spec, rpmMacroContext mc, char * sbuf)
Lubos Kardos fbda20
+{
Lubos Kardos fbda20
+    char *target = NULL;
Lubos Kardos fbda20
+    int rc;
Lubos Kardos fbda20
+
Lubos Kardos fbda20
+    mc = rpmmctxAcquire(mc);
Lubos Kardos fbda20
+    rc = doExpandMacros(mc, sbuf, &target);
Lubos Kardos fbda20
+    rpmmctxRelease(mc);
Lubos Kardos fbda20
+
Lubos Kardos fbda20
+    if (rc) {
Lubos Kardos fbda20
+	free(target);
Lubos Kardos fbda20
+	target = NULL;
Lubos Kardos fbda20
+    }
Lubos Kardos fbda20
+
Lubos Kardos fbda20
+    return target;
Lubos Kardos fbda20
+}
Lubos Kardos fbda20
+
Lubos Kardos fbda20
 void
Lubos Kardos fbda20
 rpmDumpMacroTable(rpmMacroContext mc, FILE * fp)
Lubos Kardos fbda20
 {
Lubos Kardos fbda20
diff --git a/rpmio/rpmmacro.h b/rpmio/rpmmacro.h
Lubos Kardos fbda20
index 765c78c..a4884b0 100644
Lubos Kardos fbda20
--- a/rpmio/rpmmacro.h
Lubos Kardos fbda20
+++ b/rpmio/rpmmacro.h
Lubos Kardos fbda20
@@ -66,6 +66,18 @@ int	expandMacros	(void * spec, rpmMacroContext mc,
Lubos Kardos fbda20
 				size_t slen);
Lubos Kardos fbda20
 
Lubos Kardos fbda20
 /** \ingroup rpmmacro
Lubos Kardos fbda20
+ * Expand macro into buffer.
Lubos Kardos fbda20
+ * @deprecated Use rpmExpand().
Lubos Kardos fbda20
+ * @todo Eliminate from API.
Lubos Kardos fbda20
+ * @param spec		cookie (unused)
Lubos Kardos fbda20
+ * @param mc		macro context (NULL uses global context).
Lubos Kardos fbda20
+ * @retval sbuf		input macro to expand
Lubos Kardos fbda20
+ * @return		macro expansion (malloc'ed) or NULL on failure
Lubos Kardos fbda20
+ */
Lubos Kardos fbda20
+char	*expandMacrosU	(void * spec, rpmMacroContext mc,
Lubos Kardos fbda20
+				char * sbuf);
Lubos Kardos fbda20
+
Lubos Kardos fbda20
+/** \ingroup rpmmacro
Lubos Kardos fbda20
  * Add macro to context.
Lubos Kardos fbda20
  * @deprecated Use rpmDefineMacro().
Lubos Kardos fbda20
  * @param mc		macro context (NULL uses global context).
Lubos Kardos fbda20
-- 
Lubos Kardos fbda20
1.9.3
Lubos Kardos fbda20
Lubos Kardos fbda20
From aee8446eb498fec7bfd7a2848ab97440b7bb7226 Mon Sep 17 00:00:00 2001
Lubos Kardos fbda20
From: Tom Hughes <tom@compton.nu>
Lubos Kardos fbda20
Date: Mon, 23 Nov 2015 09:38:37 +0000
Lubos Kardos fbda20
Subject: [PATCH 1/2] Rename expandMacrosU to rpmExpandMacros
Lubos Kardos fbda20
Lubos Kardos fbda20
Address review issues from #32 by renaming the function and
Lubos Kardos fbda20
cleaning up the comment and parameter list.
Lubos Kardos fbda20
---
Lubos Kardos fbda20
 build/files.c     |  2 +-
Lubos Kardos fbda20
 build/pack.c      |  2 +-
Lubos Kardos fbda20
 build/parseSpec.c |  2 +-
Lubos Kardos fbda20
 rpmio/macro.c     |  2 +-
Lubos Kardos fbda20
 rpmio/rpmmacro.h  | 10 ++++------
Lubos Kardos fbda20
 5 files changed, 8 insertions(+), 10 deletions(-)
Lubos Kardos fbda20
Lubos Kardos fbda20
diff --git a/build/files.c b/build/files.c
Lubos Kardos fbda20
index 4d49449..0bc4acc 100644
Lubos Kardos fbda20
--- a/build/files.c
Lubos Kardos fbda20
+++ b/build/files.c
Lubos Kardos fbda20
@@ -1624,7 +1624,7 @@ static rpmRC readFilesManifest(rpmSpec spec, Package pkg, const char *path)
Lubos Kardos fbda20
     while (fgets(buf, sizeof(buf), fd)) {
Lubos Kardos fbda20
 	if (handleComments(buf))
Lubos Kardos fbda20
 	    continue;
Lubos Kardos fbda20
-	char *expanded = expandMacrosU(spec, spec->macros, buf);
Lubos Kardos fbda20
+	char *expanded = rpmExpandMacros(spec->macros, buf, 0);
Lubos Kardos fbda20
 	if (expanded == NULL) {
Lubos Kardos fbda20
 	    rpmlog(RPMLOG_ERR, _("line: %s\n"), buf);
Lubos Kardos fbda20
 	    goto exit;
Lubos Kardos fbda20
diff --git a/build/pack.c b/build/pack.c
Lubos Kardos fbda20
index 6ffe450..ec06bc8 100644
Lubos Kardos fbda20
--- a/build/pack.c
Lubos Kardos fbda20
+++ b/build/pack.c
Lubos Kardos fbda20
@@ -132,7 +132,7 @@ static rpmRC addFileToTag(rpmSpec spec, const char * file,
Lubos Kardos fbda20
     }
Lubos Kardos fbda20
 
Lubos Kardos fbda20
     while (fgets(buf, sizeof(buf), f)) {
Lubos Kardos fbda20
-	char *expanded = expandMacrosU(spec, spec->macros, buf);
Lubos Kardos fbda20
+	char *expanded = rpmExpandMacros(spec->macros, buf, 0);
Lubos Kardos fbda20
 	if (expanded == NULL) {
Lubos Kardos fbda20
 	    rpmlog(RPMLOG_ERR, _("%s: line: %s\n"), fn, buf);
Lubos Kardos fbda20
 	    goto exit;
Lubos Kardos fbda20
diff --git a/build/parseSpec.c b/build/parseSpec.c
Lubos Kardos fbda20
index 610e371..6171bb0 100644
Lubos Kardos fbda20
--- a/build/parseSpec.c
Lubos Kardos fbda20
+++ b/build/parseSpec.c
Lubos Kardos fbda20
@@ -182,7 +182,7 @@ static int expandMacrosInSpecBuf(rpmSpec spec, int strip)
Lubos Kardos fbda20
 
Lubos Kardos fbda20
     lbuf = spec->lbuf;
Lubos Kardos fbda20
 
Lubos Kardos fbda20
-    spec->lbuf = expandMacrosU(spec, spec->macros, lbuf);
Lubos Kardos fbda20
+    spec->lbuf = rpmExpandMacros(spec->macros, lbuf, 0);
Lubos Kardos fbda20
     if (spec->lbuf == NULL) {
Lubos Kardos fbda20
 	rpmlog(RPMLOG_ERR, _("line %d: %s\n"),
Lubos Kardos fbda20
 		spec->lineNum, lbuf);
Lubos Kardos fbda20
diff --git a/rpmio/macro.c b/rpmio/macro.c
Lubos Kardos fbda20
index 4c8934e..f9ca027 100644
Lubos Kardos fbda20
--- a/rpmio/macro.c
Lubos Kardos fbda20
+++ b/rpmio/macro.c
Lubos Kardos fbda20
@@ -1471,7 +1471,7 @@ int expandMacros(void * spec, rpmMacroContext mc, char * sbuf, size_t slen)
Lubos Kardos fbda20
     return rc;
Lubos Kardos fbda20
 }
Lubos Kardos fbda20
 
Lubos Kardos fbda20
-char *expandMacrosU(void * spec, rpmMacroContext mc, char * sbuf)
Lubos Kardos fbda20
+char *rpmExpandMacros(rpmMacroContext mc, const char * sbuf, int flags)
Lubos Kardos fbda20
 {
Lubos Kardos fbda20
     char *target = NULL;
Lubos Kardos fbda20
     int rc;
Lubos Kardos fbda20
diff --git a/rpmio/rpmmacro.h b/rpmio/rpmmacro.h
Lubos Kardos fbda20
index a4884b0..f5ddcac 100644
Lubos Kardos fbda20
--- a/rpmio/rpmmacro.h
Lubos Kardos fbda20
+++ b/rpmio/rpmmacro.h
Lubos Kardos fbda20
@@ -67,15 +67,13 @@ int	expandMacros	(void * spec, rpmMacroContext mc,
Lubos Kardos fbda20
 
Lubos Kardos fbda20
 /** \ingroup rpmmacro
Lubos Kardos fbda20
  * Expand macro into buffer.
Lubos Kardos fbda20
- * @deprecated Use rpmExpand().
Lubos Kardos fbda20
- * @todo Eliminate from API.
Lubos Kardos fbda20
- * @param spec		cookie (unused)
Lubos Kardos fbda20
  * @param mc		macro context (NULL uses global context).
Lubos Kardos fbda20
- * @retval sbuf		input macro to expand
Lubos Kardos fbda20
+ * @param sbuf		input macro to expand
Lubos Kardos fbda20
+ * @param flags		flags (currently unused)
Lubos Kardos fbda20
  * @return		macro expansion (malloc'ed) or NULL on failure
Lubos Kardos fbda20
  */
Lubos Kardos fbda20
-char	*expandMacrosU	(void * spec, rpmMacroContext mc,
Lubos Kardos fbda20
-				char * sbuf);
Lubos Kardos fbda20
+char	*rpmExpandMacros	(rpmMacroContext mc, const char * sbuf,
Lubos Kardos fbda20
+					int flags);
Lubos Kardos fbda20
 
Lubos Kardos fbda20
 /** \ingroup rpmmacro
Lubos Kardos fbda20
  * Add macro to context.
Lubos Kardos fbda20
-- 
Lubos Kardos fbda20
1.9.3
Lubos Kardos fbda20
Lubos Kardos fbda20
From ddf9ec7befe83ba1a12453a56e4e471aa9bcf4d3 Mon Sep 17 00:00:00 2001
Lubos Kardos fbda20
From: Lubos Kardos <lkardos@redhat.com>
Lubos Kardos fbda20
Date: Thu, 26 Nov 2015 15:20:05 +0100
Lubos Kardos fbda20
Subject: [PATCH 2/2] rpmExpandMacros() is modified to be able to return more
Lubos Kardos fbda20
 return codes
Lubos Kardos fbda20
Lubos Kardos fbda20
Now rpmExpandMacros() returns integer as a return value. Negative return
Lubos Kardos fbda20
value implies failure. Return values can be more utilized in the future.
Lubos Kardos fbda20
E. g. return value could specify how many macros were expanded in given
Lubos Kardos fbda20
string.
Lubos Kardos fbda20
---
Lubos Kardos fbda20
 build/files.c     |  4 ++--
Lubos Kardos fbda20
 build/pack.c      |  4 ++--
Lubos Kardos fbda20
 build/parseSpec.c | 21 +++++++++------------
Lubos Kardos fbda20
 rpmio/macro.c     |  9 +++++----
Lubos Kardos fbda20
 rpmio/rpmmacro.h  |  7 ++++---
Lubos Kardos fbda20
 5 files changed, 22 insertions(+), 23 deletions(-)
Lubos Kardos fbda20
Lubos Kardos fbda20
diff --git a/build/files.c b/build/files.c
Lubos Kardos fbda20
index 0bc4acc..d00a785 100644
Lubos Kardos fbda20
--- a/build/files.c
Lubos Kardos fbda20
+++ b/build/files.c
Lubos Kardos fbda20
@@ -1604,6 +1604,7 @@ static rpmRC readFilesManifest(rpmSpec spec, Package pkg, const char *path)
Lubos Kardos fbda20
     FILE *fd = NULL;
Lubos Kardos fbda20
     rpmRC rc = RPMRC_FAIL;
Lubos Kardos fbda20
     unsigned int nlines = 0;
Lubos Kardos fbda20
+    char *expanded;
Lubos Kardos fbda20
 
Lubos Kardos fbda20
     if (*path == '/') {
Lubos Kardos fbda20
 	fn = rpmGetPath(path, NULL);
Lubos Kardos fbda20
@@ -1624,8 +1625,7 @@ static rpmRC readFilesManifest(rpmSpec spec, Package pkg, const char *path)
Lubos Kardos fbda20
     while (fgets(buf, sizeof(buf), fd)) {
Lubos Kardos fbda20
 	if (handleComments(buf))
Lubos Kardos fbda20
 	    continue;
Lubos Kardos fbda20
-	char *expanded = rpmExpandMacros(spec->macros, buf, 0);
Lubos Kardos fbda20
-	if (expanded == NULL) {
Lubos Kardos fbda20
+	if(rpmExpandMacros(spec->macros, buf, &expanded, 0) < 0) {
Lubos Kardos fbda20
 	    rpmlog(RPMLOG_ERR, _("line: %s\n"), buf);
Lubos Kardos fbda20
 	    goto exit;
Lubos Kardos fbda20
 	}
Lubos Kardos fbda20
diff --git a/build/pack.c b/build/pack.c
Lubos Kardos fbda20
index ec06bc8..bfb4c73 100644
Lubos Kardos fbda20
--- a/build/pack.c
Lubos Kardos fbda20
+++ b/build/pack.c
Lubos Kardos fbda20
@@ -132,8 +132,8 @@ static rpmRC addFileToTag(rpmSpec spec, const char * file,
Lubos Kardos fbda20
     }
Lubos Kardos fbda20
 
Lubos Kardos fbda20
     while (fgets(buf, sizeof(buf), f)) {
Lubos Kardos fbda20
-	char *expanded = rpmExpandMacros(spec->macros, buf, 0);
Lubos Kardos fbda20
-	if (expanded == NULL) {
Lubos Kardos fbda20
+	char *expanded;
Lubos Kardos fbda20
+	if(rpmExpandMacros(spec->macros, buf, &expanded, 0) < 0) {
Lubos Kardos fbda20
 	    rpmlog(RPMLOG_ERR, _("%s: line: %s\n"), fn, buf);
Lubos Kardos fbda20
 	    goto exit;
Lubos Kardos fbda20
 	}
Lubos Kardos fbda20
diff --git a/build/parseSpec.c b/build/parseSpec.c
Lubos Kardos fbda20
index 6171bb0..9fff0e2 100644
Lubos Kardos fbda20
--- a/build/parseSpec.c
Lubos Kardos fbda20
+++ b/build/parseSpec.c
Lubos Kardos fbda20
@@ -169,7 +169,7 @@ static int restoreFirstChar(rpmSpec spec)
Lubos Kardos fbda20
 static int expandMacrosInSpecBuf(rpmSpec spec, int strip)
Lubos Kardos fbda20
 {
Lubos Kardos fbda20
     char *lbuf = NULL;
Lubos Kardos fbda20
-    int rc = 0, isComment = 0;
Lubos Kardos fbda20
+    int isComment = 0;
Lubos Kardos fbda20
 
Lubos Kardos fbda20
      /* Don't expand macros (eg. %define) in false branch of %if clause */
Lubos Kardos fbda20
     if (!spec->readStack->reading)
Lubos Kardos fbda20
@@ -180,17 +180,17 @@ static int expandMacrosInSpecBuf(rpmSpec spec, int strip)
Lubos Kardos fbda20
     if (lbuf[0] == '#')
Lubos Kardos fbda20
 	isComment = 1;
Lubos Kardos fbda20
 
Lubos Kardos fbda20
-    lbuf = spec->lbuf;
Lubos Kardos fbda20
 
Lubos Kardos fbda20
-    spec->lbuf = rpmExpandMacros(spec->macros, lbuf, 0);
Lubos Kardos fbda20
-    if (spec->lbuf == NULL) {
Lubos Kardos fbda20
+    if(rpmExpandMacros(spec->macros, spec->lbuf, &lbuf, 0) < 0) {
Lubos Kardos fbda20
 	rpmlog(RPMLOG_ERR, _("line %d: %s\n"),
Lubos Kardos fbda20
-		spec->lineNum, lbuf);
Lubos Kardos fbda20
-	goto exit;
Lubos Kardos fbda20
-    } else {
Lubos Kardos fbda20
-	spec->lbufSize = strlen(spec->lbuf) + 1;
Lubos Kardos fbda20
+		spec->lineNum, spec->lbuf);
Lubos Kardos fbda20
+	return 1;
Lubos Kardos fbda20
     }
Lubos Kardos fbda20
 
Lubos Kardos fbda20
+    free(spec->lbuf);
Lubos Kardos fbda20
+    spec->lbuf = lbuf;
Lubos Kardos fbda20
+    spec->lbufSize = strlen(spec->lbuf) + 1;
Lubos Kardos fbda20
+
Lubos Kardos fbda20
     if (strip & STRIP_COMMENTS && isComment) {
Lubos Kardos fbda20
 	char *bufA = lbuf;
Lubos Kardos fbda20
 	char *bufB = spec->lbuf;
Lubos Kardos fbda20
@@ -212,10 +212,7 @@ static int expandMacrosInSpecBuf(rpmSpec spec, int strip)
Lubos Kardos fbda20
 		spec->lineNum, lbuf);
Lubos Kardos fbda20
     }
Lubos Kardos fbda20
 
Lubos Kardos fbda20
-exit:
Lubos Kardos fbda20
-    free(lbuf);
Lubos Kardos fbda20
-
Lubos Kardos fbda20
-    return rc;
Lubos Kardos fbda20
+    return 0;
Lubos Kardos fbda20
 }
Lubos Kardos fbda20
 
Lubos Kardos fbda20
 /* Return zero on success, 1 if we need to read more and -1 on errors. */
Lubos Kardos fbda20
diff --git a/rpmio/macro.c b/rpmio/macro.c
Lubos Kardos fbda20
index f9ca027..0c009ea 100644
Lubos Kardos fbda20
--- a/rpmio/macro.c
Lubos Kardos fbda20
+++ b/rpmio/macro.c
Lubos Kardos fbda20
@@ -1471,7 +1471,7 @@ int expandMacros(void * spec, rpmMacroContext mc, char * sbuf, size_t slen)
Lubos Kardos fbda20
     return rc;
Lubos Kardos fbda20
 }
Lubos Kardos fbda20
 
Lubos Kardos fbda20
-char *rpmExpandMacros(rpmMacroContext mc, const char * sbuf, int flags)
Lubos Kardos fbda20
+int rpmExpandMacros(rpmMacroContext mc, const char * sbuf, char ** obuf, int flags)
Lubos Kardos fbda20
 {
Lubos Kardos fbda20
     char *target = NULL;
Lubos Kardos fbda20
     int rc;
Lubos Kardos fbda20
@@ -1482,10 +1482,11 @@ char *rpmExpandMacros(rpmMacroContext mc, const char * sbuf, int flags)
Lubos Kardos fbda20
 
Lubos Kardos fbda20
     if (rc) {
Lubos Kardos fbda20
 	free(target);
Lubos Kardos fbda20
-	target = NULL;
Lubos Kardos fbda20
+	return -1;
Lubos Kardos fbda20
+    } else {
Lubos Kardos fbda20
+	*obuf = target;
Lubos Kardos fbda20
+	return 1;
Lubos Kardos fbda20
     }
Lubos Kardos fbda20
-
Lubos Kardos fbda20
-    return target;
Lubos Kardos fbda20
 }
Lubos Kardos fbda20
 
Lubos Kardos fbda20
 void
Lubos Kardos fbda20
diff --git a/rpmio/rpmmacro.h b/rpmio/rpmmacro.h
Lubos Kardos fbda20
index f5ddcac..8027f98 100644
Lubos Kardos fbda20
--- a/rpmio/rpmmacro.h
Lubos Kardos fbda20
+++ b/rpmio/rpmmacro.h
Lubos Kardos fbda20
@@ -69,11 +69,12 @@ int	expandMacros	(void * spec, rpmMacroContext mc,
Lubos Kardos fbda20
  * Expand macro into buffer.
Lubos Kardos fbda20
  * @param mc		macro context (NULL uses global context).
Lubos Kardos fbda20
  * @param sbuf		input macro to expand
Lubos Kardos fbda20
+ * @param obuf		macro expansion (malloc'ed)
Lubos Kardos fbda20
  * @param flags		flags (currently unused)
Lubos Kardos fbda20
- * @return		macro expansion (malloc'ed) or NULL on failure
Lubos Kardos fbda20
+ * @return		negative on failure
Lubos Kardos fbda20
  */
Lubos Kardos fbda20
-char	*rpmExpandMacros	(rpmMacroContext mc, const char * sbuf,
Lubos Kardos fbda20
-					int flags);
Lubos Kardos fbda20
+int	rpmExpandMacros	(rpmMacroContext mc, const char * sbuf,
Lubos Kardos fbda20
+				char ** obuf, int flags);
Lubos Kardos fbda20
 
Lubos Kardos fbda20
 /** \ingroup rpmmacro
Lubos Kardos fbda20
  * Add macro to context.
Lubos Kardos fbda20
-- 
Lubos Kardos fbda20
1.9.3
Lubos Kardos fbda20