Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

misc oom and possible memory leak fix #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
misc oom and possible memory leak fix
  • Loading branch information
Lea committed Jun 13, 2018
commit e139b87835994d007fbd64eead6c1455d7b8cf4e
16 changes: 12 additions & 4 deletions extras/scandir.c
Expand Up @@ -56,18 +56,26 @@ scandir(const char *dir, struct dirent ***namelist,

while (NULL != readdir(d))
count++;


closedir(d);

names = malloc(sizeof (struct dirent *) * count);
if (!names)
return -1;

closedir(d);
d = opendir(dir);
if (NULL == d)
if (NULL == d) {
free(names);
return -1;
}

while (NULL != (current = readdir(d))) {
if (NULL == select || select(current)) {
struct dirent *copyentry = malloc(current->d_reclen);

/* FIXME: OOM, silently skip it?*/
if (!copyentry)
continue;

memcpy(copyentry, current, current->d_reclen);

names[pos] = copyentry;
Expand Down
2 changes: 1 addition & 1 deletion extras/strutil.c
Expand Up @@ -13,7 +13,7 @@ char *strstr(char *s1, char *s2)

if (*s2 == '\0') /* everything matches empty string */
return s1;
for (p = s1; (p = strchr(p, *s2)) != NULL; p = strchr(p + 1, *s2)) {
for (p = s1; (p = strchr(p, *s2)) != NULL; p++) {
if (strncmp(p, s2, len) == 0)
return (p);
}
Expand Down
5 changes: 4 additions & 1 deletion src/index_dir.c
Expand Up @@ -383,6 +383,9 @@ int main(int argc, char *argv[])
timeptr = gmtime(&timep);
#endif
now = strdup(asctime(timeptr));
if (!now) {
return -1;
}
now[strlen(now) - 1] = '\0';
#ifdef USE_LOCALTIME
printf("</table>\n<hr noshade>\nIndex generated %s %s\n"
Expand All @@ -393,6 +396,6 @@ int main(int argc, char *argv[])
"<!-- This program is part of the Boa Webserver Copyright (C) 1991-2002 http://www.boa.org -->\n"
"</body>\n</html>\n", now);
#endif

free(now);
return 0;
}
4 changes: 2 additions & 2 deletions src/log.c
Expand Up @@ -192,8 +192,8 @@ static char *escape_pathname(const char *inp)
}
escaped = malloc (4 * strlen(inp) + 1);
if (!escaped) {
perror("malloc");
return NULL;
perror("malloc");
return NULL;
}
for (d = escaped, s = (const unsigned char *)inp; *s; s++) {
if (needs_escape (*s)) {
Expand Down
1 change: 1 addition & 0 deletions src/sublog.c
Expand Up @@ -142,6 +142,7 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
}
close(fd);
return 0;
}
#endif