Skip to content

Commit

Permalink
change argument to avoid UB in pointer dreference
Browse files Browse the repository at this point in the history
  • Loading branch information
sbiscigl committed Feb 22, 2024
1 parent a2d6cf1 commit f820ee1
Show file tree
Hide file tree
Showing 16 changed files with 52 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace Aws {
explicit S3ExpressIdentityProvider(const S3CrtClient &s3Client) : m_s3Client(s3Client) {}

virtual S3ExpressIdentity
GetS3ExpressIdentity(const Aws::Http::ServiceSpecificParameters &serviceSpecificParameters) = 0;
GetS3ExpressIdentity(const std::shared_ptr<Aws::Http::ServiceSpecificParameters> serviceSpecificParameters) = 0;

virtual ~S3ExpressIdentityProvider() {}

Expand Down Expand Up @@ -53,7 +53,7 @@ namespace Aws {

virtual ~DefaultS3ExpressIdentityProvider() override = default;

S3ExpressIdentity GetS3ExpressIdentity(const Aws::Http::ServiceSpecificParameters &serviceSpecificParameters) override;
S3ExpressIdentity GetS3ExpressIdentity(const std::shared_ptr<Aws::Http::ServiceSpecificParameters> serviceSpecificParameters) override;

private:
mutable std::shared_ptr<Aws::Utils::ConcurrentCache<Aws::String, S3ExpressIdentity>> m_credentialsCache;
Expand All @@ -75,7 +75,7 @@ namespace Aws {

virtual ~DefaultAsyncS3ExpressIdentityProvider() override;

S3ExpressIdentity GetS3ExpressIdentity(const Aws::Http::ServiceSpecificParameters &serviceSpecificParameters) override;
S3ExpressIdentity GetS3ExpressIdentity(const std::shared_ptr<Aws::Http::ServiceSpecificParameters> serviceSpecificParameters) override;

private:
void refreshIdentities(std::chrono::minutes refreshPeriod);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace Aws {
long long expirationInSeconds
) const override;

Aws::Auth::AWSCredentials GetCredentials(const Aws::Http::ServiceSpecificParameters &serviceSpecificParameters) const override;
Aws::Auth::AWSCredentials GetCredentials(const std::shared_ptr<Aws::Http::ServiceSpecificParameters> serviceSpecificParameters) const override;

protected:
bool ServiceRequireUnsignedPayload(const String &serviceName) const override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

using namespace Aws::S3Crt;

static const char* ALLOC_TAG = "S3CrtIdentityProviderAdapter";

aws_s3express_credentials_provider *S3CrtIdentityProviderAdapter::ProviderFactory(struct aws_allocator *allocator,
struct aws_s3_client *client,
aws_simple_completion_callback *on_provider_shutdown_callback,
Expand Down Expand Up @@ -42,7 +44,8 @@ aws_s3express_credentials_provider *S3CrtIdentityProviderAdapter::ProviderFactor
// hostname at this point in theory will always be this way for express hosts.
auto bucketName = hostname.substr(0, hostname.find('.'));
params.emplace("bucketName", bucketName);
Http::ServiceSpecificParameters serviceSpecificParameters{std::move(params)};
const auto serviceSpecificParameters = Aws::MakeShared<Http::ServiceSpecificParameters>("ALLOC_TAG");
serviceSpecificParameters->parameterMap = std::move(params);

//Get creds as raw ptr
auto providerImpl = static_cast<S3ExpressIdentityProvider *>(provider->impl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ Aws::S3Crt::DefaultS3ExpressIdentityProvider::DefaultS3ExpressIdentityProvider(

}

S3ExpressIdentity DefaultS3ExpressIdentityProvider::GetS3ExpressIdentity(const ServiceSpecificParameters &serviceSpecificParameters) {
auto bucketNameIter = serviceSpecificParameters.parameterMap.find("bucketName");
if (bucketNameIter == serviceSpecificParameters.parameterMap.end()) {
S3ExpressIdentity DefaultS3ExpressIdentityProvider::GetS3ExpressIdentity(const std::shared_ptr<Aws::Http::ServiceSpecificParameters> serviceSpecificParameters) {
auto bucketNameIter = serviceSpecificParameters->parameterMap.find("bucketName");
if (bucketNameIter == serviceSpecificParameters->parameterMap.end()) {
AWS_LOGSTREAM_ERROR(S3_EXPRESS_IDENTITY_PROVIDER, "property bucketName Required to make call")
return {"", "", "", {}};
}
Expand Down Expand Up @@ -146,9 +146,9 @@ void DefaultAsyncS3ExpressIdentityProvider::refreshIdentities(std::chrono::minut
}
}

S3ExpressIdentity DefaultAsyncS3ExpressIdentityProvider::GetS3ExpressIdentity(const ServiceSpecificParameters &serviceSpecificParameters) {
auto bucketNameIter = serviceSpecificParameters.parameterMap.find("bucketName");
if (bucketNameIter == serviceSpecificParameters.parameterMap.end()) {
S3ExpressIdentity DefaultAsyncS3ExpressIdentityProvider::GetS3ExpressIdentity(const std::shared_ptr<ServiceSpecificParameters> serviceSpecificParameters) {
auto bucketNameIter = serviceSpecificParameters->parameterMap.find("bucketName");
if (bucketNameIter == serviceSpecificParameters->parameterMap.end()) {
AWS_LOGSTREAM_ERROR(S3_EXPRESS_IDENTITY_PROVIDER, "property bucketName Required to make call")
return {"", "", "", {}};
}
Expand Down
6 changes: 3 additions & 3 deletions generated/src/aws-cpp-sdk-s3-crt/source/S3ExpressSigner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ bool S3ExpressSigner::SignRequest(Aws::Http::HttpRequest &request,
return false;
}
putRequestId(requestId);
auto identity = m_S3ExpressIdentityProvider->GetS3ExpressIdentity(*request.GetServiceSpecificParameters());
auto identity = m_S3ExpressIdentityProvider->GetS3ExpressIdentity(request.GetServiceSpecificParameters());
request.SetHeaderValue(S3_EXPRESS_HEADER, identity.getSessionToken());
auto isSigned = AWSAuthV4Signer::SignRequest(request, region, serviceName, signBody);
deleteRequestId(requestId);
Expand All @@ -80,7 +80,7 @@ bool S3ExpressSigner::PresignRequest(Aws::Http::HttpRequest &request,
return false;
}
putRequestId(requestId);
auto identity = m_S3ExpressIdentityProvider->GetS3ExpressIdentity(*request.GetServiceSpecificParameters());
auto identity = m_S3ExpressIdentityProvider->GetS3ExpressIdentity(request.GetServiceSpecificParameters());
request.AddQueryStringParameter(S3_EXPRESS_QUERY_PARAM, identity.getSessionToken());
auto isSigned = AWSAuthV4Signer::PresignRequest(request, region, serviceName, expirationInSeconds);
deleteRequestId(requestId);
Expand All @@ -91,7 +91,7 @@ bool S3ExpressSigner::ServiceRequireUnsignedPayload(const Aws::String &serviceNa
return S3_EXPRESS_SERVICE_NAME == serviceName || AWSAuthV4Signer::ServiceRequireUnsignedPayload(serviceName);
}

Aws::Auth::AWSCredentials S3ExpressSigner::GetCredentials(const Aws::Http::ServiceSpecificParameters &serviceSpecificParameters) const {
Aws::Auth::AWSCredentials S3ExpressSigner::GetCredentials(const std::shared_ptr<Aws::Http::ServiceSpecificParameters> serviceSpecificParameters) const {
auto identity = m_S3ExpressIdentityProvider->GetS3ExpressIdentity(serviceSpecificParameters);
return {identity.getAccessKeyId(), identity.getSecretKeyId()};
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace Aws {
explicit S3ExpressIdentityProvider(const S3Client &s3Client) : m_s3Client(s3Client) {}

virtual S3ExpressIdentity
GetS3ExpressIdentity(const Aws::Http::ServiceSpecificParameters &serviceSpecificParameters) = 0;
GetS3ExpressIdentity(const std::shared_ptr<Aws::Http::ServiceSpecificParameters> serviceSpecificParameters) = 0;

virtual ~S3ExpressIdentityProvider() {}

Expand Down Expand Up @@ -53,7 +53,7 @@ namespace Aws {

virtual ~DefaultS3ExpressIdentityProvider() override = default;

S3ExpressIdentity GetS3ExpressIdentity(const Aws::Http::ServiceSpecificParameters &serviceSpecificParameters) override;
S3ExpressIdentity GetS3ExpressIdentity(const std::shared_ptr<Aws::Http::ServiceSpecificParameters> serviceSpecificParameters) override;

private:
mutable std::shared_ptr<Aws::Utils::ConcurrentCache<Aws::String, S3ExpressIdentity>> m_credentialsCache;
Expand All @@ -75,7 +75,7 @@ namespace Aws {

virtual ~DefaultAsyncS3ExpressIdentityProvider() override;

S3ExpressIdentity GetS3ExpressIdentity(const Aws::Http::ServiceSpecificParameters &serviceSpecificParameters) override;
S3ExpressIdentity GetS3ExpressIdentity(const std::shared_ptr<Aws::Http::ServiceSpecificParameters> serviceSpecificParameters) override;

private:
void refreshIdentities(std::chrono::minutes refreshPeriod);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace Aws {
long long expirationInSeconds
) const override;

Aws::Auth::AWSCredentials GetCredentials(const Aws::Http::ServiceSpecificParameters &serviceSpecificParameters) const override;
Aws::Auth::AWSCredentials GetCredentials(const std::shared_ptr<Aws::Http::ServiceSpecificParameters> serviceSpecificParameters) const override;

protected:
bool ServiceRequireUnsignedPayload(const String &serviceName) const override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ Aws::S3::DefaultS3ExpressIdentityProvider::DefaultS3ExpressIdentityProvider(

}

S3ExpressIdentity DefaultS3ExpressIdentityProvider::GetS3ExpressIdentity(const ServiceSpecificParameters &serviceSpecificParameters) {
auto bucketNameIter = serviceSpecificParameters.parameterMap.find("bucketName");
if (bucketNameIter == serviceSpecificParameters.parameterMap.end()) {
S3ExpressIdentity DefaultS3ExpressIdentityProvider::GetS3ExpressIdentity(const std::shared_ptr<Aws::Http::ServiceSpecificParameters> serviceSpecificParameters) {
auto bucketNameIter = serviceSpecificParameters->parameterMap.find("bucketName");
if (bucketNameIter == serviceSpecificParameters->parameterMap.end()) {
AWS_LOGSTREAM_ERROR(S3_EXPRESS_IDENTITY_PROVIDER, "property bucketName Required to make call")
return {"", "", "", {}};
}
Expand Down Expand Up @@ -146,9 +146,9 @@ void DefaultAsyncS3ExpressIdentityProvider::refreshIdentities(std::chrono::minut
}
}

S3ExpressIdentity DefaultAsyncS3ExpressIdentityProvider::GetS3ExpressIdentity(const ServiceSpecificParameters &serviceSpecificParameters) {
auto bucketNameIter = serviceSpecificParameters.parameterMap.find("bucketName");
if (bucketNameIter == serviceSpecificParameters.parameterMap.end()) {
S3ExpressIdentity DefaultAsyncS3ExpressIdentityProvider::GetS3ExpressIdentity(const std::shared_ptr<ServiceSpecificParameters> serviceSpecificParameters) {
auto bucketNameIter = serviceSpecificParameters->parameterMap.find("bucketName");
if (bucketNameIter == serviceSpecificParameters->parameterMap.end()) {
AWS_LOGSTREAM_ERROR(S3_EXPRESS_IDENTITY_PROVIDER, "property bucketName Required to make call")
return {"", "", "", {}};
}
Expand Down
6 changes: 3 additions & 3 deletions generated/src/aws-cpp-sdk-s3/source/S3ExpressSigner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ bool S3ExpressSigner::SignRequest(Aws::Http::HttpRequest &request,
return false;
}
putRequestId(requestId);
auto identity = m_S3ExpressIdentityProvider->GetS3ExpressIdentity(*request.GetServiceSpecificParameters());
auto identity = m_S3ExpressIdentityProvider->GetS3ExpressIdentity(request.GetServiceSpecificParameters());
request.SetHeaderValue(S3_EXPRESS_HEADER, identity.getSessionToken());
auto isSigned = AWSAuthV4Signer::SignRequest(request, region, serviceName, signBody);
deleteRequestId(requestId);
Expand All @@ -80,7 +80,7 @@ bool S3ExpressSigner::PresignRequest(Aws::Http::HttpRequest &request,
return false;
}
putRequestId(requestId);
auto identity = m_S3ExpressIdentityProvider->GetS3ExpressIdentity(*request.GetServiceSpecificParameters());
auto identity = m_S3ExpressIdentityProvider->GetS3ExpressIdentity(request.GetServiceSpecificParameters());
request.AddQueryStringParameter(S3_EXPRESS_QUERY_PARAM, identity.getSessionToken());
auto isSigned = AWSAuthV4Signer::PresignRequest(request, region, serviceName, expirationInSeconds);
deleteRequestId(requestId);
Expand All @@ -91,7 +91,7 @@ bool S3ExpressSigner::ServiceRequireUnsignedPayload(const Aws::String &serviceNa
return S3_EXPRESS_SERVICE_NAME == serviceName || AWSAuthV4Signer::ServiceRequireUnsignedPayload(serviceName);
}

Aws::Auth::AWSCredentials S3ExpressSigner::GetCredentials(const Aws::Http::ServiceSpecificParameters &serviceSpecificParameters) const {
Aws::Auth::AWSCredentials S3ExpressSigner::GetCredentials(const std::shared_ptr<Aws::Http::ServiceSpecificParameters> serviceSpecificParameters) const {
auto identity = m_S3ExpressIdentityProvider->GetS3ExpressIdentity(serviceSpecificParameters);
return {identity.getAccessKeyId(), identity.getSecretKeyId()};
}
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ namespace Aws
*/
bool PresignRequest(Aws::Http::HttpRequest& request, const char* region, const char* serviceName, long long expirationInSeconds = 0) const override;

virtual Aws::Auth::AWSCredentials GetCredentials(const Aws::Http::ServiceSpecificParameters &serviceSpecificParameters) const;
virtual Aws::Auth::AWSCredentials GetCredentials(const std::shared_ptr<Aws::Http::ServiceSpecificParameters> serviceSpecificParameters) const;

Aws::String GetServiceName() const { return m_serviceName; }
Aws::String GetRegion() const { return m_region; }
Expand Down
8 changes: 4 additions & 4 deletions src/aws-cpp-sdk-core/source/auth/signer/AWSAuthV4Signer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ AWSAuthV4Signer::~AWSAuthV4Signer()
bool AWSAuthV4Signer::SignRequestWithSigV4a(Aws::Http::HttpRequest& request, const char* region, const char* serviceName,
bool signBody, long long expirationTimeInSeconds, Aws::Crt::Auth::SignatureType signatureType) const
{
AWSCredentials credentials = GetCredentials(*request.GetServiceSpecificParameters());
AWSCredentials credentials = GetCredentials(request.GetServiceSpecificParameters());
auto crtCredentials = Aws::MakeShared<Aws::Crt::Auth::Credentials>(v4AsymmetricLogTag,
Aws::Crt::ByteCursorFromCString(credentials.GetAWSAccessKeyId().c_str()),
Aws::Crt::ByteCursorFromCString(credentials.GetAWSSecretKey().c_str()),
Expand Down Expand Up @@ -191,7 +191,7 @@ bool AWSAuthV4Signer::SignRequest(Aws::Http::HttpRequest& request, const char* r
{
Aws::String signingRegion = region ? region : m_region;
Aws::String signingServiceName = serviceName ? serviceName : m_serviceName;
AWSCredentials credentials = GetCredentials(*request.GetServiceSpecificParameters());
AWSCredentials credentials = GetCredentials(request.GetServiceSpecificParameters());

//don't sign anonymous requests
if (credentials.GetAWSAccessKeyId().empty() || credentials.GetAWSSecretKey().empty())
Expand Down Expand Up @@ -364,7 +364,7 @@ bool AWSAuthV4Signer::PresignRequest(Aws::Http::HttpRequest& request, const char
{
Aws::String signingRegion = region ? region : m_region;
Aws::String signingServiceName = serviceName ? serviceName : m_serviceName;
AWSCredentials credentials = GetCredentials(*request.GetServiceSpecificParameters());
AWSCredentials credentials = GetCredentials(request.GetServiceSpecificParameters());

//don't sign anonymous requests
if (credentials.GetAWSAccessKeyId().empty() || credentials.GetAWSSecretKey().empty())
Expand Down Expand Up @@ -603,7 +603,7 @@ Aws::Utils::ByteBuffer AWSAuthV4Signer::ComputeHash(const Aws::String& secretKey
return hashResult.GetResult();
}

Aws::Auth::AWSCredentials AWSAuthV4Signer::GetCredentials(const Aws::Http::ServiceSpecificParameters &serviceSpecificParameters) const {
Aws::Auth::AWSCredentials AWSAuthV4Signer::GetCredentials(const std::shared_ptr<Aws::Http::ServiceSpecificParameters> serviceSpecificParameters) const {
AWS_UNREFERENCED_PARAM(serviceSpecificParameters);
return m_credentialsProvider->GetAWSCredentials();
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

using namespace Aws::S3Crt;

static const char* ALLOC_TAG = "S3CrtIdentityProviderAdapter";

aws_s3express_credentials_provider *S3CrtIdentityProviderAdapter::ProviderFactory(struct aws_allocator *allocator,
struct aws_s3_client *client,
aws_simple_completion_callback *on_provider_shutdown_callback,
Expand Down Expand Up @@ -39,7 +41,8 @@ aws_s3express_credentials_provider *S3CrtIdentityProviderAdapter::ProviderFactor
// hostname at this point in theory will always be this way for express hosts.
auto bucketName = hostname.substr(0, hostname.find('.'));
params.emplace("bucketName", bucketName);
Http::ServiceSpecificParameters serviceSpecificParameters{std::move(params)};
const auto serviceSpecificParameters = Aws::MakeShared<Http::ServiceSpecificParameters>("ALLOC_TAG");
serviceSpecificParameters->parameterMap = std::move(params);

//Get creds as raw ptr
auto providerImpl = static_cast<S3ExpressIdentityProvider *>(provider->impl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace ${rootNamespace} {
explicit S3ExpressIdentityProvider(const ${metadata.classNamePrefix}Client &s3Client) : m_s3Client(s3Client) {}

virtual S3ExpressIdentity
GetS3ExpressIdentity(const Aws::Http::ServiceSpecificParameters &serviceSpecificParameters) = 0;
GetS3ExpressIdentity(const std::shared_ptr<Aws::Http::ServiceSpecificParameters> serviceSpecificParameters) = 0;

virtual ~S3ExpressIdentityProvider() {}

Expand Down Expand Up @@ -53,7 +53,7 @@ namespace ${rootNamespace} {

virtual ~DefaultS3ExpressIdentityProvider() override = default;

S3ExpressIdentity GetS3ExpressIdentity(const Aws::Http::ServiceSpecificParameters &serviceSpecificParameters) override;
S3ExpressIdentity GetS3ExpressIdentity(const std::shared_ptr<Aws::Http::ServiceSpecificParameters> serviceSpecificParameters) override;

private:
mutable std::shared_ptr<Aws::Utils::ConcurrentCache<Aws::String, S3ExpressIdentity>> m_credentialsCache;
Expand All @@ -75,7 +75,7 @@ namespace ${rootNamespace} {

virtual ~DefaultAsyncS3ExpressIdentityProvider() override;

S3ExpressIdentity GetS3ExpressIdentity(const Aws::Http::ServiceSpecificParameters &serviceSpecificParameters) override;
S3ExpressIdentity GetS3ExpressIdentity(const std::shared_ptr<Aws::Http::ServiceSpecificParameters> serviceSpecificParameters) override;

private:
void refreshIdentities(std::chrono::minutes refreshPeriod);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ Aws::${serviceNamespace}::DefaultS3ExpressIdentityProvider::DefaultS3ExpressIden

}

S3ExpressIdentity DefaultS3ExpressIdentityProvider::GetS3ExpressIdentity(const ServiceSpecificParameters &serviceSpecificParameters) {
auto bucketNameIter = serviceSpecificParameters.parameterMap.find("bucketName");
if (bucketNameIter == serviceSpecificParameters.parameterMap.end()) {
S3ExpressIdentity DefaultS3ExpressIdentityProvider::GetS3ExpressIdentity(const std::shared_ptr<Aws::Http::ServiceSpecificParameters> serviceSpecificParameters) {
auto bucketNameIter = serviceSpecificParameters->parameterMap.find("bucketName");
if (bucketNameIter == serviceSpecificParameters->parameterMap.end()) {
AWS_LOGSTREAM_ERROR(S3_EXPRESS_IDENTITY_PROVIDER, "property bucketName Required to make call")
return {"", "", "", {}};
}
Expand Down Expand Up @@ -146,9 +146,9 @@ void DefaultAsyncS3ExpressIdentityProvider::refreshIdentities(std::chrono::minut
}
}

S3ExpressIdentity DefaultAsyncS3ExpressIdentityProvider::GetS3ExpressIdentity(const ServiceSpecificParameters &serviceSpecificParameters) {
auto bucketNameIter = serviceSpecificParameters.parameterMap.find("bucketName");
if (bucketNameIter == serviceSpecificParameters.parameterMap.end()) {
S3ExpressIdentity DefaultAsyncS3ExpressIdentityProvider::GetS3ExpressIdentity(const std::shared_ptr<ServiceSpecificParameters> serviceSpecificParameters) {
auto bucketNameIter = serviceSpecificParameters->parameterMap.find("bucketName");
if (bucketNameIter == serviceSpecificParameters->parameterMap.end()) {
AWS_LOGSTREAM_ERROR(S3_EXPRESS_IDENTITY_PROVIDER, "property bucketName Required to make call")
return {"", "", "", {}};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace ${rootNamespace} {
long long expirationInSeconds
) const override;

Aws::Auth::AWSCredentials GetCredentials(const Aws::Http::ServiceSpecificParameters &serviceSpecificParameters) const override;
Aws::Auth::AWSCredentials GetCredentials(const std::shared_ptr<Aws::Http::ServiceSpecificParameters> serviceSpecificParameters) const override;

protected:
bool ServiceRequireUnsignedPayload(const String &serviceName) const override;
Expand Down
Loading

0 comments on commit f820ee1

Please sign in to comment.