about summary refs log tree commit diff stats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--miasm2/analysis/mem.py10
-rw-r--r--test/analysis/mem.py8
2 files changed, 14 insertions, 4 deletions
diff --git a/miasm2/analysis/mem.py b/miasm2/analysis/mem.py
index 006fecd0..dbfd335a 100644
--- a/miasm2/analysis/mem.py
+++ b/miasm2/analysis/mem.py
@@ -314,7 +314,13 @@ class Ptr(Num):
         if isinstance(dst_type, MemField):
             # Patch the field to propagate the MemSelf replacement
             dst_type._get_self_type = lambda: self._get_self_type()
-            dst_type = mem(dst_type)
+            # dst_type cannot be patched here, since _get_self_type of the outer
+            # class has not yet been set. Patching dst_type involves calling
+            # mem(dst_type), which will only return a type that does not point
+            # on MemSelf but on the right class only when _get_self_type of the
+            # outer class has been replaced by _MetaMemStruct.
+            # In short, dst_type = mem(dst_type) is not valid here, it is done
+            # lazily in _fix_dst_type
         self._dst_type = dst_type
         self._type_args = type_args
         self._type_kwargs = type_kwargs
@@ -325,6 +331,8 @@ class Ptr(Num):
                 self._dst_type = self._get_self_type()
             else:
                 raise ValueError("Unsupported usecase for MemSelf, sorry")
+        if isinstance(self._dst_type, MemField):
+            self._dst_type = mem(self._dst_type)
 
     @property
     def dst_type(self):
diff --git a/test/analysis/mem.py b/test/analysis/mem.py
index d0590ebc..e9c5d60b 100644
--- a/test/analysis/mem.py
+++ b/test/analysis/mem.py
@@ -183,13 +183,13 @@ assert memarray[2:4] == [3, 3]
 try:
     memarray[2:4] = [3, 3, 3]
     assert False, "Should raise, mismatched sizes"
-except (ValueError):
+except ValueError:
     pass
 
 try:
     memarray[1, 2]
     assert False, "Should raise, mismatched sizes"
-except (ValueError):
+except ValueError:
     pass
 
 
@@ -360,12 +360,13 @@ class UnhealthyIdeas(MemStruct):
         ("pself", Ptr("I", MemSelf)),
         ("apself", Array(Ptr("I", MemSelf), 2)),
         ("ppself", Ptr("I", Ptr("I", MemSelf))),
+        ("pppself", Ptr("I", Ptr("I", Ptr("I", MemSelf)))),
     ]
 
 # Other way to handle self dependency and circular dependencies
 # NOTE: in this case, MemSelf would have been fine
 UnhealthyIdeas.fields.append(
-    ("pppself", Ptr("I", Ptr("I", Ptr("I", UnhealthyIdeas)))))
+    ("pppself2", Ptr("I", Ptr("I", Ptr("I", UnhealthyIdeas)))))
 # Regen all fields
 UnhealthyIdeas.gen_fields()
 
@@ -398,6 +399,7 @@ ideas.deref_pppself.value = my_heap.vm_alloc(jitter.vm, p_size)
 ideas.deref_pppself.deref_value.value = ideas.get_addr()
 assert ideas.deref_pppself.deref_value.deref_value == ideas
 
+
 # Cast tests
 # MemStruct cast
 MemInt = mem(Num("I"))