summaryrefslogtreecommitdiff
path: root/functions.c
diff options
context:
space:
mode:
authorLuke Bratch <luke@bratch.co.uk>2024-03-29 17:31:38 +0000
committerLuke Bratch <luke@bratch.co.uk>2024-03-29 17:31:38 +0000
commitbd7a7d2ce18babb041492762b3e55fdbad670d5c (patch)
treea208ae5941e29f774f1bdd650a1ce1f01f816299 /functions.c
parent35b494cafe1e3ff1b278040999da09b061c82fbc (diff)
Sanity check that the requested fd is greater than zero in arrindex().
Diffstat (limited to 'functions.c')
-rw-r--r--functions.c6
1 files changed, 6 insertions, 0 deletions
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) {