Server: assertion on method call with constant address space mode (or invalid address space content)
Description
When using a address space generated with scripts/generate-s2opc-address-space.py
script using --const_addspace
in order to have a constant address space memory except for variables values, the following assertion fails when using Method Call service on any method defined in address space:
src/ClientServer/services/b2c/argument_pointer_bs.c:51: argument_pointer_bs__check_and_get_variant_value: Assertion
SOPC_VariantArrayType_Array == variant->ArrayType' failed.`
Note: this assertion will also be raised in case of invalid value for method arguments in address space (if not defined as an array of arguments).
Analysis
When generating an address space with constant memory (except variants values), the variants values memory shall be defined in a separated array. Therefore the address space structure contains only indexes on this separated array as variant values in the constant address space structure. This particularity is managed by the SOPC_AddressSpace_Get_Value
function depending on the function used to create the address space used (SOPC_AddressSpace_CreateReadOnlyNodes
or SOPC_AddressSpace_Create
).
When Method Call service is used, the address_space_bs__get_InputArguments
is used to retrieve arguments of the method called stored in the address space. The implementation was using a direct access in address space node structure to access value &node->data.variable.Value
instead of calling SOPC_AddressSpace_Get_Value
. It lead to return the variant value index instead of the actual variant value.
Fixes
In order to fix this issue, the SOPC_AddressSpace_Get_Value
shall always be used and variable node value shall never be accessed directly from address space node structure.
Moreover to avoid the assertion to be raised in case of address space method misconfiguration (if method arguments is not an array of argument), the issue shall be detected and report an OPC UA service error status code instead.