Skip to content

Commit

Permalink
Merge pull request #544 from FIWARE/hardening/remove-value-expansion
Browse files Browse the repository at this point in the history
hardening/remove-value-expansion
  • Loading branch information
kzangeli authored Sep 30, 2020
2 parents c194f18 + f6fa5e1 commit b70f0ad
Show file tree
Hide file tree
Showing 42 changed files with 48 additions and 1,095 deletions.
1 change: 1 addition & 0 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@
* Issue #532 Return error if unknown URI parameter is used
* Issue #527 Bug in update of relationships with datasetId
* Issue #XXX Fixed Release Mode compilation errors in Ubuntu 20.04
* Issue #XXX Removed the feature of expanding attribute values as it doesn't fit with JSON-LD
2 changes: 1 addition & 1 deletion src/lib/mongoBackend/MongoGlobal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1431,7 +1431,7 @@ bool entitiesQuery
//
if (orionldState.uriParams.geoproperty != NULL)
{
attrNameP = orionldContextItemExpand(orionldState.contextP, orionldState.uriParams.geoproperty, NULL, true, NULL);
attrNameP = orionldContextItemExpand(orionldState.contextP, orionldState.uriParams.geoproperty, true, NULL);
dotForEq(attrNameP);
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/orionld/common/qAliasCompact.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ bool qAliasCompact(KjNode* qP, bool compact)
else
{
// Expand the variable
alias = orionldContextItemExpand(orionldState.contextP, varStart, NULL, true, NULL);
alias = orionldContextItemExpand(orionldState.contextP, varStart, true, NULL);
}

if (alias != NULL)
Expand Down
21 changes: 4 additions & 17 deletions src/lib/orionld/common/qParse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ extern "C"
//
// After implementing expansion in metadata names, for attr.b.c, 'b' needs expansion also
//
static char* varFix(char* varPath, bool* valueMayBeExpandedP, char** detailsP)
static char* varFix(char* varPath, char** detailsP)
{
char* cP = varPath;
char* attrNameP = varPath;
Expand All @@ -62,7 +62,6 @@ static char* varFix(char* varPath, bool* valueMayBeExpandedP, char** detailsP)
char* rest = NULL;
char fullPath[1100];

*valueMayBeExpandedP = false;

//
// Cases:
Expand Down Expand Up @@ -207,7 +206,7 @@ static char* varFix(char* varPath, bool* valueMayBeExpandedP, char** detailsP)
//
// All OK - let's compose ...
//
char* longNameP = orionldContextItemExpand(orionldState.contextP, attrNameP, valueMayBeExpandedP, true, NULL);
char* longNameP = orionldContextItemExpand(orionldState.contextP, attrNameP, true, NULL);

//
// Now 'longNameP' needs to be adjusted forthe DB model, that changes '.' for '=' in the database.
Expand All @@ -234,7 +233,7 @@ static char* varFix(char* varPath, bool* valueMayBeExpandedP, char** detailsP)
{
if (strcmp(mdNameP, "observedAt") != 0) // Don't expand "observedAt", nor ...
{
char* mdLongNameP = orionldContextItemExpand(orionldState.contextP, mdNameP, NULL, true, NULL);
char* mdLongNameP = orionldContextItemExpand(orionldState.contextP, mdNameP, true, NULL);

strncpy(mdLongName, mdLongNameP, sizeof(mdLongName) - 1);

Expand Down Expand Up @@ -319,7 +318,6 @@ QNode* qParse(QNode* qLexList, char** titleP, char** detailsP)
QNode* prevP = NULL;
QNode* leftP = NULL;
QNode* expressionStart;
bool valueMayBeExpanded = false;

while (qLexP != NULL)
{
Expand Down Expand Up @@ -364,7 +362,7 @@ QNode* qParse(QNode* qLexList, char** titleP, char** detailsP)
break;

case QNodeVariable:
qLexP->value.v = varFix(qLexP->value.v, &valueMayBeExpanded, detailsP);
qLexP->value.v = varFix(qLexP->value.v, detailsP);
if (qLexP->next == NULL)
{
if (compOpP == NULL)
Expand Down Expand Up @@ -428,9 +426,6 @@ QNode* qParse(QNode* qLexList, char** titleP, char** detailsP)
return NULL;
}

if ((valueP->type == QNodeStringValue) && (valueMayBeExpanded == true))
valueP->value.s = orionldContextItemExpand(orionldState.contextP, valueP->value.s, NULL, true, NULL);

qNodeAppend(commaP, valueP); // OK to enlist commaP and valueP as qLexP point to after valueP
}

Expand All @@ -439,9 +434,6 @@ QNode* qParse(QNode* qLexList, char** titleP, char** detailsP)
//
QNode* valueP = qLexP;

if ((valueP->type == QNodeStringValue) && (valueMayBeExpanded == true))
valueP->value.s = orionldContextItemExpand(orionldState.contextP, valueP->value.s, NULL, true, NULL);

qNodeAppend(commaP, valueP);
}

Expand All @@ -456,12 +448,7 @@ QNode* qParse(QNode* qLexList, char** titleP, char** detailsP)
else if (commaP != NULL)
qNodeAppend(compOpP, commaP);
else
{
if ((qLexP->type == QNodeStringValue) && (valueMayBeExpanded == true))
qLexP->value.s = orionldContextItemExpand(orionldState.contextP, qLexP->value.s, NULL, true, NULL);

qNodeAppend(compOpP, qLexP);
}

qNodeV[qNodeIx++] = compOpP;
compOpP = NULL;
Expand Down
1 change: 0 additions & 1 deletion src/lib/orionld/context/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ SET (SOURCES
orionldContextItemValueLookup.cpp
orionldContextPrefixExpand.cpp
orionldContextItemLookup.cpp
orionldContextValueExpand.cpp
orionldContextItemExpand.cpp
orionldContextFromBuffer.cpp
orionldContextFromUrl.cpp
Expand Down
12 changes: 0 additions & 12 deletions src/lib/orionld/context/orionldContextItemExpand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
// PARAMETERS
// contextP the context
// shortName the name to expand
// valueMayBeExpandedP pointer to a bool that is set to true if @type == @vocab
// contextItemPP to give the caller the complete result of the lookup
//
// RETURN VALUE
Expand All @@ -62,17 +61,13 @@ char* orionldContextItemExpand
(
OrionldContext* contextP,
const char* shortName,
bool* valueMayBeExpandedP,
bool useDefaultUrlIfNotFound,
OrionldContextItem** contextItemPP
)
{
OrionldContextItem* contextItemP;
char* colonP;

if (valueMayBeExpandedP != NULL)
*valueMayBeExpandedP = false;

if (contextP == NULL)
contextP = orionldCoreContextP;

Expand Down Expand Up @@ -110,12 +105,5 @@ char* orionldContextItemExpand
if (contextItemPP != NULL)
*contextItemPP = contextItemP;

// 5. May the value be expanded?
if ((valueMayBeExpandedP != NULL) && (contextItemP->type != NULL))
{
if (strcmp(contextItemP->type, "@vocab") == 0)
*valueMayBeExpandedP = true;
}

return contextItemP->id;
}
2 changes: 0 additions & 2 deletions src/lib/orionld/context/orionldContextItemExpand.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
// PARAMETERS
// contextP the context
// shortName the name to expand
// valueMayBeExpandedP pointer to a bool that is set to true if @type == @vocab
// contextItemPP to give the caller the complete result of the lookup
//
// RETURN VALUE
Expand All @@ -55,7 +54,6 @@ extern char* orionldContextItemExpand
(
OrionldContext* contextP,
const char* shortName,
bool* valueMayBeExpandedP,
bool useDefaultUrlIfNotFound,
OrionldContextItem** contextItemPP
);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/orionld/context/orionldContextPrefixExpand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ char* orionldContextPrefixExpand(OrionldContext* contextP, const char* str, char
// If not, look it up in the context and add it to the cache
if (prefixExpansion == NULL)
{
prefixExpansion = (char*) orionldContextItemExpand(contextP, prefix, NULL, false, NULL);
prefixExpansion = (char*) orionldContextItemExpand(contextP, prefix, false, NULL);
if (prefixExpansion != NULL)
prefixCacheInsert(prefix, prefixExpansion);
else
Expand Down
2 changes: 1 addition & 1 deletion src/lib/orionld/kjTree/kjTreeFromQueryContextResponse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ static void attrListParseAndExpand(int* attrsInAttrListP, char*** attrListExpand
//
for (int ix = 0; ix < attrs; ix++)
{
expandedV[ix] = orionldContextItemExpand(orionldState.contextP, expandedV[ix], NULL, true, NULL);
expandedV[ix] = orionldContextItemExpand(orionldState.contextP, expandedV[ix], true, NULL);
}

*attrListExpandedVecP = expandedV;
Expand Down
7 changes: 1 addition & 6 deletions src/lib/orionld/kjTree/kjTreeToContextAttribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ extern "C"
#include "orionld/context/OrionldContext.h" // OrionldContext
#include "orionld/context/orionldCoreContext.h" // orionldCoreContextP
#include "orionld/context/orionldContextItemExpand.h" // orionldContextItemExpand
#include "orionld/context/orionldContextValueExpand.h" // orionldContextValueExpand
#include "orionld/context/orionldContextItemAliasLookup.h" // orionldContextItemAliasLookup
#include "orionld/payloadCheck/pcheckGeoProperty.h" // pcheckGeoProperty
#include "orionld/kjTree/kjTreeToMetadata.h" // kjTreeToMetadata
Expand Down Expand Up @@ -551,12 +550,8 @@ bool kjTreeToContextAttribute(OrionldContext* contextP, KjNode* kNodeP, ContextA
(strcmp(kNodeP->name, "operationSpace") != 0))
{
char* longName;
bool valueMayBeExpanded = false;

longName = orionldContextItemExpand(contextP, kNodeP->name, &valueMayBeExpanded, true, &contextItemP);

if (valueMayBeExpanded)
orionldContextValueExpand(kNodeP);
longName = orionldContextItemExpand(contextP, kNodeP->name, true, &contextItemP);

kNodeP->name = longName;
caP->name = longName;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/orionld/kjTree/kjTreeToEntIdVector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ bool kjTreeToEntIdVector(KjNode* kNodeP, std::vector<ngsiv2::EntID>* entitiesP)
if (idP) entityInfo.id = idP;
if (idPatternP) entityInfo.idPattern = idPatternP;

entityInfo.type = orionldContextItemExpand(orionldState.contextP, typeP, NULL, true, NULL);
entityInfo.type = orionldContextItemExpand(orionldState.contextP, typeP, true, NULL);
entitiesP->push_back(entityInfo);
}

Expand Down
8 changes: 1 addition & 7 deletions src/lib/orionld/kjTree/kjTreeToMetadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ extern "C"
#include "orionld/common/orionldState.h" // orionldState
#include "orionld/common/orionldErrorResponse.h" // orionldErrorResponseCreate
#include "orionld/context/orionldContextItemExpand.h" // orionldContextItemExpand
#include "orionld/context/orionldContextValueExpand.h" // orionldContextValueExpand
#include "orionld/kjTree/kjTreeToMetadata.h" // Own interface


Expand Down Expand Up @@ -69,12 +68,7 @@ bool kjTreeToMetadata(ContextAttribute* caP, KjNode* nodeP, char* caName, char**
//
// Expand sub-attribute name
//
bool valueMayBeExpanded = false;

nodeP->name = orionldContextItemExpand(orionldState.contextP, nodeP->name, &valueMayBeExpanded, true, NULL);

if (valueMayBeExpanded == true)
orionldContextValueExpand(nodeP);
nodeP->name = orionldContextItemExpand(orionldState.contextP, nodeP->name, true, NULL);

if (caP->metadataVector.lookupByName(nodeP->name) != NULL)
{
Expand Down
6 changes: 3 additions & 3 deletions src/lib/orionld/kjTree/kjTreeToRegistration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ static bool kjTreeToRegistrationInformation(KjNode* regInfoNodeP, ngsiv2::Regist
{
STRING_CHECK(propP, "PropertyInfo::name");

propP->value.s = orionldContextItemExpand(orionldState.contextP, propP->value.s, NULL, true, NULL);
propP->value.s = orionldContextItemExpand(orionldState.contextP, propP->value.s, true, NULL);
regP->dataProvided.propertyV.push_back(propP->value.s);
}
}
Expand All @@ -138,7 +138,7 @@ static bool kjTreeToRegistrationInformation(KjNode* regInfoNodeP, ngsiv2::Regist
{
STRING_CHECK(relP, "RelationInfo::name");

relP->value.s = orionldContextItemExpand(orionldState.contextP, relP->value.s, NULL, true, NULL);
relP->value.s = orionldContextItemExpand(orionldState.contextP, relP->value.s, true, NULL);
regP->dataProvided.relationshipV.push_back(relP->value.s);
}
}
Expand Down Expand Up @@ -336,7 +336,7 @@ bool kjTreeToRegistration(ngsiv2::Registration* regP, char** regIdPP)
//
// Expand the name of the property
//
kNodeP->name = orionldContextItemExpand(orionldState.contextP, kNodeP->name, NULL, true, NULL);
kNodeP->name = orionldContextItemExpand(orionldState.contextP, kNodeP->name, true, NULL);
}

kNodeP = next;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/orionld/kjTree/kjTreeToStringList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ bool kjTreeToStringList(KjNode* kNodeP, std::vector<std::string>* stringListP)
char* expanded;

STRING_CHECK(attributeP, "String-List item");
expanded = orionldContextItemExpand(orionldState.contextP, attributeP->value.s, NULL, true, NULL);
expanded = orionldContextItemExpand(orionldState.contextP, attributeP->value.s, true, NULL);
stringListP->push_back(expanded);
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/orionld/kjTree/kjTreeToUpdateContextRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ void kjTreeToUpdateContextRequest(UpdateContextRequest* ucrP, KjNode* treeP, KjN
entityType = dbEntityTypeP->value.s;
}

entityTypeExpanded = orionldContextItemExpand(contextP, entityType, NULL, true, NULL);
entityTypeExpanded = orionldContextItemExpand(contextP, entityType, true, NULL);
if (entityTypeExpanded == NULL)
{
LM_E(("orionldContextItemExpand failed for '%s': %s", entityType, detail));
Expand Down
4 changes: 2 additions & 2 deletions src/lib/orionld/mongoBackend/mongoLdRegistrationsGet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ static bool uriParamTypeToFilter(mongo::BSONObjBuilder* queryBuilderP, char* typ
}
else
{
char* typeExpanded = orionldContextItemExpand(orionldState.contextP, type, NULL, true, NULL);
char* typeExpanded = orionldContextItemExpand(orionldState.contextP, type, true, NULL);
bsonArray.append(typeExpanded);
}
}
Expand Down Expand Up @@ -195,7 +195,7 @@ static bool uriParamAttrsToFilter(mongo::BSONObjBuilder* queryBuilderP, char* at
}
else
{
char* attrExpanded = orionldContextItemExpand(orionldState.contextP, attr, NULL, true, NULL);
char* attrExpanded = orionldContextItemExpand(orionldState.contextP, attr, true, NULL);
bsonArray.append(attrExpanded);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/orionld/payloadCheck/pcheckAttrs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ bool pcheckAttrs(KjNode* tree)
return false;
}

attrP->value.s = orionldContextItemExpand(orionldState.contextP, attrP->value.s, NULL, true, NULL);
attrP->value.s = orionldContextItemExpand(orionldState.contextP, attrP->value.s, true, NULL);
}

return true;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/orionld/payloadCheck/pcheckEntityInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ bool pcheckEntityInfo(KjNode* entityInfoP, bool typeMandatory)
// If a ':' is found inside the first 10 chars, the value is assumed to be expanded ...
//
if (orionldContextItemAlreadyExpanded(entityItemP->value.s) == false)
entityItemP->value.s = orionldContextItemExpand(orionldState.contextP, entityItemP->value.s, NULL, true, NULL);
entityItemP->value.s = orionldContextItemExpand(orionldState.contextP, entityItemP->value.s, true, NULL);
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/lib/orionld/payloadCheck/pcheckGeoQ.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ bool pcheckGeoQ(KjNode* geoqNodeP, bool coordsToString)

if (strcmp(pName, "location") != 0)
{
geopropertyP->value.s = orionldContextItemExpand(orionldState.contextP, pName, NULL, true, NULL);
geopropertyP->value.s = orionldContextItemExpand(orionldState.contextP, pName, true, NULL);
dotForEq(geopropertyP->value.s);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib/orionld/payloadCheck/pcheckInformationItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ bool pcheckInformationItem(KjNode* informationP)
STRING_CHECK(propP, "information[X]::properties[X]");
EMPTY_STRING_CHECK(propP, "information[X]::properties[X]");
if (orionldContextItemAlreadyExpanded(propP->value.s) == false)
propP->value.s = orionldContextItemExpand(orionldState.contextP, propP->value.s, NULL, true, NULL);
propP->value.s = orionldContextItemExpand(orionldState.contextP, propP->value.s, true, NULL);
}
}
else if (strcmp(infoItemP->name, "relationships") == 0)
Expand All @@ -88,7 +88,7 @@ bool pcheckInformationItem(KjNode* informationP)
STRING_CHECK(relP, "information[X]::relationships[X]");
EMPTY_STRING_CHECK(relP, "information[X]::relationships[X]");
if (orionldContextItemAlreadyExpanded(relP->value.s) == false)
relP->value.s = orionldContextItemExpand(orionldState.contextP, relP->value.s, NULL, true, NULL);
relP->value.s = orionldContextItemExpand(orionldState.contextP, relP->value.s, true, NULL);
}
}
else
Expand Down
2 changes: 1 addition & 1 deletion src/lib/orionld/payloadCheck/pcheckNotification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ bool pcheckNotification(KjNode* notificationP)
for (KjNode* attrP = nItemP->value.firstChildP; attrP != NULL; attrP = attrP->next)
{
STRING_CHECK(attrP, "attributes array item");
attrP->value.s = orionldContextItemExpand(orionldState.contextP, attrP->value.s, NULL, true, NULL);
attrP->value.s = orionldContextItemExpand(orionldState.contextP, attrP->value.s, true, NULL);
}
}
else if (strcmp(nItemP->name, "format") == 0)
Expand Down
2 changes: 1 addition & 1 deletion src/lib/orionld/payloadCheck/pcheckSubscription.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ bool pcheckSubscription
for (KjNode* itemP = nodeP->value.firstChildP; itemP != NULL; itemP = itemP->next)
{
STRING_CHECK(itemP, "watchedAttributes item");
itemP->value.s = orionldContextItemExpand(orionldState.contextP, itemP->value.s, NULL, true, NULL);
itemP->value.s = orionldContextItemExpand(orionldState.contextP, itemP->value.s, true, NULL);
}
*watchedAttributesPP = watchedAttributesP;
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/orionld/serviceRoutines/orionldDeleteAttribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ bool orionldDeleteAttribute(ConnectionInfo* ciP)
attrNameP = attrName;
else
{
attrNameP = orionldContextItemExpand(orionldState.contextP, attrName, NULL, true, NULL);
attrNameP = orionldContextItemExpand(orionldState.contextP, attrName, true, NULL);
// attrNameP might point to a field inside the context cache - must make our own copy as 'dotForEq' will modifyit
attrNameP = kaStrdup(&orionldState.kalloc, attrNameP);
}
Expand Down
Loading

0 comments on commit b70f0ad

Please sign in to comment.