Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hardening/3109 remove payload word part 2 #35

Merged
merged 9 commits into from
Aug 9, 2018
2 changes: 1 addition & 1 deletion src/app/contextBroker/orionRestServices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ static RestService badVerbV[] =
{ InvalidRequest, 2, { "ngsi9", "*" }, badNgsi9Request },
{ InvalidRequest, 2, { "ngsi10", "*" }, badNgsi10Request },
{ InvalidRequest, 0, { "*", "*", "*", "*", "*", "*" }, badRequest },
{ InvalidRequest, 0, { }, NULL },
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the refactor and changes done in this PR has any impact in Developers Manual?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we didn't get down to this level of details in the manual, fortunately ...

{ InvalidRequest, 0, { }, badRequest },

ORION_REST_SERVICE_END
};
Expand Down
13 changes: 11 additions & 2 deletions src/lib/common/string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ bool getIPv6Port(const std::string& in, std::string& outIp, std::string& outPort
*
* stringSplit -
*/
int stringSplit(const std::string& in, char delimiter, std::vector<std::string>& outV)
int stringSplit(const std::string& in, char delimiter, std::vector<std::string>& outV, bool skipLastComponentIfEmpty)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New parameter (skipLastComponentIfEmpty) is a bit obscure... An explantation (or example) in the function preamble would be great.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought the name was descriptive enough ...
It's about not understanding /xxx/ as two components, but one (skip last component if it is empty).
but sure, it's easy enough to comment this in the function header

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 4dfd0c0

{
char* s = strdup(in.c_str());
char* toFree = s;
Expand Down Expand Up @@ -197,10 +197,19 @@ int stringSplit(const std::string& in, char delimiter, std::vector<std::string>&
++s;
}


// 4. pick up all components
for (int ix = 0; ix < components; ix++)
{
// is last component empty?
if (skipLastComponentIfEmpty == true)
{
if ((ix == components - 1) && (*start == 0))
{
components -= 1;
break;
}
}

outV.push_back(start);
start = &start[strlen(start) + 1];
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/common/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ extern bool isIPv6(const std::string& in);
*
* stringSplit -
*/
extern int stringSplit(const std::string& in, char delimiter, std::vector<std::string>& outV);
extern int stringSplit(const std::string& in, char delimiter, std::vector<std::string>& outV, bool skipLastComponentIfEmpty = false);



Expand Down
5 changes: 2 additions & 3 deletions src/lib/jsonParse/jsonRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,13 @@ std::string jsonTreat

if (reqP == NULL)
{
std::string details = std::string("Sorry, no request treating object found for RequestType /") + requestType(request) + "/";
std::string errorReply;
char reqTypeV[STRING_SIZE_FOR_INT];

restErrorReplyGet(ciP, SccBadRequest, details, &errorReply);
restErrorReplyGet(ciP, SccBadRequest, "service not found", &errorReply);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe "service not found" should be a #define? I remember we have a .h with the "magic strings" used in error messages.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 4dfd0c0

snprintf(reqTypeV, sizeof(reqTypeV), "%d", request);

details = std::string("no request treating object found for RequestType ") + reqTypeV + " (" + requestType(request) + ")";
std::string details = std::string("no request treating object found for RequestType ") + reqTypeV + " (" + requestType(request) + ")";
alarmMgr.badInput(clientIp, details);

return errorReply;
Expand Down
15 changes: 14 additions & 1 deletion src/lib/rest/ConnectionInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <stdint.h>
#include <time.h>
#include <sys/time.h>

#include <string>
#include <vector>
#include <map>
Expand Down Expand Up @@ -64,6 +65,7 @@ class ConnectionInfo
ConnectionInfo():
connection (NULL),
verb (NOVERB),
badVerb (false),
inMimeType (JSON),
outMimeType (JSON),
tenant (""),
Expand All @@ -85,6 +87,7 @@ class ConnectionInfo
ConnectionInfo(MimeType _outMimeType):
connection (NULL),
verb (NOVERB),
badVerb (false),
inMimeType (JSON),
outMimeType (_outMimeType),
tenant (""),
Expand All @@ -106,6 +109,7 @@ class ConnectionInfo
ConnectionInfo(std::string _url, std::string _method, std::string _version, MHD_Connection* _connection = NULL):
connection (_connection),
verb (NOVERB),
badVerb (false),
inMimeType (JSON),
outMimeType (JSON),
url (_url),
Expand All @@ -132,23 +136,32 @@ class ConnectionInfo
else if (_method == "DELETE") verb = DELETE;
else if (_method == "PATCH") verb = PATCH;
else if (_method == "OPTIONS") verb = OPTIONS;
else verb = NOVERB;
else
{
badVerb = true;
verb = NOVERB;
}
}

~ConnectionInfo()
{
if (compoundValueRoot != NULL)
{
delete compoundValueRoot;
}

servicePathV.clear();
httpHeaders.release();
}

MHD_Connection* connection;
Verb verb;
bool badVerb;
MimeType inMimeType;
MimeType outMimeType;
std::string url;
int urlComponents;
std::vector<std::string> urlCompV;
std::string method;
std::string version;
std::string charset;
Expand Down
Loading