aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/filetransfer.cc
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2020-06-18 17:54:16 +0000
committerJohn Ericson <John.Ericson@Obsidian.Systems>2020-06-18 17:54:16 +0000
commit639e20dc3ed9c5b28138285653912de78fe0507f (patch)
tree5f89c2b9814c729c0b63da212a0c70904b40097d /src/libstore/filetransfer.cc
parent6c000eed80565d83d596da800ca0db92e248342e (diff)
Prevent '%' in URL from causing crashes
We have a larger problem that passsing computed strings to the first variable argument of many exception constructors is unsafe because that first variable argument is interpreted not as a plain string, but format string, and if it contains '%' boost::format will abort, since there are no arguments to the format string. In this particular instance '%' was used as part of an escape code in a URL, which, when the download failed, caused Nix to abort displaying the `FileTransferError`.
Diffstat (limited to 'src/libstore/filetransfer.cc')
-rw-r--r--src/libstore/filetransfer.cc17
1 files changed, 7 insertions, 10 deletions
diff --git a/src/libstore/filetransfer.cc b/src/libstore/filetransfer.cc
index 531b85af8..e795da860 100644
--- a/src/libstore/filetransfer.cc
+++ b/src/libstore/filetransfer.cc
@@ -410,16 +410,13 @@ struct curlFileTransfer : public FileTransfer
auto exc =
code == CURLE_ABORTED_BY_CALLBACK && _isInterrupted
- ? FileTransferError(Interrupted, fmt("%s of '%s' was interrupted", request.verb(), request.uri))
+ ? FileTransferError(Interrupted, "%s of '%s' was interrupted", request.verb(), request.uri)
: httpStatus != 0
- ? FileTransferError(err,
- fmt("unable to %s '%s': HTTP error %d",
- request.verb(), request.uri, httpStatus)
- + (code == CURLE_OK ? "" : fmt(" (curl error: %s)", curl_easy_strerror(code)))
- )
- : FileTransferError(err,
- fmt("unable to %s '%s': %s (%d)",
- request.verb(), request.uri, curl_easy_strerror(code), code));
+ ? FileTransferError(err, "unable to %s '%s': HTTP error %d%s",
+ request.verb(), request.uri, httpStatus,
+ code == CURLE_OK ? "" : fmt(" (curl error: %s)", curl_easy_strerror(code)))
+ : FileTransferError(err, "unable to %s '%s': %s (%d)",
+ request.verb(), request.uri, curl_easy_strerror(code), code);
/* If this is a transient error, then maybe retry the
download after a while. If we're writing to a
@@ -675,7 +672,7 @@ struct curlFileTransfer : public FileTransfer
auto s3Res = s3Helper.getObject(bucketName, key);
FileTransferResult res;
if (!s3Res.data)
- throw FileTransferError(NotFound, fmt("S3 object '%s' does not exist", request.uri));
+ throw FileTransferError(NotFound, "S3 object '%s' does not exist", request.uri);
res.data = s3Res.data;
callback(std::move(res));
#else