Skip to content

Commit

Permalink
Check malloc
Browse files Browse the repository at this point in the history
  • Loading branch information
nigelhorne committed Dec 27, 2024
1 parent a0c70ba commit 7ff1870
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions sniff2ban.c
Original file line number Diff line number Diff line change
Expand Up @@ -2531,19 +2531,29 @@ setup_apache_hosts(void)
p = &p[10];
else if((p = strstr(buf, "ServerAlias")) != NULL)
p = &p[11];
else
else
continue;

while(isspace(*p))
/* Trim leading whitespace */
while(isspace((unsigned char)*p))
p++;
if(*p == '\0')

if(*p == '\0') /* Skip if empty */
continue;

if(apachehosts == NULL)
tail = apachehosts = malloc(sizeof(struct apachehosts));
else {
tail->next = malloc(sizeof(struct apachehosts));
tail = tail->next;
}
if(tail == NULL)
fputs("Memory allocation failure\n", stderr);
fclose(fin);
closedir(dirp);
return;
}

q = strchr(p, '\n');
if(q)
*q = '\0';
Expand Down

0 comments on commit 7ff1870

Please sign in to comment.