summaryrefslogtreecommitdiff
path: root/apt-pkg
diff options
context:
space:
mode:
authorMichael Vogt <mvo@debian.org>2014-08-26 19:08:37 -0700
committerMichael Vogt <mvo@debian.org>2014-08-26 19:08:37 -0700
commitdcd5856b11c685ca6d4629212d2978ce196ea65c (patch)
tree932d7934b144353010d85eff5eb76324b39554c4 /apt-pkg
parent80624be7c54aec6ed98ee254366155024fca1a71 (diff)
Pass ExpectedSize to tthe backend method
This ensures that we can stop downloading if the server send too much data by accident (or by a malicious attempt)
Diffstat (limited to 'apt-pkg')
-rw-r--r--apt-pkg/acquire-method.cc2
-rw-r--r--apt-pkg/acquire-method.h1
-rw-r--r--apt-pkg/acquire-worker.cc4
3 files changed, 7 insertions, 0 deletions
diff --git a/apt-pkg/acquire-method.cc b/apt-pkg/acquire-method.cc
index e4a937d1d..9fc176747 100644
--- a/apt-pkg/acquire-method.cc
+++ b/apt-pkg/acquire-method.cc
@@ -360,6 +360,8 @@ int pkgAcqMethod::Run(bool Single)
if (hash.empty() == false)
Tmp->ExpectedHashes.push_back(HashString(*t, hash));
}
+ char *End;
+ Tmp->ExpectedSize = strtoll(LookupTag(Message, "Expected-Size", "0").c_str(), &End, 10);
Tmp->Next = 0;
// Append it to the list
diff --git a/apt-pkg/acquire-method.h b/apt-pkg/acquire-method.h
index cbf79f860..8a680335e 100644
--- a/apt-pkg/acquire-method.h
+++ b/apt-pkg/acquire-method.h
@@ -48,6 +48,7 @@ class pkgAcqMethod
bool IndexFile;
bool FailIgnore;
HashStringList ExpectedHashes;
+ unsigned long long ExpectedSize;
};
struct FetchResult
diff --git a/apt-pkg/acquire-worker.cc b/apt-pkg/acquire-worker.cc
index 54be8e99f..8bd1618f4 100644
--- a/apt-pkg/acquire-worker.cc
+++ b/apt-pkg/acquire-worker.cc
@@ -526,6 +526,9 @@ bool pkgAcquire::Worker::QueueItem(pkgAcquire::Queue::QItem *Item)
if (OutFd == -1)
return false;
+ string ExpectedSize;
+ strprintf(ExpectedSize, "%llu", Item->Owner->FileSize);
+
string Message = "600 URI Acquire\n";
Message.reserve(300);
Message += "URI: " + Item->URI;
@@ -533,6 +536,7 @@ bool pkgAcquire::Worker::QueueItem(pkgAcquire::Queue::QItem *Item)
HashStringList const hsl = Item->Owner->HashSums();
for (HashStringList::const_iterator hs = hsl.begin(); hs != hsl.end(); ++hs)
Message += "\nExpected-" + hs->HashType() + ": " + hs->HashValue();
+ Message += "\nExpected-Size: " + ExpectedSize;
Message += Item->Owner->Custom600Headers();
Message += "\n\n";