Skip to content

Commit

Permalink
- MMS server: fixed - server is sending data set response larger than…
Browse files Browse the repository at this point in the history
… negotiated MMS PDU size (LIB61850-435)
  • Loading branch information
mzillgith committed Mar 19, 2024
1 parent 681d1b0 commit a66e07d
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 17 deletions.
16 changes: 13 additions & 3 deletions src/mms/iso_mms/server/mms_get_var_access_service.c
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,12 @@ mmsServer_handleGetVariableAccessAttributesRequest(
rval = ber_decode(NULL, &asn_DEF_GetVariableAccessAttributesRequest,
(void**) &request, buffer + bufPos, maxBufPos - bufPos);

if (rval.code == RC_OK) {
if (request->present == GetVariableAccessAttributesRequest_PR_name) {
if (request->choice.name.present == ObjectName_PR_domainspecific) {
if (rval.code == RC_OK)
{
if (request->present == GetVariableAccessAttributesRequest_PR_name)
{
if (request->choice.name.present == ObjectName_PR_domainspecific)
{
Identifier_t domainId = request->choice.name.choice.domainspecific.domainId;
Identifier_t nameId = request->choice.name.choice.domainspecific.itemId;

Expand Down Expand Up @@ -343,6 +346,13 @@ mmsServer_handleGetVariableAccessAttributesRequest(

asn_DEF_GetVariableAccessAttributesRequest.free_struct(&asn_DEF_GetVariableAccessAttributesRequest, request, 0);

if (ByteBuffer_getSize(response) > connection->maxPduSize)
{
ByteBuffer_setSize(response, 0);

mmsMsg_createServiceErrorPdu(invokeId, response, MMS_ERROR_RESOURCE_OTHER);
}

return retVal;
}

Expand Down
32 changes: 21 additions & 11 deletions src/mms/iso_mms/server/mms_named_variable_list_service.c
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,8 @@ createGetNamedVariableListAttributesResponse(int invokeId, ByteBuffer* response,
LinkedList variable = LinkedList_getNext(variables);

int i;
for (i = 0; i < variableCount; i++) {
for (i = 0; i < variableCount; i++)
{
MmsNamedVariableListEntry variableEntry = (MmsNamedVariableListEntry) variable->data;

varListResponse->listOfVariable.list.array[i] = (struct GetNamedVariableListAttributesResponse__listOfVariable__Member*)
Expand Down Expand Up @@ -746,8 +747,8 @@ mmsServer_handleGetNamedVariableListAttributesRequest(
goto exit_function;
}

if (request->present == ObjectName_PR_domainspecific) {

if (request->present == ObjectName_PR_domainspecific)
{
char domainName[65];
char itemName[65];

Expand All @@ -767,14 +768,15 @@ mmsServer_handleGetNamedVariableListAttributesRequest(

MmsDomain* domain = MmsDevice_getDomain(mmsDevice, domainName);

if (domain != NULL) {
if (domain != NULL)
{
MmsNamedVariableList variableList =
MmsDomain_getNamedVariableList(domain, itemName);

if (variableList != NULL) {

if (createGetNamedVariableListAttributesResponse(invokeId, response, variableList) == false) {

if (variableList != NULL)
{
if (createGetNamedVariableListAttributesResponse(invokeId, response, variableList) == false)
{
/* encoding failed - probably because buffer size is too small for message */
ByteBuffer_setSize(response, 0);

Expand All @@ -789,8 +791,8 @@ mmsServer_handleGetNamedVariableListAttributesRequest(

}
#if (MMS_DYNAMIC_DATA_SETS == 1)
else if (request->present == ObjectName_PR_aaspecific) {

else if (request->present == ObjectName_PR_aaspecific)
{
char listName[65];

if (request->choice.aaspecific.size > 64) {
Expand All @@ -809,7 +811,8 @@ mmsServer_handleGetNamedVariableListAttributesRequest(
mmsMsg_createServiceErrorPdu(invokeId, response, MMS_ERROR_ACCESS_OBJECT_NON_EXISTENT);
}
#endif /* (MMS_DYNAMIC_DATA_SETS == 1) */
else if (request->present == ObjectName_PR_vmdspecific) {
else if (request->present == ObjectName_PR_vmdspecific)
{
char listName[65];

if (request->choice.vmdspecific.size > 64) {
Expand All @@ -833,6 +836,13 @@ mmsServer_handleGetNamedVariableListAttributesRequest(
mmsMsg_createServiceErrorPdu(invokeId, response, MMS_ERROR_ACCESS_OBJECT_ACCESS_UNSUPPORTED);
}

if (ByteBuffer_getSize(response) > connection->maxPduSize)
{
ByteBuffer_setSize(response, 0);

mmsMsg_createServiceErrorPdu(invokeId, response, MMS_ERROR_RESOURCE_OTHER);
}

exit_function:

asn_DEF_GetVariableAccessAttributesRequest.free_struct(&asn_DEF_GetNamedVariableListAttributesRequest,
Expand Down
15 changes: 12 additions & 3 deletions src/mms/iso_mms/server/mms_read_service.c
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ encodeReadResponse(MmsServerConnection connection,
printf("MMS read: message to large! send error PDU!\n");

mmsMsg_createServiceErrorPdu(invokeId, response,
MMS_ERROR_SERVICE_OTHER);
MMS_ERROR_RESOURCE_OTHER);

goto exit_function;
}
Expand Down Expand Up @@ -933,15 +933,17 @@ mmsServer_handleReadRequest(
goto exit_function;
}

if (request->variableAccessSpecification.present == VariableAccessSpecification_PR_listOfVariable) {
if (request->variableAccessSpecification.present == VariableAccessSpecification_PR_listOfVariable)
{
MmsServer_lockModel(connection->server);

handleReadListOfVariablesRequest(connection, request, invokeId, response);

MmsServer_unlockModel(connection->server);
}
#if (MMS_DATA_SET_SERVICE == 1)
else if (request->variableAccessSpecification.present == VariableAccessSpecification_PR_variableListName) {
else if (request->variableAccessSpecification.present == VariableAccessSpecification_PR_variableListName)
{
MmsServer_lockModel(connection->server);

handleReadNamedVariableListRequest(connection, request, invokeId, response);
Expand All @@ -953,6 +955,13 @@ mmsServer_handleReadRequest(
mmsMsg_createServiceErrorPdu(invokeId, response, MMS_ERROR_ACCESS_OBJECT_ACCESS_UNSUPPORTED);
}

if (ByteBuffer_getSize(response) > connection->maxPduSize)
{
ByteBuffer_setSize(response, 0);

mmsMsg_createServiceErrorPdu(invokeId, response, MMS_ERROR_RESOURCE_OTHER);
}

exit_function:
asn_DEF_MmsPdu.free_struct(&asn_DEF_MmsPdu, mmsPdu, 0);
}
Expand Down

0 comments on commit a66e07d

Please sign in to comment.