From 5cdf0d4ce7a703985e776cd38fc0be8ccd6196dc Mon Sep 17 00:00:00 2001 From: Michael Andres Date: Wed, 4 Aug 2010 16:03:40 +0200 Subject: [PATCH] Fix possibly undefined behavior in basearch computation. --- zypp/repo/RepoVariables.cc | 35 ++++++++++------------------------- 1 file changed, 10 insertions(+), 25 deletions(-) diff --git a/zypp/repo/RepoVariables.cc b/zypp/repo/RepoVariables.cc index 51b0701..c93432c 100644 --- a/zypp/repo/RepoVariables.cc +++ b/zypp/repo/RepoVariables.cc @@ -34,36 +34,21 @@ std::string RepoVariablesStringReplacer::operator()( const std::string &value ) string newvalue(value); // $arch - newvalue = str::gsub( newvalue, - "$arch", - ZConfig::instance().systemArchitecture().asString() ); - // $basearch - - Arch::CompatSet cset( Arch::compatSet( ZConfig::instance().systemArchitecture() ) ); - Arch::CompatSet::const_iterator it = cset.end(); - --it; - // now at noarch - --it; + Arch sysarch( ZConfig::instance().systemArchitecture() ); + newvalue = str::gsub( newvalue, "$arch", sysarch.asString() ); - Arch basearch = *it; - if ( basearch == Arch_noarch ) + // $basearch + Arch basearch( sysarch ); + Arch::CompatSet cset( Arch::compatSet( sysarch ) ); + if ( cset.size() > 2 ) // systemArchitecture, ..., basearch, noarch { - basearch = ZConfig::instance().systemArchitecture(); + basearch = *(++++cset.rbegin()); } + newvalue = str::gsub( newvalue, "$basearch", basearch.asString() ); - newvalue = str::gsub( newvalue, - "$basearch", - basearch.asString() ); + // $releasever (Target::distributionVersion assumes root=/ if target not initialized) + newvalue = str::gsub( newvalue, "$releasever", Target::distributionVersion(Pathname()/*guess*/) ); - // only replace $releasever if the target is - // initialized - if ( getZYpp()->getTarget() ) - { - newvalue = str::gsub( newvalue, - "$releasever", - getZYpp()->target()->distributionVersion() ); - } - return newvalue; } -- 2.7.4