From 42539b0bece976331dab8c965eb29fa525ac5def Mon Sep 17 00:00:00 2001 From: Cedric Roux Date: Thu, 29 Aug 2024 14:59:51 +0200 Subject: [PATCH] rfsim: add a check on 'sock' It is very possible that the operating system returns a file descriptor bigger than the size of bridge->buf (MAX_FD_RFSIMU, which is 250 as of now). As a minimum, let's fail if the socket file descriptor is out of bounds. A proper solution may be implemented later, if needed. --- radio/rfsimulator/simulator.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/radio/rfsimulator/simulator.c b/radio/rfsimulator/simulator.c index d944e028bb..670998f57e 100644 --- a/radio/rfsimulator/simulator.c +++ b/radio/rfsimulator/simulator.c @@ -182,6 +182,8 @@ typedef struct { static int allocCirBuf(rfsimulator_state_t *bridge, int sock) { + /* TODO: cleanup code so that this AssertFatal becomes useless */ + AssertFatal(sock >= 0 && sock < sizeofArray(bridge->buf), "socket %d is not in range\n", sock); buffer_t *ptr=&bridge->buf[sock]; ptr->circularBuf = calloc(1, sampleToByte(CirSize, 1)); if (ptr->circularBuf == NULL) {