Review at  https://gerrit.osmocom.org/5499

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
---
M src/ranap_msg_factory.c
1 file changed, 35 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-iuh refs/changes/99/5499/1

diff --git a/src/ranap_msg_factory.c b/src/ranap_msg_factory.c
index fe7e325..9611794 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,
@@ -245,6 +249,10 @@
 
        /* ies -> out */
        rc = ranap_encode_securitymodecommandies(&out, &ies);
+       if (rc < 0) {
+               LOGP(DRANAP, LOGL_ERROR, "error encoding security mode command 
IEs: %d\n", rc);
+               return NULL;
+       }
 
        /* release dynamic allocations attached to ies */
        
ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_IntegrityProtectionInformation, 
&ies.integrityProtectionInformation);
@@ -282,6 +290,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,6 +329,11 @@
 
        /* ies -> out */
        rc = ranap_encode_commonid_ies(&out, &ies);
+       if (rc < 0) {
+               LOGP(DRANAP, LOGL_ERROR, "error encoding common id IEs: %d\n", 
rc);
+               return NULL;
+       }
+
        /* release dynamic allocations attached to ies */
        ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_PermanentNAS_UE_ID, 
&ies.permanentNAS_UE_ID);
        if (rc < 0)
@@ -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,6 +455,11 @@
 
        /* ies -> out */
        rc = ranap_encode_pagingies(&out, &ies);
+       if (rc < 0) {
+               LOGP(DRANAP, LOGL_ERROR, "error encoding paging IEs: %d\n", rc);
+               return NULL;
+       }
+
        /* 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);
@@ -879,8 +905,10 @@
        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);
                return NULL;
+       }
 
        /* encode the output into the msgb */
        msg = 
ranap_generate_initiating_message(RANAP_ProcedureCode_id_Iu_ReleaseRequest,
@@ -915,8 +943,11 @@
 
        /* encoe the list IEs into the output */
        rc = ranap_encode_rab_releaserequesties(&out, &ies);
-       if (rc < 0)
+       if (rc < 0) {
+               LOGP(DRANAP, LOGL_ERROR, "error encoding release request IEs: 
%d\n", rc);
                return NULL;
+       }
+
        /* 'out' has been generated, we can release the input */
        ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_RAB_ReleaseList, 
&ies.raB_ReleaseList);
 

-- 
To view, visit https://gerrit.osmocom.org/5499
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I592c0794a94c50fde5c574b1e9bc581eb28af4ae
Gerrit-PatchSet: 1
Gerrit-Project: osmo-iuh
Gerrit-Branch: master
Gerrit-Owner: dexter <[email protected]>

Reply via email to