Fix unbounded writes

This commit is contained in:
Martin Lund 2024-06-15 14:59:31 +02:00
parent 6ec2ac19d0
commit be4fc0908f
3 changed files with 3 additions and 11 deletions

View file

@ -150,14 +150,7 @@ char* fs_search_directory(const char *dir_path, const char *dirname)
// If it's a directory, check if it's the one we're looking for
if (strcmp(entry->d_name, dirname) == 0)
{
char* result = malloc(strlen(path) + 1);
if (result == NULL)
{
// Error allocating memory
closedir(dir);
return NULL;
}
strcpy(result, path);
char *result = strndup(path, PATH_MAX);
closedir(dir);
return result;
}