From 0aa0633505aba9f30481fedbe1cf990b9a7d3028 Mon Sep 17 00:00:00 2001
From: Pierre LALET <pierre.lalet@cea.fr>
Date: Wed, 11 Jan 2017 17:31:06 +0100
Subject: [PATCH] Fix empty LLTDAttribute build & dissect

  - LLTDAttribute() produces a Raw instance (or crashes, when
    conf.debug_dissector is set).

  - str(LLTDAttribute(type=18)) crashes.
---
 scapy/layers/lltd.py | 4 +++-
 test/regression.uts  | 6 ++++++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/scapy/layers/lltd.py b/scapy/layers/lltd.py
index c7fa4b34..9a592edb 100644
--- a/scapy/layers/lltd.py
+++ b/scapy/layers/lltd.py
@@ -298,6 +298,8 @@ class LLTDAttribute(Packet):
             cmd = kargs["type"]
             if isinstance(cmd, basestring):
                 cmd = cls.fields_desc[0].s2i[cmd]
+        else:
+            return cls
         return SPECIFIC_CLASSES.get(cmd, cls)
 
 SPECIFIC_CLASSES = {}
@@ -719,7 +721,7 @@ class LLTDAttributeMachineName(LLTDAttribute):
 class LLTDAttributeDeviceUUID(LLTDAttribute):
     name = "LLTD Attribute - Device UUID"
     fields_desc = [
-        FieldLenField("len", None, length_of="value", fmt="B"),
+        FieldLenField("len", None, length_of="uuid", fmt="B"),
         StrLenField("uuid", "\x00" * 16, length_from=lambda pkt: pkt.len),
     ]
 
diff --git a/test/regression.uts b/test/regression.uts
index 7d3311fd..aac7e3af 100644
--- a/test/regression.uts
+++ b/test/regression.uts
@@ -4801,6 +4801,12 @@ assert pkt.src == pkt.real_src
 assert pkt.tos == 0
 assert pkt.function == 0
 
+= Attribute build / dissection
+assert isinstance(LLTDAttribute(), LLTDAttribute)
+assert isinstance(LLTDAttribute(str(LLTDAttribute())), LLTDAttribute)
+assert all(isinstance(LLTDAttribute(type=i), LLTDAttribute) for i in xrange(256))
+assert all(isinstance(LLTDAttribute(str(LLTDAttribute(type=i))), LLTDAttribute) for i in xrange(256))
+
 = Large TLV
 m1, m2, seq = RandMAC()._fix(), RandMAC()._fix(), 123
 preqbase = Ether(src=m1, dst=m2) / LLTD() / \
-- 
GitLab