Skip to content

Commit

Permalink
add null checks for empty value tag(#240)
Browse files Browse the repository at this point in the history
  • Loading branch information
matkonnerth authored Oct 9, 2023
1 parent 4b0b0f3 commit f052d60
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 1 deletion.
2 changes: 1 addition & 1 deletion backends/open62541/src/import.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ static void handleVariableNode(const NL_VariableNode *node, UA_NodeId *id,
attr.arrayDimensionsSize = 1;
}
RawData *data = NULL;
if (node->value)
if (node->value && node->value->data != NULL)
{
const UA_DataType *dataType = UA_findDataType(&attr.dataType);
if (!dataType)
Expand Down
7 changes: 7 additions & 0 deletions backends/open62541/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@ add_test(NAME nodeAttributes_Test
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMAND nodeAttributes ${CMAKE_CURRENT_SOURCE_DIR}/nodeAttributes.xml)

add_executable(primitiveValues primitiveValues.c)
target_include_directories(primitiveValues PRIVATE ${CHECK_INCLUDE_DIR})
target_link_libraries(primitiveValues PRIVATE NodesetLoader open62541::open62541 ${CHECK_LIBRARIES} ${PTHREAD_LIB})
add_test(NAME primitiveValues_Test
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMAND primitiveValues ${CMAKE_CURRENT_SOURCE_DIR}/primitiveValues.xml)

add_executable(conversion conversion.c)
target_include_directories(conversion PRIVATE ${CHECK_INCLUDE_DIR})
target_link_libraries(conversion PRIVATE NodesetLoader open62541::open62541 ${CHECK_LIBRARIES} ${PTHREAD_LIB})
Expand Down
67 changes: 67 additions & 0 deletions backends/open62541/tests/primitiveValues.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "check.h"
#include <NodesetLoader/backendOpen62541.h>
#include <NodesetLoader/dataTypes.h>
#include <open62541/server.h>
#include <open62541/server_config_default.h>
#include <open62541/types.h>

#include "testHelper.h"

UA_Server *server;
char *nodesetPath = NULL;

static void setup(void)
{
printf("path to testnodesets %s\n", nodesetPath);
server = UA_Server_new();
UA_ServerConfig *config = UA_Server_getConfig(server);
UA_ServerConfig_setDefault(config);
}

static void teardown(void)
{
UA_Server_run_shutdown(server);
#ifdef USE_CLEANUP_CUSTOM_DATATYPES
const UA_DataTypeArray *customTypes =
UA_Server_getConfig(server)->customDataTypes;
#endif
UA_Server_delete(server);
#ifdef USE_CLEANUP_CUSTOM_DATATYPES
NodesetLoader_cleanupCustomDataTypes(customTypes);
#endif
}

START_TEST(loadPrimitiveValues)
{
ck_assert(NodesetLoader_loadFile(server, nodesetPath, NULL));
}
END_TEST

static Suite *testSuite_Client(void)
{
Suite *s = suite_create("primitiveValues");
TCase *tc_server = tcase_create("primitiveValues");
tcase_add_unchecked_fixture(tc_server, setup, teardown);
tcase_add_test(tc_server, loadPrimitiveValues);
suite_add_tcase(s, tc_server);
return s;
}

int main(int argc, char *argv[])
{
printf("%s", argv[0]);
if (!(argc > 1))
return 1;
nodesetPath = argv[1];
Suite *s = testSuite_Client();
SRunner *sr = srunner_create(s);
srunner_set_fork_status(sr, CK_NOFORK);
srunner_run_all(sr, CK_NORMAL);
int number_failed = srunner_ntests_failed(sr);
srunner_free(sr);
return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
}
9 changes: 9 additions & 0 deletions backends/open62541/tests/primitiveValues.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,13 @@
</QualifiedName>
</Value>
</UAVariable>
<UAVariable NodeId="ns=1;i=1020" BrowseName="EmptyValueTag" DataType="Int32" ValueRank="-1">
<DisplayName>EmptyValueTag</DisplayName>
<References>
<Reference ReferenceType="HasTypeDefinition">i=68</Reference>
<Reference ReferenceType="HasComponent" IsForward="false">i=85</Reference>
</References>
<Value>
</Value>
</UAVariable>
</UANodeSet>
4 changes: 4 additions & 0 deletions src/Value.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,10 @@ static void ComplexData_clear(NL_Data *data)

static void Data_clear(NL_Data *data)
{
if(!data)
{
return;
}
if (data->type == DATATYPE_PRIMITIVE)
{
PrimitiveData_clear(data);
Expand Down

0 comments on commit f052d60

Please sign in to comment.