From 5830e3b3a027416a21a52542ee8132530d273bfc Mon Sep 17 00:00:00 2001 From: mich Date: Thu, 30 Apr 2020 13:18:22 +0200 Subject: [PATCH] corenet: complete explicit exception handling --- pycrate_corenet/HdlrUEIu.py | 8 +++---- pycrate_corenet/HdlrUENG.py | 2 +- pycrate_corenet/HdlrUES1.py | 18 +++++++-------- pycrate_corenet/ProcCNEMM.py | 22 +++++++++--------- pycrate_corenet/ProcCNESM.py | 4 ++-- pycrate_corenet/ProcCNGMM.py | 6 ++--- pycrate_corenet/ProcCNHnbap.py | 2 +- pycrate_corenet/ProcCNMM.py | 4 ++-- pycrate_corenet/ProcCNNgap.py | 4 ++-- pycrate_corenet/ProcCNRanap.py | 42 +++++++++++++++++----------------- pycrate_corenet/ProcCNRua.py | 10 ++++---- pycrate_corenet/ProcCNS1ap.py | 18 +++++++-------- pycrate_corenet/ProcCNSM.py | 2 +- pycrate_corenet/ProcCNSMS.py | 2 +- pycrate_corenet/ProcProto.py | 14 ++++++------ pycrate_corenet/ServerAuC.py | 6 ++--- pycrate_corenet/ServerGTPU.py | 12 +++++----- pycrate_corenet/ServerSMS.py | 4 ++-- pycrate_corenet/utils.py | 32 +++++++++++++------------- 19 files changed, 106 insertions(+), 106 deletions(-) diff --git a/pycrate_corenet/HdlrUEIu.py b/pycrate_corenet/HdlrUEIu.py index 14bef0a..fa1f615 100644 --- a/pycrate_corenet/HdlrUEIu.py +++ b/pycrate_corenet/HdlrUEIu.py @@ -156,7 +156,7 @@ class UEIuSigStack(SigStack): return [] try: PDU_RANAP.from_aper(buf) - except: + except Exception: asn_ranap_release() self._log('WNG', 'invalid RANAP PDU transfer-syntax: %s'\ % hexlify(buf).decode('ascii')) @@ -178,7 +178,7 @@ class UEIuSigStack(SigStack): # RNC-initiated procedure, instantiate it try: Proc = RANAPProcRncDispatcher[pdu_rx[1]['procedureCode']](self) - except: + except Exception: self._log('ERR', 'invalid RANAP PDU, initiatingMessage, code %i'\ % pdu_rx[1]['procedureCode']) # error cause: protocol, abstract-syntax-error-reject @@ -209,7 +209,7 @@ class UEIuSigStack(SigStack): # CN-initiated procedure, transfer the PDU to it try: Proc = self.Proc[pdu_rx[1]['procedureCode']] - except: + except Exception: self._log('ERR', 'invalid RANAP PDU, %s, code %i'\ % (pdu_rx[0], pdu_rx[1]['procedureCode'])) # error cause: protocol, message-not-compatible-with-receiver-state @@ -244,7 +244,7 @@ class UEIuSigStack(SigStack): return None try: Proc = ProcClass(self) - except: + except Exception: # no active Iu link self._log('ERR', 'no active Iu link to initialize the RANAP procedure %s'\ % ProcClass.__name__) diff --git a/pycrate_corenet/HdlrUENG.py b/pycrate_corenet/HdlrUENG.py index f90f257..c7f3c70 100644 --- a/pycrate_corenet/HdlrUENG.py +++ b/pycrate_corenet/HdlrUENG.py @@ -148,7 +148,7 @@ class UEFGMMd(SigStack): Proc = self.init_proc(ProcClass, encod={ProcClass.Init: IEs}, fgmm_preempt=True, sec=sec) try: NgapTxProc = Proc.output() - except: + except Exception: self._log('ERR', 'invalid IEs for network-initiated procedure %s' % Proc.Name) Proc.abort() return False, Proc diff --git a/pycrate_corenet/HdlrUES1.py b/pycrate_corenet/HdlrUES1.py index c0674e0..1ba48d2 100644 --- a/pycrate_corenet/HdlrUES1.py +++ b/pycrate_corenet/HdlrUES1.py @@ -526,7 +526,7 @@ class UEEMMd(SigStack): def set_sec_ctx_smc(self, ksi): try: secctx = self.S1.SEC[ksi] - except: + except Exception: pass else: secctx['EEA'], secctx['EIA'] = self._get_sec_eea(), self._get_sec_eia() @@ -639,7 +639,7 @@ class UEEMMd(SigStack): Proc = self.init_proc(ProcClass, encod={ProcClass.Init: IEs}, emm_preempt=True, sec=sec) try: S1apTxProc = Proc.output() - except: + except Exception: self._log('ERR', 'invalid IEs for network-initiated procedure %s' % Proc.Name) Proc.abort() return False, Proc @@ -953,7 +953,7 @@ class UEESMd(SigStack): """ try: trans = self.Trans[trans_id] - except: + except Exception: # err cause 47: PTI mismatch return None, 47 # @@ -1308,7 +1308,7 @@ class UES1d(SigStack): # eNB-initiated procedure, instantiate it try: Proc = S1APProcEnbDispatcher[pdu_rx[1]['procedureCode']](self) - except: + except Exception: self._log('ERR', 'invalid S1AP PDU, initiatingMessage, code %i'\ % pdu_rx[1]['procedureCode']) errcause = ('protocol', 'abstract-syntax-error-reject') @@ -1340,7 +1340,7 @@ class UES1d(SigStack): # CN-initiated procedure, transfer the PDU to it try: Proc = self.Proc[pdu_rx[1]['procedureCode']] - except: + except Exception: self._log('ERR', 'invalid S1AP PDU, %s, code %i'\ % (pdu_rx[0], pdu_rx[1]['procedureCode'])) errcause = ('protocol', 'message-not-compatible-with-receiver-state') @@ -1385,7 +1385,7 @@ class UES1d(SigStack): return None try: Proc = ProcClass(self) - except: + except Exception: # no active S1 link self._log('ERR', 'no active S1 link to initialize the S1AP procedure %s'\ % ProcClass.__name__) @@ -1755,7 +1755,7 @@ class UES1d(SigStack): if sh == 2: NasTxSec.encrypt(secctx['Knasenc'], 1, secctx['EEA'], sqnmsb) NasTxSec.mac_compute(secctx['Knasint'], 1, secctx['EIA'], sqnmsb) - except: + except Exception: self._log('ERR', 'NAS SEC DL: unable to protect the NAS message %s' % NasTx._name) #self.reset_sec_ctx() return None @@ -1869,7 +1869,7 @@ class UES1d(SigStack): tai = (self.UE.PLMN, self.UE.TAC) try: enbs = [self.Server.RAN[enbid] for enbid in self.Server.TAI[tai]] - except: + except Exception: self._log('ERR', 'paging: no eNB serving the UE TAI %s.%.4x' % tai) return # @@ -1895,7 +1895,7 @@ class UES1d(SigStack): tai = (self.UE.PLMN, self.UE.TAC) try: enbs = [self.Server.RAN[enbid] for enbid in self.Server.TAI[tai]] - except: + except Exception: self._log('ERR', 'paging: no eNB serving the UE TAI %s.%.4x' % tai) return False # diff --git a/pycrate_corenet/ProcCNEMM.py b/pycrate_corenet/ProcCNEMM.py index 664f91f..e462e6f 100644 --- a/pycrate_corenet/ProcCNEMM.py +++ b/pycrate_corenet/ProcCNEMM.py @@ -147,7 +147,7 @@ class EMMSigProc(NASSigProc): try: if self.EMM.Proc[-1] == self: del self.EMM.Proc[-1] - except: + except Exception: self._log('WNG', 'EMM stack corrupted') else: if self._emm_preempt: @@ -903,7 +903,7 @@ class EMMAttach(EMMSigProc): # -> we need to get its IMSI before continuing try: del self.UE.Server._UEpre[self.UE.MTMSI] - except: + except Exception: pass # if self.UEInfo['EPSID'][0] == 1: @@ -924,7 +924,7 @@ class EMMAttach(EMMSigProc): try: secctx = self.S1.SEC[self.S1.SEC['KSI']] secctx['UL_enb'] = self._nas_rx._ulcnt - except: + except Exception: pass if self.EMM.require_smc(self): return self._ret_smc(self.UEInfo['NAS_KSI']) @@ -966,7 +966,7 @@ class EMMAttach(EMMSigProc): try: secctx = self.S1.SEC[self.S1.SEC['KSI']] secctx['UL_enb'] = self._nas_rx._ulcnt - except: + except Exception: pass if self.EMM.require_smc(self): return self._ret_smc(self.UEInfo['NAS_KSI']) @@ -1147,7 +1147,7 @@ class EMMDetachUE(EMMSigProc): # just delete it try: del self.UE.Server._UEpre[self.UE.MTMSI] - except: + except Exception: pass def process(self, pdu): @@ -1378,7 +1378,7 @@ class EMMTrackingAreaUpdate(EMMSigProc): # -> we need to get its IMSI before continuing try: del self.UE.Server._UEpre[self.UE.MTMSI] - except: + except Exception: pass # need to request the IMSI, prepare an id request procedure return self._ret_req_imsi() @@ -1391,7 +1391,7 @@ class EMMTrackingAreaUpdate(EMMSigProc): try: secctx = self.S1.SEC[self.S1.SEC['KSI']] secctx['UL_enb'] = self._nas_rx._ulcnt - except: + except Exception: pass if self.EMM.require_smc(self): return self._ret_smc(self.UEInfo['NAS_KSI']) @@ -1426,7 +1426,7 @@ class EMMTrackingAreaUpdate(EMMSigProc): try: secctx = self.S1.SEC[self.S1.SEC['KSI']] secctx['UL_enb'] = self._nas_rx._ulcnt - except: + except Exception: pass if self.EMM.require_smc(self): return self._ret_smc(self.UEInfo['NAS_KSI']) @@ -1617,7 +1617,7 @@ class EMMServiceRequest(EMMSigProc): # -> we need to get its IMSI before continuing try: del self.UE.Server._UEpre[self.UE.MTMSI] - except: + except Exception: pass # need to request the IMSI, prepare an id request procedure return self._ret_req_imsi() @@ -1630,7 +1630,7 @@ class EMMServiceRequest(EMMSigProc): try: secctx = self.S1.SEC[self.S1.SEC['KSI']] secctx['UL_enb'] = self._nas_rx._ulcnt - except: + except Exception: pass if self.EMM.require_smc(self) and self.EMM.SER_SMC_ALW: return self._ret_smc((0, self.UEInfo['KSI'].get_val())) @@ -1655,7 +1655,7 @@ class EMMServiceRequest(EMMSigProc): try: secctx = self.S1.SEC[self.S1.SEC['KSI']] secctx['UL_enb'] = self._nas_rx._ulcnt - except: + except Exception: pass if self.EMM.require_smc(self) and self.EMM.SER_SMC_ALW: return self._ret_smc((0, self.UEInfo['KSI'].get_val())) diff --git a/pycrate_corenet/ProcCNESM.py b/pycrate_corenet/ProcCNESM.py index 1197081..dc0de40 100644 --- a/pycrate_corenet/ProcCNESM.py +++ b/pycrate_corenet/ProcCNESM.py @@ -116,7 +116,7 @@ class ESMSigProc(NASSigProc): # select the encoder and duplicate it try: Encod = self.Encod[(pd, typ)] - except: + except Exception: return ESMHeader = {} if 'EPSBearerId' in kw: @@ -163,7 +163,7 @@ class ESMSigProc(NASSigProc): ProcStack = self.ESM.Proc[self._ebi] if ProcStack[-1] == self: del ProcStack[-1] - except: + except Exception: self._log('WNG', 'ESM stack corrupted') def init_timer(self): diff --git a/pycrate_corenet/ProcCNGMM.py b/pycrate_corenet/ProcCNGMM.py index dcccdfc..93779f9 100644 --- a/pycrate_corenet/ProcCNGMM.py +++ b/pycrate_corenet/ProcCNGMM.py @@ -135,7 +135,7 @@ class GMMSigProc(NASSigProc): try: if self.GMM.Proc[-1] == self: del self.GMM.Proc[-1] - except: + except Exception: self._log('WNG', 'GMM stack corrupted') else: if self._gmm_preempt: @@ -383,7 +383,7 @@ class GMMAttach(GMMSigProc): # we remove it from the Server's provisory dict of UE try: del self.UE.Server._UEpre[self.UE.PTMSI] - except: + except Exception: pass # if self.UEInfo['ID'][0] == 1: @@ -805,7 +805,7 @@ class GMMRoutingAreaUpdating(GMMSigProc): # we remove it from the Server's provisory dict of UE try: del self.UE.Server._UEpre[self.UE.PTMSI] - except: + except Exception: pass # need to request the IMSI, prepare an id request procedure return self._ret_req_imsi() diff --git a/pycrate_corenet/ProcCNHnbap.py b/pycrate_corenet/ProcCNHnbap.py index d0dad41..8d607a9 100644 --- a/pycrate_corenet/ProcCNHnbap.py +++ b/pycrate_corenet/ProcCNHnbap.py @@ -475,7 +475,7 @@ class HNBAPErrorIndHNB(HNBAPSigProc): # abort it try: self.ProcHnbap[self.HNB.ProcHnbapLast].abort() - except: + except Exception: pass diff --git a/pycrate_corenet/ProcCNMM.py b/pycrate_corenet/ProcCNMM.py index a851d86..a456e71 100644 --- a/pycrate_corenet/ProcCNMM.py +++ b/pycrate_corenet/ProcCNMM.py @@ -139,7 +139,7 @@ class MMSigProc(NASSigProc): try: if self.MM.Proc[-1] == self: del self.MM.Proc[-1] - except: + except Exception: self._log('WNG', 'MM stack corrupted') else: if self._mm_preempt: @@ -760,7 +760,7 @@ class MMLocationUpdating(MMSigProc): # we remove it from the Server's provisory dict of UE try: del self.UE.Server._UEpre[self.UE.TMSI] - except: + except Exception: pass # if self.UEInfo['ID'][0] == 1: diff --git a/pycrate_corenet/ProcCNNgap.py b/pycrate_corenet/ProcCNNgap.py index 82bc890..2b283b5 100644 --- a/pycrate_corenet/ProcCNNgap.py +++ b/pycrate_corenet/ProcCNNgap.py @@ -1542,7 +1542,7 @@ class NGAPErrorIndNonUERAN(NGAPNonUESigProc): # abort it try: self.GNB.Proc[self.GNB.ProcLast].abort() - except: + except Exception: pass @@ -1627,7 +1627,7 @@ class NGAPErrorIndRAN(NGAPSigProc): # abort it try: self.NG.Proc[self.NG.ProcLast].abort() - except: + except Exception: pass diff --git a/pycrate_corenet/ProcCNRanap.py b/pycrate_corenet/ProcCNRanap.py index 2158ac0..d171050 100644 --- a/pycrate_corenet/ProcCNRanap.py +++ b/pycrate_corenet/ProcCNRanap.py @@ -334,7 +334,7 @@ class RANAPRABAssignment(RANAPSigProc): self._recv(pdu) try: del self.Iu.Proc[self.Code] - except: + except Exception: pass # if self.errcause: @@ -581,7 +581,7 @@ class RANAPIuRelease(RANAPSigProc): # remove from the Iu RANAP procedure stack try: del self.Iu.Proc[self.Code] - except: + except Exception: pass self._release_iu() @@ -589,7 +589,7 @@ class RANAPIuRelease(RANAPSigProc): # remove from the Iu RANAP procedure stack try: del self.Iu.Proc[self.Code] - except: + except Exception: pass self._log('INF', 'aborting') self._release_iu() @@ -883,7 +883,7 @@ class RANAPSRNSContextTransfer(RANAPSigProc): self._recv(pdu) try: del self.Iu.Proc[self.Code] - except: + except Exception: pass if not self.errcause: # TODO: do something with the list of RAB contexts @@ -1119,7 +1119,7 @@ class RANAPCNInvokeTrace(RANAPSigProc): def send(self): try: tracerefl = '0x%s' % hexlify(self.TraceReference).decode('ascii') - except: + except Exception: tracerefl = repr(self.TraceReference) self._log('INF', 'sent with trace reference %s' % tracerefl) return self._send() @@ -1177,7 +1177,7 @@ class RANAPSecurityModeControl(RANAPSigProc): self._recv(pdu) try: del self.Iu.Proc[self.Code] - except: + except Exception: pass # if self.errcause: @@ -1187,7 +1187,7 @@ class RANAPSecurityModeControl(RANAPSigProc): elif pdu[0] == 'unsuccessfulOutcome': try: self._log('WNG', 'failure, rejected with cause %r' % (self.UEInfo['Cause'], )) - except: + except Exception: self._log('WNG', 'failure, rejected without cause') self.success = False self.Iu.reset_sec_ctx() @@ -1198,13 +1198,13 @@ class RANAPSecurityModeControl(RANAPSigProc): try: secctx['UEA'] = self.UEInfo['ChosenEncryptionAlgorithm'] uea = secctx['UEA'] - except: + except Exception: secctx['UEA'] = None uea = 0 try: secctx['UIA'] = self.UEInfo['ChosenIntegrityProtectionAlgorithm'] uia = 1 + secctx['UIA'] # UIA1 -> uia = 1, UIA2 -> uia = 2 - except: + except Exception: secctx['UIA'] = None uia = 0 self._log('INF', 'accepted with UEA%i / UIA%i' % (uea, uia)) @@ -1370,7 +1370,7 @@ class RANAPLocationReport(RANAPSigProc): if 'PositionData' in ueinfo: try: desc.extend( self._get_position_data(ueinfo['PositionData']) ) - except: + except Exception: pass else: del ueinfo['PositionData'] @@ -1462,7 +1462,7 @@ class RANAPDataVolumeReport(RANAPSigProc): self._recv(pdu) try: del self.Iu.Proc[self.Code] - except: + except Exception: pass if not self.errcause: # TODO: do something with the data volume report @@ -1824,7 +1824,7 @@ class RANAPResetCN(RANAPConlessSigProc): self._recv(pdu) try: del self.RNC.ProcRanap[self.Code] - except: + except Exception: pass if not self.errcause: self._log('INF', 'success') @@ -1990,7 +1990,7 @@ class RANAPErrorIndConlessRNC(RANAPConlessSigProc): # abort it try: self.RNC.ProcRanap[self.RNC.ProcRanapLast].abort() - except: + except Exception: pass @@ -2081,7 +2081,7 @@ class RANAPErrorIndRNC(RANAPSigProc): # abort it try: self.Iu.Proc[self.Iu.ProcLast].abort() - except: + except Exception: pass @@ -2120,7 +2120,7 @@ class RANAPCNDeactivateTrace(RANAPSigProc): def send(self): try: tracerefl = '0x%s' % hexlify(self.TraceReference) - except: + except Exception: tracerefl = repr(self.TraceReference) self._log('INF', 'sent with trace reference %s' % tracerefl) return self._send() @@ -2176,7 +2176,7 @@ class RANAPResetResourceCN(RANAPConlessSigProc): self._recv(pdu) try: del self.RNC.ProcRanap[self.Code] - except: + except Exception: pass if not self.errcause: self._log('INF', 'success') @@ -2237,7 +2237,7 @@ class RANAPResetResourceRNC(RANAPConlessSigProc): RResList = RReslist[0] for RRes in RResList: RResIds.append(RRes['value'][1]['iuSigConId'][0]) - except: + except Exception: self._log('WNG', 'unexpected formatting of ResetResourceList') # # reset all UE connections handled by the RNC handler self.RNC in the @@ -2246,7 +2246,7 @@ class RANAPResetResourceRNC(RANAPConlessSigProc): for rres in RResIds: try: ue = self.RNC.UE_IuPS[rres] - except: + except Exception: pass else: ue.IuPS.SM.pdp_suspend() @@ -2259,7 +2259,7 @@ class RANAPResetResourceRNC(RANAPConlessSigProc): for rres in RResIds: try: ue = self.RNC.UE_IuCS[rres] - except: + except Exception: pass else: if ue.IuCS.MM.state != 'INACTIVE': @@ -2378,7 +2378,7 @@ class RANAPLocationRelatedData(RANAPSigProc): self._recv(pdu) try: del self.Iu.Proc[self.Code] - except: + except Exception: pass # if self.errcause: @@ -2387,7 +2387,7 @@ class RANAPLocationRelatedData(RANAPSigProc): self.success = False try: self._log('WNG', 'failure, rejected with cause %r' % (self.UEInfo['Cause'], )) - except: + except Exception: self._log('WNG', 'failure, rejected without cause') else: self.success = True diff --git a/pycrate_corenet/ProcCNRua.py b/pycrate_corenet/ProcCNRua.py index 60368fa..219228c 100644 --- a/pycrate_corenet/ProcCNRua.py +++ b/pycrate_corenet/ProcCNRua.py @@ -157,7 +157,7 @@ class RUAConnect(RUASigProc): ctx_id = self.ConInfo['Context_ID'][0] try: ued = self.HNB.UE_HNBAP[ctx_id] - except: + except Exception: self._log('ERR', 'no UE associated to context-id %i'\ % self.ConInfo['Context_ID'][0]) self.errcause = ('radioNetwork', 'connect-failed') @@ -236,7 +236,7 @@ class RUADirectTransfer(RUASigProc): if self.ConInfo['CN_DomainIndicator'] == 'cs-domain': try: ued = self.HNB.UE_IuCS[self.ConInfo['Context_ID'][0]] - except: + except Exception: self._log('ERR', 'no UE associated to context-id %i'\ % self.ConInfo['Context_ID'][0]) self.errcause = ('protocol', 'abstract-syntax-error-reject') @@ -245,7 +245,7 @@ class RUADirectTransfer(RUASigProc): else: try: ued = self.HNB.UE_IuPS[self.ConInfo['Context_ID'][0]] - except: + except Exception: self._log('ERR', 'no UE associated to context-id %i'\ % self.ConInfo['Context_ID'][0]) self.errcause = ('protocol', 'abstract-syntax-error-reject') @@ -307,7 +307,7 @@ class RUADisconnect(RUASigProc): if self.ConInfo['CN_DomainIndicator'] == 'cs-domain': try: ued = self.HNB.UE_IuCS[self.ConInfo['Context_ID'][0]] - except: + except Exception: self._log('ERR', 'no UE associated to context-id %i'\ % self.ConInfo['Context_ID'][0]) self.errcause = ('protocol', 'abstract-syntax-error-reject') @@ -321,7 +321,7 @@ class RUADisconnect(RUASigProc): else: try: ued = self.HNB.UE_IuPS[self.ConInfo['Context_ID'][0]] - except: + except Exception: self._log('ERR', 'no UE associated to context-id %i'\ % self.ConInfo['Context_ID'][0]) self.errcause = ('protocol', 'abstract-syntax-error-reject') diff --git a/pycrate_corenet/ProcCNS1ap.py b/pycrate_corenet/ProcCNS1ap.py index 060534d..d420bb5 100644 --- a/pycrate_corenet/ProcCNS1ap.py +++ b/pycrate_corenet/ProcCNS1ap.py @@ -524,7 +524,7 @@ class S1APInitialContextSetup(S1APSigProc): self._recv(pdu) try: del self.S1.Proc[self.Code] - except: + except Exception: pass # if self.errcause: @@ -537,7 +537,7 @@ class S1APInitialContextSetup(S1APSigProc): elif pdu[0] == 'unsuccessfulOutcome': try: self._log('WNG', 'failure, rejected with cause %r' % (self.UEInfo['Cause'], )) - except: + except Exception: self._log('WNG', 'failure, rejected without cause') self.success = False if hasattr(self, '_gtp_add_mobile_ebi'): @@ -683,7 +683,7 @@ class S1APUEContextRelease(S1APSigProc): # remove from the S1AP procedure stack try: del self.S1.Proc[self.Code] - except: + except Exception: pass self._release_s1() @@ -691,7 +691,7 @@ class S1APUEContextRelease(S1APSigProc): # remove from the S1AP procedure stack try: del self.S1.Proc[self.Code] - except: + except Exception: pass self._log('INF', 'aborting') self._release_s1() @@ -1609,7 +1609,7 @@ class S1APResetCN(S1APNonUESigProc): self._recv(pdu) try: del self.ENB.Proc[self.Code] - except: + except Exception: pass if not self.errcause: self._log('INF', 'success') @@ -1776,7 +1776,7 @@ class S1APErrorIndNonUEENB(S1APNonUESigProc): # abort it try: self.ENB.Proc[self.ENB.ProcLast].abort() - except: + except Exception: pass @@ -1861,7 +1861,7 @@ class S1APErrorIndENB(S1APSigProc): # abort it try: self.S1.Proc[self.S1.ProcLast].abort() - except: + except Exception: pass @@ -2581,7 +2581,7 @@ class S1APWriteReplaceWarning(S1APNonUESigProc): self._recv(pdu) try: del self.ENB.Proc[self.Code] - except: + except Exception: pass if not self.errcause: msgid, sernum = self.ENBInfo['MessageIdentifier'][0], self.ENBInfo['SerialNumber'][0] @@ -2640,7 +2640,7 @@ class S1APKill(S1APNonUESigProc): self._recv(pdu) try: del self.ENB.Proc[self.Code] - except: + except Exception: pass if not self.errcause: self._log('INF', 'stopped broadcasting warning message') diff --git a/pycrate_corenet/ProcCNSM.py b/pycrate_corenet/ProcCNSM.py index fdb8c56..9f9fcdc 100644 --- a/pycrate_corenet/ProcCNSM.py +++ b/pycrate_corenet/ProcCNSM.py @@ -143,7 +143,7 @@ class SMSigProc(NASSigProc): ProcStack = self.SM.Proc[self._tid] if ProcStack[-1] == self: del ProcStack[-1] - except: + except Exception: self._log('WNG', 'SM stack corrupted') def init_timer(self): diff --git a/pycrate_corenet/ProcCNSMS.py b/pycrate_corenet/ProcCNSMS.py index 4f71d53..bfb70a0 100644 --- a/pycrate_corenet/ProcCNSMS.py +++ b/pycrate_corenet/ProcCNSMS.py @@ -83,7 +83,7 @@ class CMSMSProc(NASSigProc): def rm_from_sms_stack(self): try: del self.SMS.Proc[self.TID] - except: + except Exception: pass def init_timer(self): diff --git a/pycrate_corenet/ProcProto.py b/pycrate_corenet/ProcProto.py index 05f4c3a..dd382b4 100644 --- a/pycrate_corenet/ProcProto.py +++ b/pycrate_corenet/ProcProto.py @@ -118,7 +118,7 @@ class LinkSigProc(SigProc): mand.append( ident ) try: pyname = pythonize_name(cont_ies[ident]['Value']._tr._name) - except: + except Exception: pass else: if pyname in encod[0]: @@ -137,7 +137,7 @@ class LinkSigProc(SigProc): mand.append( ident ) try: pyname = pythonize_name(cont_exts[ident]['Extension']._tr._name) - except: + except Exception: pass else: if pyname in encod[1]: @@ -203,7 +203,7 @@ class LinkSigProc(SigProc): ident = ie['id'] try: IE = IEs[ident] - except: + except Exception: # unknown IE, c'est pas grave... self._log('INF', 'decode_pdu: unknown IE ident in PDU, %r' % ie) ret['id_%i' % ident] = ie['value'] @@ -233,7 +233,7 @@ class LinkSigProc(SigProc): ident = ie['id'] try: IE = Extensions[ident] - except: + except Exception: # unknown Extension, c'est pas grave non plus... self._log('INF', 'decode_pdu: unknown Ext ident in PDU, %r' % ie) ret['idext_%i' % ident] = ie['extensionValue'] @@ -588,7 +588,7 @@ class NASSigProc(SigProc): return try: Decod = self.Decod[(pd, typ)] - except: + except Exception: self._log('WNG', 'decode_msg: no decoder dict found') Decod = {} # @@ -618,7 +618,7 @@ class NASSigProc(SigProc): # get the instance encoder try: Encod = self.Encod[mid] - except: + except Exception: self._log('WNG', 'encode_msg: no encoder dict found') Encod = {} # get the class encoder and update the instance's one @@ -660,7 +660,7 @@ class NASSigProc(SigProc): # select the encoder and duplicate it try: Encod = self.Encod[(pd, typ)] - except: + except Exception: return Encod.update(kw) diff --git a/pycrate_corenet/ServerAuC.py b/pycrate_corenet/ServerAuC.py index 1d1256c..f2e1f5a 100644 --- a/pycrate_corenet/ServerAuC.py +++ b/pycrate_corenet/ServerAuC.py @@ -246,7 +246,7 @@ class AuC: # lookup db for authentication Key and counter for IMSI try: K_ALG2_SQN_OP = self.db[IMSI] - except: + except Exception: self._log('WNG', '[make_3g_vector] IMSI %s not present in AuC.db' % IMSI) return None # @@ -305,7 +305,7 @@ class AuC: # lookup db for authentication Key and counter for IMSI try: K_ALG2_SQN_OP = self.db[IMSI] - except: + except Exception: self._log('WNG', '[make_4g_vector] IMSI %s not present in AuC.db' % IMSI) return None # @@ -360,7 +360,7 @@ class AuC: # lookup db for authentication Key and counter for IMSI try: K_ALG2_SQN_OP = self.db[IMSI] - except: + except Exception: self._log('WNG', '[synch_sqn] IMSI %s not present in AuC.db' % IMSI) return None # diff --git a/pycrate_corenet/ServerGTPU.py b/pycrate_corenet/ServerGTPU.py index 19810f5..5dff7fb 100644 --- a/pycrate_corenet/ServerGTPU.py +++ b/pycrate_corenet/ServerGTPU.py @@ -615,7 +615,7 @@ class GTPUd(object): else: self._log('WNG', 'invalid IP packet from UE, dropping it') return - except: + except Exception: self._log('WNG', 'invalid GTP / IP packet from RAN / UE, dropping it') return # @@ -722,7 +722,7 @@ class GTPUd(object): # try: stats = self.stats[ipsrc] - except: + except Exception: stats = self.init_stats(ipsrc) # if ipvers == 4: @@ -862,7 +862,7 @@ class GTPUd(object): # add the sk_int within ran_info sk_int = self.sk_int[self._sk_int_ind[ran_ip[0]]] ran_info = (ran_ip[0], ran_ip[1], sk_int) - except: + except Exception: self._log('ERR', 'invalid RAN IP, %r' % ran_ip) ran_info = None else: @@ -890,7 +890,7 @@ class GTPUd(object): # add the sk_int within ran_info sk_int = self.sk_int[self._sk_int_ind[ran_ip[0]]] ran_info = (ran_ip[0], ran_ip[1], sk_int) - except: + except Exception: self._log('ERR', 'invalid RAN IP, %r' % ran_ip) ran_info = None else: @@ -913,7 +913,7 @@ class GTPUd(object): ipv4addr = inet_ntoa(ipv4buf) try: del self._mobiles_addr[ipv4buf] - except: + except Exception: pass else: ipv4addr = None @@ -921,7 +921,7 @@ class GTPUd(object): ipv6addr = inet_ntop(AF_INET6, self.IPV6_NET_PREF + ipv6buf) try: del self._mobiles_addr[ipv6buf] - except: + except Exception: pass else: ipv6addr = None diff --git a/pycrate_corenet/ServerSMS.py b/pycrate_corenet/ServerSMS.py index a9e67e8..6c9794a 100644 --- a/pycrate_corenet/ServerSMS.py +++ b/pycrate_corenet/ServerSMS.py @@ -227,7 +227,7 @@ class SMSd(object): # 1) reassociate to the SMS SUBMIT of the initial sender try: tp_oa = rp_req[5][1]['TP_OA']['Num'].decode() - except: + except Exception: self._log('WNG', 'report_status: unable to retrieve the TP originating address') else: if tp_oa in self.Proc: @@ -471,7 +471,7 @@ class SMSd(object): else: data = ud tp_msg['TP_UD']['UD'].set_val(data) - except: + except Exception: self._log('WNG', 'invalid TP UD') else: self._inject_tp(tp_msg, num) diff --git a/pycrate_corenet/utils.py b/pycrate_corenet/utils.py index 338fde4..a638737 100644 --- a/pycrate_corenet/utils.py +++ b/pycrate_corenet/utils.py @@ -228,7 +228,7 @@ def decode_ue_rad_cap(buf): UERadCap = RRCLTE.EUTRA_InterNodeDefinitions.UERadioAccessCapabilityInformation try: UERadCap.from_uper(buf) - except: + except Exception: return None uecapinfo = {} try: @@ -241,7 +241,7 @@ def decode_ue_rad_cap(buf): 'criticalExtensions', 'c1', 'ueCapabilityInformation-r8')) - except: + except Exception: return UERadCap._val, uecapinfo # decode each ueCapabilityRAT-Container for caprat in radcapinfo['ue-CapabilityRAT-ContainerList']: @@ -250,7 +250,7 @@ def decode_ue_rad_cap(buf): UEEUTRACap = RRCLTE.EUTRA_RRC_Definitions.UE_EUTRA_Capability try: UEEUTRACap.from_uper(caprat['ueCapabilityRAT-Container']) - except: + except Exception: uecapinfo[rattype] = caprat['ueCapabilityRAT-Container'] else: uecapinfo[rattype] = UEEUTRACap._val @@ -258,7 +258,7 @@ def decode_ue_rad_cap(buf): UEUTRACap = RRC3G.PDU_definitions.InterRATHandoverInfo try: UEUTRACap.from_uper(caprat['ueCapabilityRAT-Container']) - except: + except Exception: uecapinfo[rattype] = caprat['ueCapabilityRAT-Container'] else: uecapinfo[rattype] = UEUTRACap._val @@ -275,7 +275,7 @@ def decode_ue_rad_cap(buf): try: m2.from_bytes(buf_m2) m3.from_bytes(buf_m3) - except: + except Exception: uecapinfo[rattype] = caprat['ueCapabilityRAT-Container'] else: uecapinfo[rattype] = (m2, m3) @@ -283,7 +283,7 @@ def decode_ue_rad_cap(buf): mrc = NAS.ms_ra_capability_value_part.clone() try: mrc.from_bytes(caprat['ueCapabilityRAT-Container']) - except: + except Exception: uecapinfo[rattype] = caprat['ueCapabilityRAT-Container'] else: uecapinfo[rattype] = mrc @@ -505,7 +505,7 @@ def inet_aton_cn(*pdnaddr, **kw): # IPv4 address try: return inet_aton(pdnaddr[1]) - except: + except Exception: log('WNG: IPv4 address conversion error, %r' % pdnaddr[1]) return pdnaddr[1] elif pdnaddr[0] == 2: @@ -517,7 +517,7 @@ def inet_aton_cn(*pdnaddr, **kw): else: try: return inet_pton(AF_INET6, ipaddr) - except: + except Exception: log('WNG: IPv6 address conversion error, %r' % pdnaddr[1]) return ipaddr elif pdnaddr[0] == 3: @@ -526,14 +526,14 @@ def inet_aton_cn(*pdnaddr, **kw): # PDN address try: return inet_aton_cn(2, pdnaddr[2]) + inet_aton_cn(1, pdnaddr[1]) - except: + except Exception: log('WNG: IPv4v6 PDN address conversion error, %r' % pdnaddr[1]) return pdnaddr[1] else: # PDP address try: return inet_aton_cn(1, pdnaddr[1]) + inet_aton_cn(2, pdnaddr[2]) - except: + except Exception: log('WNG: IPv4v6 PDP address conversion error, %r' % pdnaddr[1]) return pdnaddr[1] else: @@ -550,7 +550,7 @@ def inet_ntoa_cn(pdntype, buf, dom='EPS'): # IPv4 address try: return (1, inet_ntoa(buf)) - except: + except Exception: log('WNG: IPv4 buffer conversion error, %s' % hexlify(buf).decode('ascii')) return None elif pdntype == 2: @@ -560,7 +560,7 @@ def inet_ntoa_cn(pdntype, buf, dom='EPS'): else: try: return (2, inet_ntop(AF_INET6, buf)) - except: + except Exception: log('WNG: IPv6 buffer conversion error, %s' % hexlify(buf).decode('ascii')) return None elif pdntype == 3: @@ -568,13 +568,13 @@ def inet_ntoa_cn(pdntype, buf, dom='EPS'): # PDN address try: return (3, inet_ntoa(buf[8:12]), inet_ntoa_cn(2, buf[:8])[1]) - except: + except Exception: log('WNG: IPv4v6 PDN buffer conversion error, %s' % hexlify(buf).decode('ascii')) else: # PDP address try: return (3, inet_ntoa(buf[:4]), inet_ntop(AF_INET6, buf[4:20])) - except: + except Exception: log('WNG: IPv4v6 PDP buffer conversion error, %s' % hexlify(buf).decode('ascii')) else: return (pdntype, buf) @@ -670,7 +670,7 @@ def print_pduies(desc): % (ident, pythonize_name(ies('id', ident)['Value']._tr._name), ies('id', ident)['presence'][0].upper()) - except: + except Exception: info = ' - %i: [%s] (%s)'\ % (ident, ies('id', ident)['Value'].TYPE, @@ -692,7 +692,7 @@ def print_pduies(desc): % (ident, pythonize_name(ies('id', ident)['Extension']._tr._name), ies('id', ident)['presence'][0].upper()) - except: + except Exception: info = ' - %i: [%s] (%s)'\ % (ident, pythonize_name(ies('id', ident)['Extension'].TYPE),