From d56e2453d6335f6909a7a72a6ed3dd64aa9d7508 Mon Sep 17 00:00:00 2001 From: benthompson15 Date: Tue, 13 Oct 2020 11:39:38 -0500 Subject: [PATCH] MCOL-4347: Better handling of getConnection() returning NULL from libmarias3 init. --- storage-manager/src/S3Storage.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/storage-manager/src/S3Storage.cpp b/storage-manager/src/S3Storage.cpp index 700b515e8..117f5def0 100644 --- a/storage-manager/src/S3Storage.cpp +++ b/storage-manager/src/S3Storage.cpp @@ -231,6 +231,12 @@ int S3Storage::getObject(const string &_sourceKey, boost::shared_array string sourceKey = prefix + _sourceKey; ms3_st *creds = getConnection(); + if (!creds) + { + logger->log(LOG_ERR, "S3Storage::getObject(): failed to GET, S3Storage::getConnection() returned NULL on init"); + errno = EINVAL; + return -1; + } ScopedConnection sc(this, creds); do { @@ -325,6 +331,12 @@ int S3Storage::putObject(const boost::shared_array data, size_t len, co string destKey = prefix + _destKey; uint8_t s3err; ms3_st *creds = getConnection(); + if (!creds) + { + logger->log(LOG_ERR, "S3Storage::putObject(): failed to PUT, S3Storage::getConnection() returned NULL on init"); + errno = EINVAL; + return -1; + } ScopedConnection sc(this, creds); do { @@ -363,6 +375,12 @@ int S3Storage::deleteObject(const string &_key) uint8_t s3err; string key = prefix + _key; ms3_st *creds = getConnection(); + if (!creds) + { + logger->log(LOG_ERR, "S3Storage::deleteObject(): failed to DELETE, S3Storage::getConnection() returned NULL on init"); + errno = EINVAL; + return -1; + } ScopedConnection sc(this, creds); do { @@ -401,6 +419,12 @@ int S3Storage::copyObject(const string &_sourceKey, const string &_destKey) string sourceKey = prefix + _sourceKey, destKey = prefix + _destKey; uint8_t s3err; ms3_st *creds = getConnection(); + if (!creds) + { + logger->log(LOG_ERR, "S3Storage::copyObject(): failed to copy, S3Storage::getConnection() returned NULL on init"); + errno = EINVAL; + return -1; + } ScopedConnection sc(this, creds); do @@ -455,6 +479,12 @@ int S3Storage::exists(const string &_key, bool *out) uint8_t s3err; ms3_status_st status; ms3_st *creds = getConnection(); + if (!creds) + { + logger->log(LOG_ERR, "S3Storage::exists(): failed to HEAD, S3Storage::getConnection() returned NULL on init"); + errno = EINVAL; + return -1; + } ScopedConnection sc(this, creds); do {