From 00cea448469d4b286484f224b79f5743a5e41cdb Mon Sep 17 00:00:00 2001 From: Nigel Horne Date: Fri, 27 Dec 2024 15:19:52 -0500 Subject: [PATCH] Trap memory failures --- sniff2ban.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/sniff2ban.c b/sniff2ban.c index 2aa9300..33e87b6 100644 --- a/sniff2ban.c +++ b/sniff2ban.c @@ -2548,9 +2548,9 @@ setup_apache_hosts(void) tail = tail->next; } if(tail == NULL) - fputs("Memory allocation failure\n", stderr); fclose(fin); closedir(dirp); + fputs("Memory allocation failure\n", stderr); return; } @@ -2560,6 +2560,13 @@ setup_apache_hosts(void) if(verbose >= 3) printf("Adding apache hostname %s\n", p); tail->name = strdup(p); + if(tail->name == NULL) { + free(tail); + fclose(fin); + closedir(dirp); + fputs("Memory allocation failure\n", stderr); + return; + } tail->next = NULL; } fclose(fin);