From bd7a7d2ce18babb041492762b3e55fdbad670d5c Mon Sep 17 00:00:00 2001 From: Luke Bratch Date: Fri, 29 Mar 2024 17:31:38 +0000 Subject: Sanity check that the requested fd is greater than zero in arrindex(). --- functions.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'functions.c') diff --git a/functions.c b/functions.c index 31282ed..377f1af 100644 --- a/functions.c +++ b/functions.c @@ -438,6 +438,12 @@ void updategreetings(char *greeting001, char *greeting002, char *greeting003, ch // TODO - Use this wherever we are calculating the position (various places) instead of // duplicating code. int arrindex(struct client *clients, int clientfd) { + // Make sure the client fd requested is >0 (less than 0 is nonsense, 0 is almost certainly standard input) + if (clientfd < 1) { + debugprint(DEBUG_CRIT, "arrindex(): error: requested client fd '%d' is less than 1, returning -1.\n", clientfd); + return -1; + } + // Find the client in the clients array for (int i = 0; i < MAXCLIENTS; i++) { if (clients[i].fd == clientfd) { -- cgit v1.2.3