diff --git a/Makefile b/Makefile index 65d61364..9c7f3687 100644 --- a/Makefile +++ b/Makefile @@ -134,6 +134,7 @@ CFLAGS += -Wnested-externs CFLAGS += -Wmissing-declarations CFLAGS += -Wshadow CFLAGS += -Wall +CGLAGS += -Wextra #CFLAGS += -Werror all: lib diff --git a/examples/iec61850_client_example_files/file-tool.c b/examples/iec61850_client_example_files/file-tool.c index 6a53dd0a..19ee9340 100644 --- a/examples/iec61850_client_example_files/file-tool.c +++ b/examples/iec61850_client_example_files/file-tool.c @@ -26,26 +26,26 @@ static char _dirname[1000]; static char* dirname(char* path) { - char* lastSep = NULL; + char* lastSep = NULL; - int len = strlen(path); - int i = 0; + int len = strlen(path); + int i = 0; - while (i < len) { - if (path[i] == '/' || path[i] == ':' || path[i] == '\\') - lastSep = path + i; + while (i < len) { + if (path[i] == '/' || path[i] == ':' || path[i] == '\\') + lastSep = path + i; - i++; - } + i++; + } - if (lastSep) { - strcpy(_dirname, path); - _dirname[lastSep - path] = 0; - } - else - strcpy("", path); + if (lastSep) { + strcpy(_dirname, path); + _dirname[lastSep - path] = 0; + } + else + strcpy(_dirname, ""); - return _dirname; + return _dirname; } @@ -54,24 +54,24 @@ static char _basename[1000]; static char* basename(char* path) { - char* lastSep = NULL; + char* lastSep = NULL; - int len = strlen(path); - int i = 0; + int len = strlen(path); + int i = 0; - while (i < len) { - if (path[i] == '/' || path[i] == ':' || path[i] == '\\') - lastSep = path + i; + while (i < len) { + if (path[i] == '/' || path[i] == ':' || path[i] == '\\') + lastSep = path + i; - i++; - } + i++; + } - if (lastSep) - strcpy(_basename, lastSep + 1); - else - strcpy(_basename, path); + if (lastSep) + strcpy(_basename, lastSep + 1); + else + strcpy(_basename, path); - return _basename; + return _basename; } #endif diff --git a/src/iec61850/client/client_report.c b/src/iec61850/client/client_report.c index cd1594ee..477116f6 100644 --- a/src/iec61850/client/client_report.c +++ b/src/iec61850/client/client_report.c @@ -460,7 +460,7 @@ iedConnection_handleReport(IedConnection self, MmsValue* value) matchingReport->timestamp = MmsValue_getBinaryTimeAsUtcMs(timeStampValue); if (DEBUG_IED_CLIENT) - printf("IED_CLIENT: report has timestamp %lu\n", matchingReport->timestamp); + printf("IED_CLIENT: report has timestamp %llu\n", (unsigned long long) matchingReport->timestamp); inclusionIndex++; } diff --git a/src/iec61850/client/ied_connection.c b/src/iec61850/client/ied_connection.c index 4aa8e822..846570af 100644 --- a/src/iec61850/client/ied_connection.c +++ b/src/iec61850/client/ied_connection.c @@ -1925,9 +1925,7 @@ IedConnection_getFile(IedConnection self, IedClientError* error, const char* fil clientFileReadHandler.retVal = true; clientFileReadHandler.byteReceived = 0; - bool continueRead = true; - - while (continueRead == true) { + while (true) { bool moreFollows = MmsConnection_fileRead(self->connection, &mmsError, frsmId, mmsFileReadHandler, &clientFileReadHandler); diff --git a/src/iec61850/common/iec61850_common.c b/src/iec61850/common/iec61850_common.c index 67a4216c..704be1da 100644 --- a/src/iec61850/common/iec61850_common.c +++ b/src/iec61850/common/iec61850_common.c @@ -22,6 +22,7 @@ */ #include "iec61850_common.h" +#include "iec61850_common_internal.h" #include "libiec61850_platform_includes.h" diff --git a/src/iec61850/server/mms_mapping/reporting.c b/src/iec61850/server/mms_mapping/reporting.c index 461074a6..6fecb102 100644 --- a/src/iec61850/server/mms_mapping/reporting.c +++ b/src/iec61850/server/mms_mapping/reporting.c @@ -2186,7 +2186,10 @@ removeAllGIReportsFromReportBuffer(ReportBuffer* reportBuffer) reportBuffer->oldestReport = currentReport->next; } else { - lastReport->next = currentReport->next; + if (lastReport != NULL) + lastReport->next = currentReport->next; + else + lastReport = currentReport; } #if (DEBUG_IED_SERVER == 1) diff --git a/src/mms/iso_mms/asn1c/OCTET_STRING.c b/src/mms/iso_mms/asn1c/OCTET_STRING.c index 9c908d3d..3a12b4d2 100644 --- a/src/mms/iso_mms/asn1c/OCTET_STRING.c +++ b/src/mms/iso_mms/asn1c/OCTET_STRING.c @@ -1261,13 +1261,15 @@ OCTET_STRING_encode_uper(asn_TYPE_descriptor_t *td, asn_enc_rval_t er; int ct_extensible = ct->flags & APC_EXTENSIBLE; int inext = 0; /* Lies not within extension root */ - int sizeinunits = st->size; + int sizeinunits; const uint8_t *buf; int ret; if(!st || !st->buf) _ASN_ENCODE_FAILED; + sizeinunits = st->size; + if(unit_bits == 1) { sizeinunits = sizeinunits * 8 - (st->bits_unused & 0x07); } @@ -1387,38 +1389,41 @@ OCTET_STRING_print_utf8(asn_TYPE_descriptor_t *td, const void *sptr, } void -OCTET_STRING_free(asn_TYPE_descriptor_t *td, void *sptr, int contents_only) { - OCTET_STRING_t *st = (OCTET_STRING_t *)sptr; - asn_OCTET_STRING_specifics_t *specs = td->specifics - ? (asn_OCTET_STRING_specifics_t *)td->specifics - : &asn_DEF_OCTET_STRING_specs; - asn_struct_ctx_t *ctx = (asn_struct_ctx_t *) - ((char *)st + specs->ctx_offset); - struct _stack *stck; - - if(!td || !st) - return; - - if(st->buf) { - FREEMEM(st->buf); - } - - /* - * Remove decode-time stack. - */ - stck = (struct _stack *)ctx->ptr; - if(stck) { - while(stck->tail) { - struct _stack_el *sel = stck->tail; - stck->tail = sel->prev; - FREEMEM(sel); - } - FREEMEM(stck); - } - - if(!contents_only) { - FREEMEM(st); - } +OCTET_STRING_free(asn_TYPE_descriptor_t *td, void *sptr, int contents_only) +{ + OCTET_STRING_t *st = (OCTET_STRING_t*) sptr; + + if ((td == NULL) || (st == NULL)) + return; + + asn_OCTET_STRING_specifics_t *specs = td->specifics + ? (asn_OCTET_STRING_specifics_t*) td->specifics + : + &asn_DEF_OCTET_STRING_specs; + asn_struct_ctx_t *ctx = (asn_struct_ctx_t*) + ((char*) st + specs->ctx_offset); + struct _stack *stck; + + if (st->buf) { + FREEMEM(st->buf); + } + + /* + * Remove decode-time stack. + */ + stck = (struct _stack*) ctx->ptr; + if (stck) { + while (stck->tail) { + struct _stack_el *sel = stck->tail; + stck->tail = sel->prev; + FREEMEM(sel); + } + FREEMEM(stck); + } + + if (!contents_only) { + FREEMEM(st); + } } /* diff --git a/src/mms/iso_mms/asn1c/constr_CHOICE.c b/src/mms/iso_mms/asn1c/constr_CHOICE.c index de2cc3a4..c1db22f3 100644 --- a/src/mms/iso_mms/asn1c/constr_CHOICE.c +++ b/src/mms/iso_mms/asn1c/constr_CHOICE.c @@ -964,12 +964,13 @@ CHOICE_print(asn_TYPE_descriptor_t *td, const void *sptr, int ilevel, void CHOICE_free(asn_TYPE_descriptor_t *td, void *ptr, int contents_only) { - asn_CHOICE_specifics_t *specs = (asn_CHOICE_specifics_t *)td->specifics; - int present; if(!td || !ptr) return; + asn_CHOICE_specifics_t *specs = (asn_CHOICE_specifics_t *)td->specifics; + int present; + /* * Figure out which CHOICE element is encoded. */ diff --git a/src/mms/iso_mms/asn1c/constr_SET_OF.c b/src/mms/iso_mms/asn1c/constr_SET_OF.c index e183de47..85f78c97 100644 --- a/src/mms/iso_mms/asn1c/constr_SET_OF.c +++ b/src/mms/iso_mms/asn1c/constr_SET_OF.c @@ -841,7 +841,14 @@ asn_dec_rval_t SET_OF_decode_uper(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td, asn_per_constraints_t *constraints, void **sptr, asn_per_data_t *pd) { asn_dec_rval_t rv; - asn_SET_OF_specifics_t *specs = (asn_SET_OF_specifics_t *)td->specifics; + + rv.code = RC_OK; + rv.consumed = 0; + + if (td == NULL) + return rv; + + asn_SET_OF_specifics_t *specs = (asn_SET_OF_specifics_t *)td->specifics; asn_TYPE_member_t *elm = td->elements; /* Single one */ void *st = *sptr; asn_anonymous_set_ *list; @@ -866,7 +873,7 @@ SET_OF_decode_uper(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td, else if(td->per_constraints) ct = &td->per_constraints->size; else ct = 0; - if(ct && ct->flags & APC_EXTENSIBLE) { + if(ct && (ct->flags & APC_EXTENSIBLE)) { int value = per_get_few_bits(pd, 1); if(value < 0) _ASN_DECODE_STARVED; if(value) ct = 0; /* Not restricted! */ @@ -905,8 +912,6 @@ SET_OF_decode_uper(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td, nelems = -1; /* Allow uper_get_length() */ } while(repeat); - rv.code = RC_OK; - rv.consumed = 0; return rv; } diff --git a/src/mms/iso_mms/client/mms_client_connection.c b/src/mms/iso_mms/client/mms_client_connection.c index 4a304171..ad1ddfcf 100644 --- a/src/mms/iso_mms/client/mms_client_connection.c +++ b/src/mms/iso_mms/client/mms_client_connection.c @@ -1273,7 +1273,8 @@ mmsIsoCallback(IsoIndication indication, void* parameter, ByteBuffer* payload) if (bufPos == -1) goto exit_with_error; - uint32_t invokeId; + bool hasInvokeId = false; + uint32_t invokeId = 0; while (bufPos < payload->size) { @@ -1291,6 +1292,14 @@ mmsIsoCallback(IsoIndication indication, void* parameter, ByteBuffer* payload) goto exit_with_error; if (extendedTag) { + + if (hasInvokeId == false) { + if (DEBUG_MMS_CLIENT) + printf("MMS_CLIENT: invalid message received - missing invoke ID!\n"); + + goto exit_with_error; + } + switch (nestedTag) { @@ -1351,6 +1360,8 @@ mmsIsoCallback(IsoIndication indication, void* parameter, ByteBuffer* payload) if (DEBUG_MMS_CLIENT) printf("MMS_CLIENT: received request with invokeId: %i\n", invokeId); + hasInvokeId = true; + self->lastInvokeId = invokeId; break; @@ -3376,7 +3387,8 @@ MmsConnection_readJournalTimeRangeAsync(MmsConnection self, MmsError* mmsError, if ((MmsValue_getType(startTime) != MMS_BINARY_TIME) || (MmsValue_getType(endTime) != MMS_BINARY_TIME)) { - *mmsError = MMS_ERROR_INVALID_ARGUMENTS; + if (mmsError) + *mmsError = MMS_ERROR_INVALID_ARGUMENTS; goto exit_function; } @@ -3447,7 +3459,8 @@ MmsConnection_readJournalStartAfterAsync(MmsConnection self, MmsError* mmsError, if ((MmsValue_getType(timeSpecification) != MMS_BINARY_TIME) || (MmsValue_getType(entrySpecification) != MMS_OCTET_STRING)) { - *mmsError = MMS_ERROR_INVALID_ARGUMENTS; + if (mmsError) + *mmsError = MMS_ERROR_INVALID_ARGUMENTS; goto exit_function; } diff --git a/src/mms/iso_mms/common/mms_common_msg.c b/src/mms/iso_mms/common/mms_common_msg.c index 28efbc38..857119a0 100644 --- a/src/mms/iso_mms/common/mms_common_msg.c +++ b/src/mms/iso_mms/common/mms_common_msg.c @@ -244,36 +244,6 @@ mmsMsg_parseDataElement(Data_t* dataElement) printf("MMS CLIENT: error parsing data element (invalid structure size)!\n"); } } - else if (dataElement->present == Data_PR_array) { - - int componentCount = dataElement->choice.array->list.count; - - if (componentCount > 0) { - value = (MmsValue*) GLOBAL_CALLOC(1, sizeof(MmsValue)); - - value->type = MMS_ARRAY; - value->value.structure.size = componentCount; - value->value.structure.components = (MmsValue**) GLOBAL_CALLOC(componentCount, sizeof(MmsValue*)); - - int i; - - for (i = 0; i < componentCount; i++) { - value->value.structure.components[i] = - mmsMsg_parseDataElement(dataElement->choice.array->list.array[i]); - - if (value->value.structure.components[i] == NULL) { - MmsValue_delete(value); - value = NULL; - break; - } - } - } - else { - if (DEBUG_MMS_CLIENT) - printf("MMS CLIENT: error parsing data element (invalid array size)!\n"); - } - - } else { if (dataElement->present == Data_PR_integer) { 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 486383bc..3d77c360 100644 --- a/src/mms/iso_mms/server/mms_get_namelist_service.c +++ b/src/mms/iso_mms/server/mms_get_namelist_service.c @@ -257,10 +257,11 @@ getNameListDomainSpecific(MmsServerConnection connection, char* domainName) #if (MMS_DATA_SET_SERVICE == 1) static LinkedList -createStringsFromNamedVariableList(LinkedList nameList, LinkedList variableLists) +createStringsFromNamedVariableList(LinkedList variableLists) { - nameList = LinkedList_create(); + LinkedList nameList = LinkedList_create(); LinkedList variableListsElement = LinkedList_getNext(variableLists); + while (variableListsElement != NULL) { MmsNamedVariableList variableList = (MmsNamedVariableList) variableListsElement->data; @@ -285,7 +286,7 @@ getNamedVariableListsDomainSpecific(MmsServerConnection connection, char* domain if (domain != NULL) { LinkedList variableLists = MmsDomain_getNamedVariableLists(domain); - nameList = createStringsFromNamedVariableList(nameList, variableLists); + nameList = createStringsFromNamedVariableList(variableLists); } return nameList; @@ -300,7 +301,7 @@ getNamedVariableListsVMDSpecific(MmsServerConnection connection) LinkedList variableLists = MmsDevice_getNamedVariableLists(device); - nameList = createStringsFromNamedVariableList(nameList, variableLists); + nameList = createStringsFromNamedVariableList(variableLists); return nameList; } @@ -313,7 +314,7 @@ getNamedVariableListAssociationSpecific(MmsServerConnection connection) LinkedList variableLists = MmsServerConnection_getNamedVariableLists(connection); - nameList = createStringsFromNamedVariableList(nameList, variableLists); + nameList = createStringsFromNamedVariableList(variableLists); return nameList; }