From 28c3f9ca211170e95fa6cf663de11542080494e1 Mon Sep 17 00:00:00 2001 From: lisa neigut Date: Thu, 28 Mar 2019 14:28:08 -0700 Subject: [PATCH] tlv: don't crash when you fail to parse the TLV passing back a null TLV was crashing here, because we tried to dereference a null pointer. instead, we put it into a temporary struct that we can check for NULL-ness, before assigning to the passed in pointer. --- tools/generate-wire.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/generate-wire.py b/tools/generate-wire.py index 870272351..9ecad810f 100755 --- a/tools/generate-wire.py +++ b/tools/generate-wire.py @@ -504,10 +504,11 @@ class Message(object): elif f.is_tlv: if not f.is_variable_size(): raise TypeError('TLV {} not variable size'.format(f.name)) - subcalls.append('{tlv_name} = fromwire__{tlv_name}(ctx, &cursor, &plen, &{tlv_len});' + subcalls.append('struct {tlv_name} *_tlv = fromwire__{tlv_name}(ctx, &cursor, &plen, &{tlv_len});' .format(tlv_name=f.name, tlv_len=f.lenvar)) - subcalls.append('if (!{tlv_name})'.format(tlv_name=f.name)) + subcalls.append('if (!_tlv)') subcalls.append('return false;') + subcalls.append('*{tlv_name} = *_tlv;'.format(tlv_name=f.name)) elif f.is_variable_size(): subcalls.append("//2nd case {name}".format(name=f.name)) typename = f.fieldtype.name