Fix some strlcpy() misuse that cuts off the last character of the copied

string.
Clean up some log messages.
This commit is contained in:
Nicholas J. Kain 2010-11-12 17:24:54 -05:00
parent f4a00f3826
commit 9d7ad2f11c
3 changed files with 9 additions and 10 deletions

View File

@ -1,5 +1,5 @@
/* ifchd.c - interface change daemon
* Time-stamp: <2010-11-12 14:27:47 njk>
* Time-stamp: <2010-11-12 17:22:34 njk>
*
* (C) 2004-2010 Nicholas J. Kain <njkain at gmail dot com>
*
@ -357,7 +357,7 @@ static int stream_onto_list(int i)
curl[i]->str = xmalloc(e - s + 1);
strlcpy(curl[i]->str, ibuf[i] + s, e - s);
strlcpy(curl[i]->str, ibuf[i] + s, e - s + 1);
last[i] = curl[i];
s = e + 1;
}
@ -378,6 +378,8 @@ static void execute_list(int i)
p = curl[i]->str;
log_line("execute_list - p = '%s'", p);
switch (state[i]) {
case STATE_NOTHING:
if (strncmp(p, CMD_INTERFACE, sizeof(CMD_INTERFACE)) == 0)
@ -683,7 +685,7 @@ read_again:
}
/* Append new stream input avoiding overflow. */
strlcpy(ibuf[i] + index, buf, sizeof(ibuf[i]) - index - 1);
strlcpy(ibuf[i] + index, buf, sizeof(ibuf[i]) - index);
/* Decompose ibuf contents onto strlist. */
index = stream_onto_list(i);

View File

@ -178,10 +178,10 @@ int get_raw_packet(struct dhcpMessage *payload, int fd)
uint16_t check;
ssize_t len = 0;
const ssize_t wanted = sizeof(struct iphdr) + sizeof(struct udphdr);
const ssize_t header_size = sizeof(struct iphdr) + sizeof(struct udphdr);
memset(&packet, 0, sizeof(struct udp_dhcp_packet));
while (len < wanted) {
while (len < header_size) {
ssize_t r = read(fd, &packet + len,
sizeof(struct udp_dhcp_packet) - len);
if (r == 0)
@ -205,8 +205,7 @@ int get_raw_packet(struct dhcpMessage *payload, int fd)
return -2;
}
log_line("len: %d wanted: %d", len, wanted);
if (len < wanted) {
if (len < header_size) {
log_line("Message too short to contain IP + UDP headers, ignoring");
sleep(1);
return -2;
@ -284,6 +283,6 @@ int get_raw_packet(struct dhcpMessage *payload, int fd)
log_error("received bogus message (bad magic) -- ignoring");
return -2;
}
log_line("oooooh!!! got some!");
log_line("Received valid DHCP message.");
return len - (sizeof(packet.ip) + sizeof(packet.udp));
}

View File

@ -295,8 +295,6 @@ static void handle_packet(void)
struct in_addr temp_addr;
struct dhcpMessage packet;
log_line("got a packet");
if (listen_mode == LISTEN_KERNEL)
len = get_packet(&packet, fd);
else