It is a bad idea to have a map with string_refs as output params.

This is very much unsafe as the string_ref could point on a stack
variable of the callee.
pull/3415/head
Julien Boeuf 9 years ago
parent e456f77644
commit 8b0b6f413d
  1. 2
      include/grpc++/security/auth_metadata_processor.h
  2. 2
      include/grpc++/security/credentials.h
  3. 2
      src/cpp/client/secure_credentials.cc
  4. 8
      test/cpp/end2end/end2end_test.cc

@ -45,7 +45,7 @@ namespace grpc {
class AuthMetadataProcessor { class AuthMetadataProcessor {
public: public:
typedef std::multimap<grpc::string_ref, grpc::string_ref> InputMetadata; typedef std::multimap<grpc::string_ref, grpc::string_ref> InputMetadata;
typedef std::multimap<grpc::string, grpc::string_ref> OutputMetadata; typedef std::multimap<grpc::string, grpc::string> OutputMetadata;
virtual ~AuthMetadataProcessor() {} virtual ~AuthMetadataProcessor() {}

@ -180,7 +180,7 @@ class MetadataCredentialsPlugin {
// Gets the auth metatada produced by this plugin. // Gets the auth metatada produced by this plugin.
virtual Status GetMetadata( virtual Status GetMetadata(
grpc::string_ref service_url, grpc::string_ref service_url,
std::multimap<grpc::string, grpc::string_ref>* metadata) = 0; std::multimap<grpc::string, grpc::string>* metadata) = 0;
}; };
std::shared_ptr<Credentials> MetadataCredentialsFromPlugin( std::shared_ptr<Credentials> MetadataCredentialsFromPlugin(

@ -173,7 +173,7 @@ void MetadataCredentialsPluginWrapper::GetMetadata(
void MetadataCredentialsPluginWrapper::InvokePlugin( void MetadataCredentialsPluginWrapper::InvokePlugin(
const char* service_url, grpc_credentials_plugin_metadata_cb cb, const char* service_url, grpc_credentials_plugin_metadata_cb cb,
void* user_data) { void* user_data) {
std::multimap<grpc::string, grpc::string_ref> metadata; std::multimap<grpc::string, grpc::string> metadata;
Status status = plugin_->GetMetadata(service_url, &metadata); Status status = plugin_->GetMetadata(service_url, &metadata);
std::vector<grpc_metadata> md; std::vector<grpc_metadata> md;
for (auto it = metadata.begin(); it != metadata.end(); ++it) { for (auto it = metadata.begin(); it != metadata.end(); ++it) {

@ -121,7 +121,7 @@ class TestMetadataCredentialsPlugin : public MetadataCredentialsPlugin {
bool IsBlocking() const GRPC_OVERRIDE { return is_blocking_; } bool IsBlocking() const GRPC_OVERRIDE { return is_blocking_; }
Status GetMetadata(grpc::string_ref service_url, Status GetMetadata(grpc::string_ref service_url,
std::multimap<grpc::string, grpc::string_ref>* metadata) std::multimap<grpc::string, grpc::string>* metadata)
GRPC_OVERRIDE { GRPC_OVERRIDE {
EXPECT_GT(service_url.length(), 0UL); EXPECT_GT(service_url.length(), 0UL);
EXPECT_TRUE(metadata != nullptr); EXPECT_TRUE(metadata != nullptr);
@ -175,9 +175,9 @@ class TestAuthMetadataProcessor : public AuthMetadataProcessor {
if (auth_md_value == kGoodGuy) { if (auth_md_value == kGoodGuy) {
context->AddProperty(kIdentityPropName, kGoodGuy); context->AddProperty(kIdentityPropName, kGoodGuy);
context->SetPeerIdentityPropertyName(kIdentityPropName); context->SetPeerIdentityPropertyName(kIdentityPropName);
consumed_auth_metadata->insert( consumed_auth_metadata->insert(std::make_pair(
std::make_pair(string(auth_md->first.data(), auth_md->first.length()), string(auth_md->first.data(), auth_md->first.length()),
auth_md->second)); string(auth_md->second.data(), auth_md->second.length())));
return Status::OK; return Status::OK;
} else { } else {
return Status(StatusCode::UNAUTHENTICATED, return Status(StatusCode::UNAUTHENTICATED,

Loading…
Cancel
Save