summaryrefslogtreecommitdiff
path: root/networking/udhcp/leases.c
diff options
context:
space:
mode:
authorDenys Vlasenko2009-07-07 14:59:30 +0200
committerDenys Vlasenko2009-07-07 14:59:30 +0200
commit95cc814dbd37a4cb5a69b5eac80bd3e5173fe908 (patch)
treee5adfbc603dd9b70371a77c5f1a5c19ba937f4ae /networking/udhcp/leases.c
parenta51543a3a486ca60018394dda2623fdf1f16a965 (diff)
downloadbusybox-95cc814dbd37a4cb5a69b5eac80bd3e5173fe908.zip
busybox-95cc814dbd37a4cb5a69b5eac80bd3e5173fe908.tar.gz
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 <vda.linux@googlemail.com>
Diffstat (limited to 'networking/udhcp/leases.c')
-rw-r--r--networking/udhcp/leases.c23
1 files changed, 11 insertions, 12 deletions
diff --git a/networking/udhcp/leases.c b/networking/udhcp/leases.c
index 68fba72..afd41bf 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;
}