Skip to content

Commit

Permalink
Added some hardening
Browse files Browse the repository at this point in the history
  • Loading branch information
nigelhorne committed Dec 27, 2024
1 parent da54982 commit 3d32df2
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions sniff2ban.c
Original file line number Diff line number Diff line change
Expand Up @@ -2500,18 +2500,24 @@ setup_apache_hosts(void)
const struct dirent *d;
struct apachehosts *tail;

if(dirp == NULL)
if(dirp == NULL) {
perror("Failed to open directory");
return;
}

tail = NULL;
while((d = readdir(dirp)) != NULL) {
FILE *fin;
char buf[BUFSIZ + 1];

if(d->d_ino == 0)
continue;
if(d->d_name[0] == '.')
if(d->d_ino == 0 || d->d_name[0] == '.')
continue; /* Skip hidden and invalid files */

if(snprintf(buf, sizeof(buf), "%s/%s", SITES_ENABLED_DIR, d->d_name) >= sizeof(buf)) {
fprintf(stderr, "File path too long, skipping: %s\n", d->d_name);
continue;
sprintf(buf, "%s/%s", SITES_ENABLED_DIR, d->d_name);
}

fin = fopen(buf, "r");
if(fin == NULL) {
perror(buf);
Expand Down

0 comments on commit 3d32df2

Please sign in to comment.