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
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 @@
/* 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 @@
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 @@
/* 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 @@
/* 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 @@
/* 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 @@
/* 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 @@
/* 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 @@
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 @@
/* 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,