From 1eb19cf690b473307eda73ce0c2dbcb75019c166 Mon Sep 17 00:00:00 2001 From: Philipp Maier Date: Tue, 19 Dec 2017 17:46:36 +0100 Subject: ranap_msg_factory: check IE encoder return codes in many functions, the returncode (rc) from the IE encoder functions is not checked. Add a return code check and log error message (like it is already done in the functions which already check the return code) Change-Id: I592c0794a94c50fde5c574b1e9bc581eb28af4ae --- src/ranap_msg_factory.c | 47 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 7 deletions(-) diff --git a/src/ranap_msg_factory.c b/src/ranap_msg_factory.c index fe7e325..f47c82b 100644 --- a/src/ranap_msg_factory.c +++ b/src/ranap_msg_factory.c @@ -185,6 +185,10 @@ struct msgb *ranap_new_msg_dt(uint8_t sapi, const uint8_t *nas, unsigned int nas /* ies -> dt */ rc = ranap_encode_directtransferies(&dt, &ies); + if (rc < 0) { + LOGP(DRANAP, LOGL_ERROR, "error encoding direct transfer IEs: %d\n", rc); + return NULL; + } /* dt -> msg */ msg = ranap_generate_initiating_message(RANAP_ProcedureCode_id_DirectTransfer, @@ -251,6 +255,11 @@ struct msgb *ranap_new_msg_sec_mod_cmd(const uint8_t *ik, const uint8_t *ck, enu if (ck) ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_EncryptionInformation, &ies.encryptionInformation); + if (rc < 0) { + LOGP(DRANAP, LOGL_ERROR, "error encoding security mode command IEs: %d\n", rc); + return NULL; + } + /* out -> msg */ msg = ranap_generate_initiating_message(RANAP_ProcedureCode_id_SecurityModeControl, RANAP_Criticality_reject, @@ -282,6 +291,10 @@ struct msgb *ranap_new_msg_sec_mod_compl( /* ies -> out */ rc = ranap_encode_securitymodecompleteies(&out, &ies); + if (rc < 0) { + LOGP(DRANAP, LOGL_ERROR, "error encoding security mode complete IEs: %d\n", rc); + return NULL; + } /* out -> msg */ msg = ranap_generate_successful_outcome(RANAP_ProcedureCode_id_SecurityModeControl, @@ -317,10 +330,14 @@ struct msgb *ranap_new_msg_common_id(const char *imsi) /* ies -> out */ rc = ranap_encode_commonid_ies(&out, &ies); + /* release dynamic allocations attached to ies */ ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_PermanentNAS_UE_ID, &ies.permanentNAS_UE_ID); - if (rc < 0) + + if (rc < 0) { + LOGP(DRANAP, LOGL_ERROR, "error encoding common id IEs: %d\n", rc); return NULL; + } /* out -> msg */ msg = ranap_generate_initiating_message(RANAP_ProcedureCode_id_CommonID, @@ -349,8 +366,10 @@ struct msgb *ranap_new_msg_iu_rel_cmd(const RANAP_Cause_t *cause_in) /* ies -> out */ rc = ranap_encode_iu_releasecommandies(&out, &ies); - if (rc < 0) + if (rc < 0) { + LOGP(DRANAP, LOGL_ERROR, "error encoding release command IEs: %d\n", rc); return NULL; + } /* out -> msg */ msg = ranap_generate_initiating_message(RANAP_ProcedureCode_id_Iu_Release, @@ -377,8 +396,10 @@ struct msgb *ranap_new_msg_iu_rel_compl(void) /* ies -> out */ rc = ranap_encode_iu_releasecompleteies(&out, &ies); - if (rc < 0) + if (rc < 0) { + LOGP(DRANAP, LOGL_ERROR, "error encoding release complete IEs: %d\n", rc); return NULL; + } /* out -> msg */ msg = ranap_generate_successful_outcome(RANAP_ProcedureCode_id_Iu_Release, @@ -434,11 +455,15 @@ struct msgb *ranap_new_msg_paging_cmd(const char *imsi, const uint32_t *tmsi, in /* ies -> out */ rc = ranap_encode_pagingies(&out, &ies); + /* release dynamic allocation attached to ies */ ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_PermanentNAS_UE_ID, &ies.permanentNAS_UE_ID); ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_TemporaryUE_ID, &ies.temporaryUE_ID); - if (rc < 0) + + if (rc < 0) { + LOGP(DRANAP, LOGL_ERROR, "error encoding paging IEs: %d\n", rc); return NULL; + } /* out -> msg */ msg = ranap_generate_initiating_message(RANAP_ProcedureCode_id_Paging, @@ -879,13 +904,17 @@ struct msgb *ranap_new_msg_iu_rel_req(const RANAP_Cause_t *cause) memcpy(&ies.cause, cause, sizeof(ies.cause)); rc = ranap_encode_iu_releaserequesties(&out, &ies); - if (rc < 0) + if (rc < 0) { + LOGP(DRANAP, LOGL_ERROR, "error encoding release request IEs: %d\n", rc); + ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_Iu_ReleaseRequest, &out); return NULL; + } /* encode the output into the msgb */ msg = ranap_generate_initiating_message(RANAP_ProcedureCode_id_Iu_ReleaseRequest, RANAP_Criticality_reject, &asn_DEF_RANAP_Iu_ReleaseRequest, &out); + ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_Iu_ReleaseRequest, &out); return msg; @@ -915,11 +944,15 @@ struct msgb *ranap_new_msg_rab_rel_req(uint8_t rab_id, const RANAP_Cause_t *caus /* encoe the list IEs into the output */ rc = ranap_encode_rab_releaserequesties(&out, &ies); - if (rc < 0) - return NULL; + /* 'out' has been generated, we can release the input */ ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_RAB_ReleaseList, &ies.raB_ReleaseList); + if (rc < 0) { + LOGP(DRANAP, LOGL_ERROR, "error encoding release request IEs: %d\n", rc); + return NULL; + } + /* encode the output into the msgb */ msg = ranap_generate_initiating_message(RANAP_ProcedureCode_id_RAB_ReleaseRequest, RANAP_Criticality_reject, -- cgit v1.2.3