From fb7cac312f528b90d6ee169357573fe4ddd06642 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fran=C3=A7ois=20De=20Keersmaeker?=
 <francois.dekeersmaeker@uclouvain.be>
Date: Fri, 12 May 2023 10:43:07 +0200
Subject: [PATCH] Added variable initialization to prevent UnboundLocalError

---
 src/packet/BOOTP.py | 4 ++++
 src/packet/CoAP.py  | 4 ++++
 src/packet/DNS.py   | 4 ++++
 3 files changed, 12 insertions(+)

diff --git a/src/packet/BOOTP.py b/src/packet/BOOTP.py
index 173e5e0..a095de0 100644
--- a/src/packet/BOOTP.py
+++ b/src/packet/BOOTP.py
@@ -70,6 +70,10 @@ class BOOTP(Packet):
         # Get field which will be modified
         field = random.choice(self.fields)
 
+        # Initialize old and new values
+        old_value = None
+        new_value = None
+
         if field == "chaddr":
             old_value = self.layer.getfieldval("chaddr")  # Store old value of field
             new_value = Packet.bytes_edit_char(old_value[:6]) + old_value[6:]  # Randomly change one byte in the MAC address
diff --git a/src/packet/CoAP.py b/src/packet/CoAP.py
index 7f940f1..9d79806 100644
--- a/src/packet/CoAP.py
+++ b/src/packet/CoAP.py
@@ -80,6 +80,10 @@ class CoAP(Packet):
         # Get field which will be modified
         field = random.choice(self.fields)
 
+        # Initialize old and new values
+        old_value = None
+        new_value = None
+
         # Chosen field is an integer
         if field == "type" or field == "code":
             old_value = self.layer.getfieldval(field)
diff --git a/src/packet/DNS.py b/src/packet/DNS.py
index b5ad2fa..ce8fb30 100644
--- a/src/packet/DNS.py
+++ b/src/packet/DNS.py
@@ -52,6 +52,10 @@ class DNS(Packet):
         # Get auxiliary fields
         qdcount = self.layer.getfieldval("qdcount")
         question_record = self.layer.getfieldval("qd") if qdcount > 0 else None
+
+        # Initialize old and new values
+        old_value = None
+        new_value = None
         
         # Field is QR flag
         if field == "qr":
-- 
GitLab