Skip to content

Commit

Permalink
Fixed a crash
Browse files Browse the repository at this point in the history
  • Loading branch information
kzangeli committed Dec 15, 2022
1 parent 80dbd98 commit a3199e8
Show file tree
Hide file tree
Showing 3 changed files with 165 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Fixed Issues:
* Issue #1227 Case insensitive matching for http request header keys
* Issue #280 Crash when an attributed is PATCHed to have an empty array as value

7 changes: 7 additions & 0 deletions src/lib/orionld/serviceRoutines/orionldPatchEntity2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,13 @@ bool kjValuesDiffer(KjNode* leftAttr, KjNode* rightAttr)
if (type == KjBoolean) return (left->value.b == right->value.b)? false : true;

// Compound values ... let's just render the values and do a strcmp on the rendered buffers
// However, might be an empty array/object (kjFastRenderSize crashes if the parameter is NULL)
//
if ((left->value.firstChildP == NULL) && (right->value.firstChildP == NULL))
return false;
else if ((left->value.firstChildP == NULL) || (right->value.firstChildP == NULL))
return true;

int leftBufSize = kjFastRenderSize(left->value.firstChildP);
int rightBufSize = kjFastRenderSize(right->value.firstChildP);
char* leftBuf = kaAlloc(&orionldState.kalloc, leftBufSize);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
# Copyright 2022 FIWARE Foundation e.V.
#
# This file is part of Orion-LD Context Broker.
#
# Orion-LD Context Broker is free software: you can redistribute it and/or
# modify it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# Orion-LD Context Broker is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
# General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Orion-LD Context Broker. If not, see http://www.gnu.org/licenses/.
#
# For those usages not covered by this license please contact with
# orionld at fiware dot org

# VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh

--NAME--
Update an entity attribute using PATCH

--SHELL-INIT--
export BROKER=orionld
dbInit CB
brokerStart CB 0 IPv4 -experimental

--SHELL--
#
# 01. Create an entity E1 with an attribute P1=[]
# 02. Patch E1, setting P1=[] - make sure there's no crash
# 03. GET E1
# 04. Patch E1, setting P1=[] - again
# 05. GET E1
#

echo "01. Create an entity E1 with an attribute P1=1"
echo "=============================================="
payload='{
"id": "urn:E1",
"type": "T",
"@context": [ "https://fiware.github.io/NGSI-LD_TestSuite/ldContext/testContext.jsonld" ]
}'
orionCurl --url /ngsi-ld/v1/entities --payload "$payload" -H "Content-Type: application/ld+json"
echo
echo


echo "02. Patch E1, setting P1=[] - make sure there's no crash"
echo "========================================================"
payload='{
"@context": [ "https://fiware.github.io/NGSI-LD_TestSuite/ldContext/testContext.jsonld" ],
"P1": {
"type": "Property",
"value": []
}
}'
orionCurl --url /ngsi-ld/v1/entities/urn:E1 -X PATCH --payload "$payload" -H "Content-Type: application/ld+json"
echo
echo


echo "03. GET E1"
echo "=========="
orionCurl --url /ngsi-ld/v1/entities/urn:E1
echo
echo


echo "04. Patch E1, setting P1=[] - again"
echo "==================================="
payload='{
"@context": [ "https://fiware.github.io/NGSI-LD_TestSuite/ldContext/testContext.jsonld" ],
"P1": {
"type": "Property",
"value": []
}
}'
orionCurl --url /ngsi-ld/v1/entities/urn:E1 -X PATCH --payload "$payload" -H "Content-Type: application/ld+json"
echo
echo


echo "05. GET E1"
echo "=========="
orionCurl --url /ngsi-ld/v1/entities/urn:E1
echo
echo


--REGEXPECT--
01. Create an entity E1 with an attribute P1=1
==============================================
HTTP/1.1 201 Created
Content-Length: 0
Date: REGEX(.*)
Location: /ngsi-ld/v1/entities/urn:E1



02. Patch E1, setting P1=[] - make sure there's no crash
========================================================
HTTP/1.1 204 No Content
Date: REGEX(.*)



03. GET E1
==========
HTTP/1.1 200 OK
Content-Length: 100
Content-Type: application/json
Date: REGEX(.*)
Link: <https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context.jsonld>; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json"

{
"http://example.org/P1": {
"type": "Property",
"value": []
},
"id": "urn:E1",
"type": "http://example.org/T"
}


04. Patch E1, setting P1=[] - again
===================================
HTTP/1.1 204 No Content
Date: REGEX(.*)



05. GET E1
==========
HTTP/1.1 200 OK
Content-Length: 100
Content-Type: application/json
Date: REGEX(.*)
Link: <https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context.jsonld>; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json"

{
"http://example.org/P1": {
"type": "Property",
"value": []
},
"id": "urn:E1",
"type": "http://example.org/T"
}


--TEARDOWN--
brokerStop CB
dbDrop CB

0 comments on commit a3199e8

Please sign in to comment.