Browse Source

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.
pr-2587
lisa neigut 6 years ago
committed by Rusty Russell
parent
commit
28c3f9ca21
  1. 5
      tools/generate-wire.py

5
tools/generate-wire.py

@ -504,10 +504,11 @@ class Message(object):
elif f.is_tlv: elif f.is_tlv:
if not f.is_variable_size(): if not f.is_variable_size():
raise TypeError('TLV {} not variable size'.format(f.name)) 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)) .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('return false;')
subcalls.append('*{tlv_name} = *_tlv;'.format(tlv_name=f.name))
elif f.is_variable_size(): elif f.is_variable_size():
subcalls.append("//2nd case {name}".format(name=f.name)) subcalls.append("//2nd case {name}".format(name=f.name))
typename = f.fieldtype.name typename = f.fieldtype.name

Loading…
Cancel
Save