gnrc_tcp: check if option length field is present before accessing it
TCP options have up to three fields (kind, length, value). The current code only checks for the presence of the first field. Before accessing the second field (length) the code must ensure that a length field is even present.
This commit is contained in:
parent
018c15ae0c
commit
e5503d62bf
@ -49,6 +49,7 @@ extern "C" {
|
|||||||
* @brief TCP option "length"-field values.
|
* @brief TCP option "length"-field values.
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
#define TCP_OPTION_LENGTH_MIN (2U) /**< Mimimum amount of bytes needed for an option with a length field */
|
||||||
#define TCP_OPTION_LENGTH_MSS (0x04) /**< MSS Option Size always 4 */
|
#define TCP_OPTION_LENGTH_MSS (0x04) /**< MSS Option Size always 4 */
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
|
|||||||
@ -51,7 +51,7 @@ int _option_parse(gnrc_tcp_tcb_t *tcb, tcp_hdr_t *hdr)
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
case TCP_OPTION_KIND_MSS:
|
case TCP_OPTION_KIND_MSS:
|
||||||
if (option->length > opt_left || option->length != TCP_OPTION_LENGTH_MSS) {
|
if (opt_left < TCP_OPTION_LENGTH_MIN || option->length > opt_left || option->length != TCP_OPTION_LENGTH_MSS) {
|
||||||
DEBUG("gnrc_tcp_option.c : _option_parse() : invalid MSS Option length.\n");
|
DEBUG("gnrc_tcp_option.c : _option_parse() : invalid MSS Option length.\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -66,7 +66,7 @@ int _option_parse(gnrc_tcp_tcb_t *tcb, tcp_hdr_t *hdr)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (option->length > opt_left) {
|
if (opt_left < TCP_OPTION_LENGTH_MIN || option->length > opt_left) {
|
||||||
DEBUG("gnrc_tcp_option.c : _option_parse() : invalid option length\n");
|
DEBUG("gnrc_tcp_option.c : _option_parse() : invalid option length\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user