From 95cc814dbd37a4cb5a69b5eac80bd3e5173fe908 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 7 Jul 2009 14:59:30 +0200 Subject: udhcpd: fix a bug in add_lease where it was reading at [-1] It is not correct when we read lease file! Signed-off-by: Denys Vlasenko --- networking/udhcp/leases.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'networking/udhcp/leases.c') diff --git a/networking/udhcp/leases.c b/networking/udhcp/leases.c index 68fba726e..afd41bfd4 100644 --- a/networking/udhcp/leases.c +++ b/networking/udhcp/leases.c @@ -50,10 +50,10 @@ static void clear_lease(const uint8_t *chaddr, uint32_t yiaddr) /* Add a lease into the table, clearing out any old ones */ struct dyn_lease* FAST_FUNC add_lease( const uint8_t *chaddr, uint32_t yiaddr, - leasetime_t leasetime, uint8_t *hostname) + leasetime_t leasetime, + const char *hostname, int hostname_len) { struct dyn_lease *oldest; - uint8_t hostname_length; /* clean out any old ones */ clear_lease(chaddr, yiaddr); @@ -63,16 +63,15 @@ struct dyn_lease* FAST_FUNC add_lease( if (oldest) { oldest->hostname[0] = '\0'; if (hostname) { - /* option size byte, + 1 for NUL */ - hostname_length = hostname[-1] + 1; - if (hostname_length > sizeof(oldest->hostname)) - hostname_length = sizeof(oldest->hostname); - hostname = (uint8_t*) safe_strncpy((char*)oldest->hostname, (char*)hostname, hostname_length); + char *p; + if (hostname_len > sizeof(oldest->hostname)) + hostname_len = sizeof(oldest->hostname); + p = safe_strncpy(oldest->hostname, hostname, hostname_len); /* sanitization (s/non-ASCII/^/g) */ - while (*hostname) { - if (*hostname < ' ' || *hostname > 126) - *hostname = '^'; - hostname++; + while (*p) { + if (*p < ' ' || *p > 126) + *p = '^'; + p++; } } memcpy(oldest->lease_mac, chaddr, 6); @@ -137,7 +136,7 @@ static int nobody_responds_to_arp(uint32_t nip, const uint8_t *safe_mac) temp.s_addr = nip; bb_info_msg("%s belongs to someone, reserving it for %u seconds", inet_ntoa(temp), (unsigned)server_config.conflict_time); - add_lease(blank_chaddr, nip, server_config.conflict_time, NULL); + add_lease(blank_chaddr, nip, server_config.conflict_time, NULL, 0); return 0; } -- cgit v1.2.3