From aca800dae9ce4f16b71959e7a9a4d10fa65851d4 Mon Sep 17 00:00:00 2001
From: Wu Jing <wu.jing@cn.fujitsu.com>
Date: Tue, 10 Apr 2018 17:19:52 +0900
Subject: [PATCH] fix SegmentFault by harq_pid==8 after clean_dlsch_eNB

---
 openair1/PHY/LTE_TRANSPORT/dlsch_modulation.c | 12 ++++++++++++
 openair1/SCHED/phy_procedures_lte_eNb.c       |  2 +-
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/openair1/PHY/LTE_TRANSPORT/dlsch_modulation.c b/openair1/PHY/LTE_TRANSPORT/dlsch_modulation.c
index 9fef0f1f4f..219d618170 100644
--- a/openair1/PHY/LTE_TRANSPORT/dlsch_modulation.c
+++ b/openair1/PHY/LTE_TRANSPORT/dlsch_modulation.c
@@ -2064,6 +2064,10 @@ int dlsch_modulation(PHY_VARS_eNB* phy_vars_eNB,
   if ((dlsch0 != NULL) && (dlsch1 != NULL)){
 
     harq_pid = dlsch0->harq_ids[frame%2][subframe_offset];
+    if(harq_pid >= dlsch0->Mdlharq) {
+      LOG_E(PHY,"illegal harq_pid %d\n", harq_pid);
+      return(-1);
+    }
     dlsch0_harq = dlsch0->harq_processes[harq_pid];
     mimo_mode = dlsch0_harq->mimo_mode;
     mod_order0 = dlsch0_harq->Qm;
@@ -2081,6 +2085,10 @@ int dlsch_modulation(PHY_VARS_eNB* phy_vars_eNB,
   }else if ((dlsch0 != NULL) && (dlsch1 == NULL)){
 
     harq_pid = dlsch0->harq_ids[frame%2][subframe_offset];
+    if(harq_pid >= dlsch0->Mdlharq) {
+      LOG_E(PHY,"illegal harq_pid %d\n", harq_pid);
+      return(-1);
+    }
     dlsch0_harq = dlsch0->harq_processes[harq_pid];
     mimo_mode = dlsch0_harq->mimo_mode;
     mod_order0 = dlsch0_harq->Qm;
@@ -2098,6 +2106,10 @@ int dlsch_modulation(PHY_VARS_eNB* phy_vars_eNB,
   }else if ((dlsch0 == NULL) && (dlsch1 != NULL)){
 
     harq_pid = dlsch1->harq_ids[frame%2][subframe_offset];
+    if(harq_pid >= dlsch1->Mdlharq) {
+      LOG_E(PHY,"illegal harq_pid %d\n", harq_pid);
+      return(-1);
+    }
     dlsch1_harq = dlsch1->harq_processes[harq_pid];
     mimo_mode = dlsch1_harq->mimo_mode;
     mod_order0 = dlsch1_harq->Qm;
diff --git a/openair1/SCHED/phy_procedures_lte_eNb.c b/openair1/SCHED/phy_procedures_lte_eNb.c
index b402c7c0a5..2ac83d1118 100644
--- a/openair1/SCHED/phy_procedures_lte_eNb.c
+++ b/openair1/SCHED/phy_procedures_lte_eNb.c
@@ -1689,7 +1689,7 @@ void release_harq(PHY_VARS_eNB *eNB,int UE_id,int tb,uint16_t frame,uint8_t subf
       frame_tx = ul_ACK_subframe2_dl_frame(&eNB->frame_parms,frame,subframe,subframe_tx);
       if (((1<<m)&mask) > 0) {
           harq_pid = dlsch0->harq_ids[frame_tx%2][subframe_tx];
-	if ((harq_pid>=0) && (harq_pid<10)) {
+	if ((harq_pid>=0) && (harq_pid<dlsch0->Mdlharq)) {
 	  dlsch0_harq     = dlsch0->harq_processes[harq_pid];
 	  dlsch1_harq     = dlsch1->harq_processes[harq_pid];
 	  AssertFatal(dlsch0_harq!=NULL,"dlsch0_harq is null\n");
-- 
GitLab