summaryrefslogtreecommitdiff
path: root/functions.c
diff options
context:
space:
mode:
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) {