Clean up end_option(), and fix a possible off-by-one in the bound check.
This commit is contained in:
parent
5a38e49a81
commit
ba553e5d94
@ -116,17 +116,16 @@ uint8_t* get_option(struct dhcpMessage *packet, int code)
|
||||
}
|
||||
|
||||
/* return the position of the 'end' option */
|
||||
int end_option(unsigned char *optionptr)
|
||||
int end_option(uint8_t *optionptr)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
while (i < DHCP_OPTIONS_BUFSIZE && optionptr[i] != DHCP_END) {
|
||||
if (optionptr[i] == DHCP_PADDING)
|
||||
++i;
|
||||
else
|
||||
i += optionptr[i + OPT_LEN] + 2;
|
||||
if (optionptr[i] != DHCP_PADDING)
|
||||
i += optionptr[i + OPT_LEN] + OPT_DATA - 1;
|
||||
i++;
|
||||
}
|
||||
return (i < DHCP_OPTIONS_BUFSIZE ? i : DHCP_OPTIONS_BUFSIZE);
|
||||
return (i < DHCP_OPTIONS_BUFSIZE - 1 ? i : DHCP_OPTIONS_BUFSIZE - 1);
|
||||
}
|
||||
|
||||
|
||||
|
@ -31,7 +31,7 @@ extern struct dhcp_option options[];
|
||||
extern int option_lengths[];
|
||||
|
||||
uint8_t *get_option(struct dhcpMessage *packet, int code);
|
||||
int end_option(unsigned char *optionptr);
|
||||
int end_option(uint8_t *optionptr);
|
||||
int add_option_string(unsigned char *optionptr, unsigned char *string);
|
||||
int add_simple_option(unsigned char *optionptr, unsigned char code, uint32_t data);
|
||||
struct option_set *find_option(struct option_set *opt_list, char code);
|
||||
|
Loading…
Reference in New Issue
Block a user