On 12/6/19 5:21 PM, Tim Kourt wrote:
Add parser and accessor for the domain name lease option.
ell/dhcp-lease.c | 24 +++++++++++++++++++++++-
ell/dhcp-private.h | 1 +
ell/dhcp.h | 1 +
3 files changed, 25 insertions(+), 1 deletion(-)
@@ -99,6 +101,18 @@ struct l_dhcp_lease
*_dhcp_lease_parse_options(struct dhcp_message_iter *iter)
+ case L_DHCP_OPTION_DOMAIN_NAME:
+ if (l < 1)
+ lease->domain_name = l_new(char, l + 1);
+ memcpy(lease->domain_name, v, l);
+ if (lease->domain_name[l - 1] != '\0')
+ lease->domain_name[l] = '\0';
So strictly speaking this if is not necessary as you already use l_new
which memsets returned memory to 0. However, you might want to be much
more strict about accepting NULs at the end. One is okay, multiple is
likely not ok. Embedded NULs are probably not okay either.
Also, it might be a good idea to more strictly check the domain name
here. Fail if we get an empty string, a dot or localhost. I believe
hostnames has a max length as well. And we should maybe limit these to
ascii or at least valid utf8 for now.