diff --git a/src/common/linked_list.c b/src/common/linked_list.c index c3f8720b..d0ac6162 100644 --- a/src/common/linked_list.c +++ b/src/common/linked_list.c @@ -156,14 +156,14 @@ LinkedList_remove(LinkedList list, void* data) LinkedList LinkedList_insertAfter(LinkedList list, void* data) { - LinkedList originalNextElement = LinkedList_getNext(list); - LinkedList newElement = LinkedList_create(); - newElement->data = data; - newElement->next = originalNextElement; + if (newElement) { + newElement->data = data; + newElement->next = LinkedList_getNext(list); - list->next = newElement; + list->next = newElement; + } return newElement; } diff --git a/src/mms/iso_mms/server/mms_file_service.c b/src/mms/iso_mms/server/mms_file_service.c index ab86c880..fce656cc 100644 --- a/src/mms/iso_mms/server/mms_file_service.c +++ b/src/mms/iso_mms/server/mms_file_service.c @@ -1,7 +1,7 @@ /* * mms_file_service.c * - * Copyright 2013-2018 Michael Zillgith + * Copyright 2013-2022 Michael Zillgith * * This file is part of libIEC61850. * @@ -370,7 +370,6 @@ mmsServer_handleFileOpenRequest( else mmsMsg_createServiceErrorPdu(invokeId, response, MMS_ERROR_FILE_FILE_NON_EXISTENT); - } else mmsMsg_createServiceErrorPdu(invokeId, response, MMS_ERROR_RESOURCE_OTHER); @@ -390,7 +389,6 @@ exit_reject_invalid_pdu: #if (MMS_OBTAIN_FILE_SERVICE == 1) - static void /* Confirmed service error (ServiceError) */ createServiceErrorObtainFileError(uint32_t invokeId, ByteBuffer* response, MmsError errorType, uint32_t value) @@ -403,7 +401,6 @@ createServiceErrorObtainFileError(uint32_t invokeId, ByteBuffer* response, buffer, size); } - static void createObtainFileResponse(uint32_t invokeId, ByteBuffer* response) { @@ -1176,7 +1173,8 @@ mmsServer_handleFileDirectoryRequest( char* continueAfter = NULL; - while (bufPos < maxBufPos) { + while (bufPos < maxBufPos) + { uint8_t tag = buffer[bufPos++]; int length; @@ -1215,8 +1213,6 @@ mmsServer_handleFileDirectoryRequest( mmsMsg_createMmsRejectPdu(&invokeId, MMS_ERROR_REJECT_INVALID_PDU, response); return; } - - } int maxPduSize = connection->maxPduSize; diff --git a/src/mms/iso_mms/server/mms_get_namelist_service.c b/src/mms/iso_mms/server/mms_get_namelist_service.c index 77c13d5c..f1a24b6a 100644 --- a/src/mms/iso_mms/server/mms_get_namelist_service.c +++ b/src/mms/iso_mms/server/mms_get_namelist_service.c @@ -1,7 +1,7 @@ /* * mms_get_namelist_service.c * - * Copyright 2013, 2014, 2015 Michael Zillgith + * Copyright 2013-2022 Michael Zillgith * * This file is part of libIEC61850. * @@ -109,18 +109,21 @@ appendMmsSubVariable(char* name, char* child) char* newName = (char*) GLOBAL_MALLOC(newSize); - int bufPos = 0; - int i; - for (i = 0; i < nameLen; i++) { - newName[bufPos++] = name[i]; - } - newName[bufPos++] = '$'; + if (newName) + { + int bufPos = 0; + int i; + for (i = 0; i < nameLen; i++) { + newName[bufPos++] = name[i]; + } + newName[bufPos++] = '$'; - for (i = 0; i < childLen; i++) { - newName[bufPos++] = child[i]; - } + for (i = 0; i < childLen; i++) { + newName[bufPos++] = child[i]; + } - newName[bufPos] = 0; + newName[bufPos] = 0; + } return newName; } @@ -139,30 +142,37 @@ addSubNamedVaribleNamesToList(LinkedList nameList, char* prefix, MmsVariableSpec #if (CONFIG_MMS_SORT_NAME_LIST == 1) int* index = (int*) GLOBAL_MALLOC(sizeof(int) * variable->typeSpec.structure.elementCount); - for (i = 0; i < variable->typeSpec.structure.elementCount; i++) - index[i] = i; + if (index) + { + for (i = 0; i < variable->typeSpec.structure.elementCount; i++) + index[i] = i; - sortIndex(index, variable->typeSpec.structure.elementCount, variables); + sortIndex(index, variable->typeSpec.structure.elementCount, variables); #endif /* (CONFIG_MMS_SORT_NAME_LIST == 1) */ - for (i = 0; i < variable->typeSpec.structure.elementCount; i++) { + for (i = 0; i < variable->typeSpec.structure.elementCount; i++) { #if (CONFIG_MMS_SORT_NAME_LIST == 1) - char* variableName = appendMmsSubVariable(prefix, variables[index[i]]->name); + char* variableName = appendMmsSubVariable(prefix, variables[index[i]]->name); #else - char* variableName = appendMmsSubVariable(prefix, variables[i]->name); + char* variableName = appendMmsSubVariable(prefix, variables[i]->name); #endif /* (CONFIG_MMS_SORT_NAME_LIST == 1) */ - listElement = LinkedList_insertAfter(listElement, variableName); + if (variableName) + { + listElement = LinkedList_insertAfter(listElement, variableName); #if (CONFIG_MMS_SORT_NAME_LIST == 1) - listElement = addSubNamedVaribleNamesToList(listElement, variableName, variables[index[i]]); + listElement = addSubNamedVaribleNamesToList(listElement, variableName, variables[index[i]]); #else - listElement = addSubNamedVaribleNamesToList(listElement, variableName, variables[i]); + listElement = addSubNamedVaribleNamesToList(listElement, variableName, variables[i]); #endif /* (CONFIG_MMS_SORT_NAME_LIST == 1) */ - } + } + } #if (CONFIG_MMS_SORT_NAME_LIST == 1) - GLOBAL_FREEMEM(index); + GLOBAL_FREEMEM(index); + + } #endif }