summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Andres Klode <julian.klode@canonical.com>2024-11-11 13:53:59 +0100
committerJulian Andres Klode <julian.klode@canonical.com>2024-11-18 21:11:18 +0100
commitb888c66c7244de9b20d174555ffdc22829d6c222 (patch)
tree5179721de1b6683f47802e881f30f580d0b7b7bb
parent963efeff8778afacef35f69c181d234e0a27d5d3 (diff)
ftparchive: override: Remove fixed-size line buffers
LP: #2087848
-rw-r--r--ftparchive/override.cc12
-rwxr-xr-xtest/integration/test-apt-ftparchive-cachedb19
2 files changed, 26 insertions, 5 deletions
diff --git a/ftparchive/override.cc b/ftparchive/override.cc
index 02d1566c8..a6768d9d9 100644
--- a/ftparchive/override.cc
+++ b/ftparchive/override.cc
@@ -36,9 +36,10 @@ bool Override::ReadOverride(string const &File,bool const &Source)
if (F == 0)
return _error->Errno("fopen",_("Unable to open %s"),File.c_str());
- char Line[1000];
+ char *Line = nullptr;
+ size_t LineSize = 0;
unsigned long long Counter = 0;
- while (fgets(Line,sizeof(Line),F) != 0)
+ while (getline(&Line, &LineSize, F) != -1)
{
Counter++;
Item Itm;
@@ -124,6 +125,7 @@ bool Override::ReadOverride(string const &File,bool const &Source)
if (ferror(F))
_error->Errno("fgets",_("Failed to read the override file %s"),File.c_str());
+ free(Line);
fclose(F);
return true;
}
@@ -140,9 +142,10 @@ bool Override::ReadExtraOverride(string const &File,bool const &/*Source*/)
if (F == 0)
return _error->Errno("fopen",_("Unable to open %s"),File.c_str());
- char Line[1000];
+ char *Line = nullptr;
+ size_t LineSize = 0;
unsigned long long Counter = 0;
- while (fgets(Line,sizeof(Line),F) != 0)
+ while (getline(&Line, &LineSize, F) != -1)
{
Counter++;
@@ -198,6 +201,7 @@ bool Override::ReadExtraOverride(string const &File,bool const &/*Source*/)
if (ferror(F))
_error->Errno("fgets",_("Failed to read the override file %s"),File.c_str());
+ free(Line);
fclose(F);
return true;
}
diff --git a/test/integration/test-apt-ftparchive-cachedb b/test/integration/test-apt-ftparchive-cachedb
index 73d762cc8..e1cd9867d 100755
--- a/test/integration/test-apt-ftparchive-cachedb
+++ b/test/integration/test-apt-ftparchive-cachedb
@@ -33,6 +33,8 @@ mkdir -p aptarchive/dists/test/main/binary-i386
mkdir -p aptarchive/pool/main
mkdir aptarchive-overrides
+touch aptarchive-overrides/bin-override
+touch aptarchive-overrides/extra-override
mkdir aptarchive-cache
cat > ftparchive.conf <<"EOF"
Dir {
@@ -60,7 +62,8 @@ TreeDefault {
Tree "dists/test" {
Sections "main";
Architectures "i386";
-
+ BinOverride "bin-override";
+ ExtraOverride "extra-override";
};
EOF
@@ -94,6 +97,19 @@ ensure_correct_contents_file
testsuccessequal ' Misses in Cache: 0
dists/test/Contents-i386: New 402 B Misses in Cache: 0' grep Misses stats-out.txt
+msgmsg "Test overrides"
+
+manyX=$(head -c2000 /dev/zero | tr '\0' 'X')
+
+echo "foo priority${manyX} overrideSection" > aptarchive-overrides/bin-override
+echo "foo Extra ${manyX}trailer" > aptarchive-overrides/extra-override
+
+testsuccess aptftparchive generate ftparchive.conf -o APT::FTPArchive::ShowCacheMisses=1
+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
+
+msgmsg "Test Clean"
# and clean
rm -rf aptarchive/pool/main/*
testsuccessequal "packages-main-i386.db" aptftparchive clean ftparchive.conf
@@ -101,3 +117,4 @@ testsuccess aptftparchive clean ftparchive.conf -o Debug::APT::FTPArchive::Clean
cp rootdir/tmp/testsuccess.output clean-out.txt
testsuccessequal "0 Number of unique keys in the tree" grep unique clean-out.txt
testsuccessequal "packages-main-i386.db" grep packages-main-i386.db clean-out.txt
+