handle pkgnames shorter than modifiers
authorDavid Kalnischkies <david@kalnischkies.de>
Mon, 21 Apr 2014 11:26:55 +0000 (13:26 +0200)
committerDavid Kalnischkies <david@kalnischkies.de>
Sat, 26 Apr 2014 07:51:05 +0000 (09:51 +0200)
The bugreport highlights the problem with an empty package name. We fix
this by 'ignoring' these so that it behaves just like "apt-get install".
The deeper problem is that modifier strings can be longer than a package
name in which case the comparison doesn't make sense, so don't compare
then. Was not noticed so far as all modifiers are of length 1, so the
only package name shorter than this is in fact the empty package name.

Closes: 744940

apt-pkg/cacheset.cc
test/integration/test-ubuntu-bug-365611-long-package-names

index d453a2b..2ed6a96 100644 (file)
@@ -391,6 +391,8 @@ bool VersionContainerInterface::FromModifierCommandLine(unsigned short &modID,
                                                        CacheSetHelper &helper) {
        Version select = NEWEST;
        std::string str = cmdline;
+       if (unlikely(str.empty() == true))
+               return false;
        bool modifierPresent = false;
        unsigned short fallback = modID;
        for (std::list<Modifier>::const_iterator mod = mods.begin();
@@ -400,8 +402,8 @@ bool VersionContainerInterface::FromModifierCommandLine(unsigned short &modID,
                size_t const alength = strlen(mod->Alias);
                switch(mod->Pos) {
                case Modifier::POSTFIX:
-                       if (str.compare(str.length() - alength, alength,
-                                       mod->Alias, 0, alength) != 0)
+                       if (str.length() <= alength ||
+                             str.compare(str.length() - alength, alength, mod->Alias, 0, alength) != 0)
                                continue;
                        str.erase(str.length() - alength);
                        modID = mod->ID;
index 894c8dc..f22986e 100755 (executable)
@@ -4,8 +4,12 @@ set -e
 TESTDIR=$(readlink -f $(dirname $0))
 . $TESTDIR/framework
 setupenvironment
-configarchitecture "i386"
+configarchitecture 'i386'
 setupaptarchive
 
 aptget install $(for i in $(seq 0 1000); do echo -n 'a'; done) 2> longpackagename.log > /dev/null || true
 testfileequal 'longpackagename.log' "E: Unable to locate package $(for i in $(seq 0 1000); do echo -n 'a'; done)"
+
+# … and the opposite of long:
+aptget install "" -s >longpackagename.log 2>&1 || true
+testfileequal 'longpackagename.log' "$(aptget install -s)"