Skip to content

Commit 38aacb0

Browse files
committed
add the port id range check
1 parent cd195ec commit 38aacb0

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

libcanard/canard.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
// The internal includes are placed here after the config header is included and CANARD_ASSERT is defined.
4343

4444
#include "_canard_cavl.h"
45+
#include <stdio.h>
46+
#include <stdlib.h>
4547

4648
// --------------------------------------------- COMMON DEFINITIONS ---------------------------------------------
4749

@@ -1384,6 +1386,13 @@ int8_t canardRxSubscribe(struct CanardInstance* const ins,
13841386
{
13851387
int8_t out = -CANARD_ERROR_INVALID_ARGUMENT;
13861388
const size_t tk = (size_t) transfer_kind;
1389+
1390+
assert(port_id >= 49152 && port_id <= 65535);
1391+
if (port_id < 49152 || port_id > 65535)
1392+
{
1393+
fprintf(stderr, "Invalid port: %d. Port should be within 49152 to 65535\n", port_id);
1394+
exit(EXIT_FAILURE);
1395+
}
13871396
if ((ins != NULL) && (out_subscription != NULL) && (tk < CANARD_NUM_TRANSFER_KINDS))
13881397
{
13891398
// Reset to the initial state. This is absolutely critical because the new payload size limit may be larger

0 commit comments

Comments
 (0)