Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions extras/scandir.c
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
}
close(fd);
return 0;
}
#endif