- Remove size limit when expanding macros

- Resolves: #1303034
This commit is contained in:
Lubos Kardos 2016-02-26 16:44:43 +01:00
parent afee5b61a3
commit 7a8cd25c20
2 changed files with 127 additions and 1 deletions

View File

@ -0,0 +1,122 @@
diff -up rpm-4.12.0.1/build/files.c.umacros rpm-4.12.0.1/build/files.c
--- rpm-4.12.0.1/build/files.c.umacros 2016-02-29 09:42:04.850077315 +0100
+++ rpm-4.12.0.1/build/files.c 2016-02-29 09:45:10.589560945 +0100
@@ -1590,6 +1590,7 @@ static rpmRC readFilesManifest(rpmSpec s
FILE *fd = NULL;
rpmRC rc = RPMRC_FAIL;
unsigned int nlines = 0;
+ char *expanded;
if (*path == '/') {
fn = rpmGetPath(path, NULL);
@@ -1607,11 +1608,12 @@ static rpmRC readFilesManifest(rpmSpec s
while (fgets(buf, sizeof(buf), fd)) {
if (handleComments(buf))
continue;
- if (expandMacros(spec, spec->macros, buf, sizeof(buf))) {
+ if(rpmExpandMacros(spec->macros, buf, &expanded, 0) < 0) {
rpmlog(RPMLOG_ERR, _("line: %s\n"), buf);
goto exit;
}
- argvAdd(&(pkg->fileList), buf);
+ argvAdd(&(pkg->fileList), expanded);
+ free(expanded);
nlines++;
}
diff -up rpm-4.12.0.1/build/pack.c.umacros rpm-4.12.0.1/build/pack.c
--- rpm-4.12.0.1/build/pack.c.umacros 2016-02-29 09:46:19.502627699 +0100
+++ rpm-4.12.0.1/build/pack.c 2016-02-29 09:49:16.040236952 +0100
@@ -132,11 +132,13 @@ static rpmRC addFileToTag(rpmSpec spec,
}
while (fgets(buf, sizeof(buf), f)) {
- if (expandMacros(spec, spec->macros, buf, sizeof(buf))) {
+ char *expanded;
+ if(rpmExpandMacros(spec->macros, buf, &expanded, 0) < 0) {
rpmlog(RPMLOG_ERR, _("%s: line: %s\n"), fn, buf);
goto exit;
}
- appendStringBuf(sb, buf);
+ appendStringBuf(sb, expanded);
+ free(expanded);
}
headerPutString(h, tag, getStringBuf(sb));
rc = RPMRC_OK;
diff -up rpm-4.12.0.1/build/parseSpec.c.umacros rpm-4.12.0.1/build/parseSpec.c
--- rpm-4.12.0.1/build/parseSpec.c.umacros 2016-02-29 09:50:25.366298100 +0100
+++ rpm-4.12.0.1/build/parseSpec.c 2016-02-29 10:00:07.043817897 +0100
@@ -159,6 +159,7 @@ static int copyNextLineFromOFI(rpmSpec s
{
/* Expand next line from file into line buffer */
if (!(spec->nextline && *spec->nextline)) {
+ char *expanded;
int pc = 0, bc = 0, nc = 0;
const char *from = ofi->readPtr;
char ch = ' ';
@@ -208,11 +209,14 @@ static int copyNextLineFromOFI(rpmSpec s
/* Don't expand macros (eg. %define) in false branch of %if clause */
if (spec->readStack->reading &&
- expandMacros(spec, spec->macros, spec->lbuf, spec->lbufSize)) {
+ (rpmExpandMacros(spec->macros, spec->lbuf, &expanded, 0) < 0)) {
rpmlog(RPMLOG_ERR, _("line %d: %s\n"),
spec->lineNum, spec->lbuf);
return -1;
}
+ free(spec->lbuf);
+ spec->lbuf = expanded;
+ spec->lbufSize = strlen(spec->lbuf) + 1;
spec->nextline = spec->lbuf;
}
return 0;
diff -up rpm-4.12.0.1/rpmio/macro.c.umacros rpm-4.12.0.1/rpmio/macro.c
--- rpm-4.12.0.1/rpmio/macro.c.umacros 2016-02-29 09:31:47.642443073 +0100
+++ rpm-4.12.0.1/rpmio/macro.c 2016-02-29 10:01:58.550338901 +0100
@@ -1462,6 +1462,25 @@ int expandMacros(void * spec, rpmMacroCo
return rc;
}
+
+int rpmExpandMacros(rpmMacroContext mc, const char * sbuf, char ** obuf, int flags)
+{
+ char *target = NULL;
+ int rc;
+
+ mc = rpmmctxAcquire(mc);
+ rc = doExpandMacros(mc, sbuf, &target);
+ rpmmctxRelease(mc);
+
+ if (rc) {
+ free(target);
+ return -1;
+ } else {
+ *obuf = target;
+ return 1;
+ }
+}
+
void
rpmDumpMacroTable(rpmMacroContext mc, FILE * fp)
{
diff -up rpm-4.12.0.1/rpmio/rpmmacro.h.umacros rpm-4.12.0.1/rpmio/rpmmacro.h
--- rpm-4.12.0.1/rpmio/rpmmacro.h.umacros 2016-02-29 09:18:31.244184999 +0100
+++ rpm-4.12.0.1/rpmio/rpmmacro.h 2016-02-29 10:03:29.370134290 +0100
@@ -66,6 +66,17 @@ int expandMacros (void * spec, rpmMacroC
size_t slen);
/** \ingroup rpmmacro
+ * Expand macro into buffer.
+ * @param mc macro context (NULL uses global context).
+ * @param sbuf input macro to expand
+ * @param obuf macro expansion (malloc'ed)
+ * @param flags flags (currently unused)
+ * @return negative on failure
+ */
+int rpmExpandMacros (rpmMacroContext mc, const char * sbuf,
+ char ** obuf, int flags);
+
+/** \ingroup rpmmacro
* Add macro to context.
* @deprecated Use rpmDefineMacro().
* @param mc macro context (NULL uses global context).

View File

@ -27,7 +27,7 @@
Summary: The RPM package management system
Name: rpm
Version: %{rpmver}
Release: %{?snapver:0.%{snapver}.}14%{?dist}
Release: %{?snapver:0.%{snapver}.}15%{?dist}
Group: System Environment/Base
Url: http://www.rpm.org/
Source0: http://rpm.org/releases/rpm-4.12.x/%{name}-%{srcver}.tar.bz2
@ -67,6 +67,7 @@ Patch109: rpm-4.12.0-gpg-passphrase2.patch
Patch110: rpm-4.12.0-Fix-Python3-import.patch
Patch111: rpm-4.12.x-weakdeps-manpage.patch
Patch112: rpm-4.12.0-fix-crash-on-corrupted.patch
Patch113: rpm-4.12.0-unlimited-macro-expand.patch
# These are not yet upstream
Patch302: rpm-4.7.1-geode-i686.patch
@ -551,6 +552,9 @@ exit 0
%doc doc/librpm/html/*
%changelog
* Mon Feb 29 2016 Lubos Kardos <lkardos@redhat.com> - 4.12.0.1-15
- Remove size limit when expanding macros (#1303034)
* Fri Nov 20 2015 Lubos Kardos <lkardos@redhat.com> - 4.12.0.1-14
- Fix crash when parsing corrupted RPM file (#1273360)