From cc74d50a6dadfa30914844e6c4c0513287bf7f68 Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Fri, 5 Dec 2008 13:38:30 +0200 Subject: [PATCH] Tighten up setting and checking of buildroot (ticket #10) - expand, set and verify buildroot just once for after main package preamble is parsed to avoid sub-packages from overriding it - spec can still mess with %buildroot by defining it to something else after preamble but that's another issue... --- build/parsePreamble.c | 21 +++++++++++++++++++++ build/parseSpec.c | 9 --------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/build/parsePreamble.c b/build/parsePreamble.c index 09fd88ca8..33091770e 100644 --- a/build/parsePreamble.c +++ b/build/parsePreamble.c @@ -874,6 +874,27 @@ int parsePreamble(rpmSpec spec, int initialPackage) } } + /* + * Expand buildroot one more time to get %{version} and the like + * from the main package, validate sanity. The spec->buildRoot could + * still contain unexpanded macros but it cannot be empty or '/', and it + * can't be messed with by anything spec does beyond this point. + */ + if (initialPackage) { + char *buildRoot = rpmGetPath(spec->buildRoot, NULL); + if (*buildRoot == '\0') { + rpmlog(RPMLOG_ERR, _("%%{buildroot} couldn't be empty\n")); + goto exit; + } + if (!strcmp(buildRoot, "/")) { + rpmlog(RPMLOG_ERR, _("%%{buildroot} can not be \"/\"\n")); + goto exit; + } + free(spec->buildRoot); + spec->buildRoot = buildRoot; + addMacro(spec->macros, "buildroot", NULL, spec->buildRoot, RMIL_SPEC); + } + /* XXX Skip valid arch check if not building binary package */ if (!spec->anyarch && checkForValidArchitectures(spec)) { goto exit; diff --git a/build/parseSpec.c b/build/parseSpec.c index 11e0622a5..cf22db353 100644 --- a/build/parseSpec.c +++ b/build/parseSpec.c @@ -433,15 +433,6 @@ int parseSpec(rpmts ts, const char *specFile, const char *rootDir, } else { spec->buildRoot = rpmGetPath("%{?buildroot:%{buildroot}}", NULL); } - addMacro(spec->macros, "buildroot", NULL, spec->buildRoot, RMIL_SPEC); - if (*spec->buildRoot == '\0') { - rpmlog(RPMLOG_ERR, _("BuildRoot couldn't be empty\n")); - goto errxit; - } - if (!strcmp(spec->buildRoot, "/")) { - rpmlog(RPMLOG_ERR, _("BuildRoot can not be \"/\"\n")); - goto errxit; - } addMacro(NULL, "_docdir", NULL, "%{_defaultdocdir}", RMIL_SPEC); spec->recursing = recursing; spec->anyarch = anyarch;