summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Andres Klode <julian.klode@canonical.com>2024-11-11 14:09:41 +0100
committerJulian Andres Klode <julian.klode@canonical.com>2024-11-20 15:04:28 +0100
commit709adda89a575e6c542310e6632c090632bb9732 (patch)
treecd53499ae57556e016f3d87dc3e596ec69919fd9
parentb888c66c7244de9b20d174555ffdc22829d6c222 (diff)
ftparchive: cachedb: Remove 600-byte key limit
Instead of snprintf() into a fixed-size buffer, construct an std::string using assign() and append(). A previous version used strprintf() which would have been hilariously inefficient. LP: #2087848
-rw-r--r--ftparchive/cachedb.h7
-rwxr-xr-xtest/integration/test-apt-ftparchive-cachedb32
2 files changed, 36 insertions, 3 deletions
diff --git a/ftparchive/cachedb.h b/ftparchive/cachedb.h
index 98817b9ec..0002c6059 100644
--- a/ftparchive/cachedb.h
+++ b/ftparchive/cachedb.h
@@ -34,7 +34,7 @@ class CacheDB
// Database state/access
DBT Key;
DBT Data;
- char TmpKey[600];
+ std::string TmpKey;
DB *Dbp;
bool DBLoaded;
bool ReadOnly;
@@ -45,8 +45,9 @@ class CacheDB
{
memset(&Key,0,sizeof(Key));
memset(&Data,0,sizeof(Data));
- Key.data = TmpKey;
- Key.size = snprintf(TmpKey,sizeof(TmpKey),"%s:%s",FileName.c_str(), Type);
+ TmpKey.assign(FileName).append(":").append(Type);
+ Key.data = TmpKey.data();
+ Key.size = TmpKey.size();
}
void InitQueryStats() {
diff --git a/test/integration/test-apt-ftparchive-cachedb b/test/integration/test-apt-ftparchive-cachedb
index e1cd9867d..1ba1f23ba 100755
--- a/test/integration/test-apt-ftparchive-cachedb
+++ b/test/integration/test-apt-ftparchive-cachedb
@@ -1,6 +1,11 @@
#!/bin/sh
set -e
+db_dump=db_dump
+if command -v db_dump-5 >/dev/null 2>&1; then
+ db_dump=db_dump-5
+fi
+
ensure_correct_packages_file() {
testequal "Package: foo
Architecture: i386
@@ -109,6 +114,33 @@ testsuccessequal "Priority: priority${manyX}" grep ^Priority ./aptarchive/dists/
testsuccessequal "Section: overrideSection" grep ^Section ./aptarchive/dists/test/main/binary-i386/Packages
testsuccessequal "Extra: ${manyX}trailer" grep ^Extra ./aptarchive/dists/test/main/binary-i386/Packages
+
+msgmsg "Test long paths"
+x128=$(head -c 128 /dev/zero | tr '\0' 'X')
+longPath=${x128}/${x128}/${x128}/${x128}/${x128}/${x128}/${x128}/${x128}
+mkdir -p aptarchive/pool/main/$longPath
+mv aptarchive/pool/main/foo_1_i386.deb aptarchive/pool/main/$longPath/foo_1_i386.deb
+
+# before
+testsuccess $db_dump -f dump -p aptarchive-cache/packages-main-i386.db
+testsuccess grep "^ ./aptarchive/pool/main/foo_1_i386.deb:cl$" dump
+testsuccess grep "^ ./aptarchive/pool/main/foo_1_i386.deb:cn$" dump
+testsuccess grep "^ ./aptarchive/pool/main/foo_1_i386.deb:st$" dump
+
+testsuccess aptftparchive generate ftparchive.conf -o APT::FTPArchive::ShowCacheMisses=1
+
+# file is still found
+testsuccessequal "Filename: pool/main/${longPath}/foo_1_i386.deb" grep ^Filename ./aptarchive/dists/test/main/binary-i386/Packages
+testsuccessequal "Priority: priority${manyX}" grep ^Priority ./aptarchive/dists/test/main/binary-i386/Packages
+testsuccessequal "Section: overrideSection" grep ^Section ./aptarchive/dists/test/main/binary-i386/Packages
+testsuccessequal "Extra: ${manyX}trailer" grep ^Extra ./aptarchive/dists/test/main/binary-i386/Packages
+
+# file is in the database
+testsuccess $db_dump -f dump -p aptarchive-cache/packages-main-i386.db
+testsuccess grep "^ ./aptarchive/pool/main/${longPath}/foo_1_i386.deb:cl$" dump
+testsuccess grep "^ ./aptarchive/pool/main/${longPath}/foo_1_i386.deb:cn$" dump
+testsuccess grep "^ ./aptarchive/pool/main/${longPath}/foo_1_i386.deb:st"$ dump
+
msgmsg "Test Clean"
# and clean
rm -rf aptarchive/pool/main/*