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 */
|
/* return the position of the 'end' option */
|
||||||
int end_option(unsigned char *optionptr)
|
int end_option(uint8_t *optionptr)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
while (i < DHCP_OPTIONS_BUFSIZE && optionptr[i] != DHCP_END) {
|
while (i < DHCP_OPTIONS_BUFSIZE && optionptr[i] != DHCP_END) {
|
||||||
if (optionptr[i] == DHCP_PADDING)
|
if (optionptr[i] != DHCP_PADDING)
|
||||||
++i;
|
i += optionptr[i + OPT_LEN] + OPT_DATA - 1;
|
||||||
else
|
i++;
|
||||||
i += optionptr[i + OPT_LEN] + 2;
|
|
||||||
}
|
}
|
||||||
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[];
|
extern int option_lengths[];
|
||||||
|
|
||||||
uint8_t *get_option(struct dhcpMessage *packet, int code);
|
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_option_string(unsigned char *optionptr, unsigned char *string);
|
||||||
int add_simple_option(unsigned char *optionptr, unsigned char code, uint32_t data);
|
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);
|
struct option_set *find_option(struct option_set *opt_list, char code);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user