Skip to content

Commit

Permalink
correct base64 decode buffer length
Browse files Browse the repository at this point in the history
  • Loading branch information
AO-StreetArt committed Dec 14, 2018
1 parent 6514525 commit 8e150ac
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions src/controller/include/scene_handler_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ class SceneHandlerFactory: public Poco::Net::HTTPRequestHandlerFactory {
{config=conf;proc=processor;accounts = accts;event_cache=cache;}
Poco::Net::HTTPRequestHandler* createRequestHandler(const Poco::Net::HTTPServerRequest& request) {
// Authentication Routine
char *buffer = NULL;
// Determine if we have any credentials
bool authentication_failure = false;
if (accounts) {
Expand All @@ -70,36 +69,33 @@ class SceneHandlerFactory: public Poco::Net::HTTPRequestHandlerFactory {
// Pull and decode the authentication info
std::istringstream istr(req_auth_info);
Poco::Base64Decoder b64in(istr);
int length = 100;
buffer = new char[length];
b64in.read(buffer, length);
std::string auth_info_str(buffer);
std::string auth_info_str;
getline(b64in, auth_info_str);
// Split the username and password string
std::stringstream auth_info_stream(auth_info_str);
std::getline(auth_info_stream, username, ':');
std::getline(auth_info_stream, password);

// Actually authenticate against the Account Manager Interface
if (!(accounts->authenticate_user(username, password))) {
// User has failed authentication, return error
Poco::Logger::get("Controller").error("Authentication failed");
authentication_failure = true;
} else {
Poco::Logger::get("Controller").debug("Authentication success");
}
} else {
// invalid auth type
Poco::Logger::get("Controller").error("Invalid authentication type");
authentication_failure = true;
}
}

// Actually authenticate against the Account Manager Interface
if (!(accounts->authenticate_user(username, password))) {
// User has failed authentication, return error
Poco::Logger::get("Controller").error("Authentication failed");
authentication_failure = true;
} else {
Poco::Logger::get("Controller").debug("Authentication success");
}
} else {
// We require credentials but haven't been provided any
Poco::Logger::get("Controller").error("Credentials not provided");
authentication_failure = true;
}
}
if (buffer) delete buffer;
if (authentication_failure) return NULL;

// Parse the URI Path
Expand Down

0 comments on commit 8e150ac

Please sign in to comment.