Passing the invalid length returned from a failed call to dns_copy()
in to dns_question() will cause the latter to fail safely, but via a
path that is not obviously safe at first glance.
Check the return value from dns_copy() at the point of use, to reduce
future review noise.
Signed-off-by: Michael Brown <mcb30@ipxe.org>
size_t answer_offset;
size_t next_offset;
size_t rdlength;
- size_t name_len;
+ int name_len;
int rc;
/* Sanity check */
dns, dns_name ( &buf ) );
dns->search.offset = dns->search.len;
name_len = dns_copy ( &buf, &dns->name );
+ if ( name_len < 0 ) {
+ rc = name_len;
+ dns_done ( dns, rc );
+ goto done;
+ }
dns->offset = ( offsetof ( typeof ( dns->buf ), name ) +
name_len - 1 /* Strip root label */ );
if ( ( rc = dns_question ( dns ) ) != 0 ) {