aboutsummaryrefslogtreecommitdiff
path: root/tests/unit/libstore/filetransfer.cc
diff options
context:
space:
mode:
authorLulu <lulu.berlin.2023@gmail.com>2024-10-07 09:43:30 +0200
committerLulu <lulu.berlin.2023@gmail.com>2024-10-08 01:26:30 +0200
commit51a5025913cd2c901203e1a8d8f8a0df1c1a130b (patch)
tree31b6b3b84c745d46b2a3684ab312a73df6580af0 /tests/unit/libstore/filetransfer.cc
parented9b7f4f84fd60ad8618645cc1bae2d686ff0db6 (diff)
Avoid calling memcpy when len == 0 in filetransfer.cc
There was a bug report about a potential call to `memcpy` with a null pointer which is not reproducible: https://git.lix.systems/lix-project/lix/issues/492 This occurred in `src/libstore/filetransfer.cc` in `InnerSource::read`. To ensure that this doesn't happen, an early return is added before calling `memcpy` if the length of the data to be copied is 0. This change also adds a test that ensures that when `InnerSource::read` is called with an empty file, it throws an `EndOfFile` exception. Change-Id: Ia18149bee9a3488576c864f28475a3a0c9eadfbb
Diffstat (limited to 'tests/unit/libstore/filetransfer.cc')
-rw-r--r--tests/unit/libstore/filetransfer.cc8
1 files changed, 8 insertions, 0 deletions
diff --git a/tests/unit/libstore/filetransfer.cc b/tests/unit/libstore/filetransfer.cc
index 71e7392fc..fd4d326f0 100644
--- a/tests/unit/libstore/filetransfer.cc
+++ b/tests/unit/libstore/filetransfer.cc
@@ -150,6 +150,14 @@ TEST(FileTransfer, exceptionAbortsDownload)
}
}
+TEST(FileTransfer, exceptionAbortsRead)
+{
+ auto [port, srv] = serveHTTP("200 ok", "content-length: 0\r\n", [] { return ""; });
+ auto ft = makeFileTransfer();
+ char buf[10] = "";
+ ASSERT_THROW(ft->download(FileTransferRequest(fmt("http://[::1]:%d/index", port)))->read(buf, 10), EndOfFile);
+}
+
TEST(FileTransfer, NOT_ON_DARWIN(reportsSetupErrors))
{
auto [port, srv] = serveHTTP("404 not found", "", [] { return ""; });