Commit f268768d authored by Richard Genoud's avatar Richard Genoud Committed by Tom Rini
Browse files

fs/squashfs: sqfs_opendir: fix some memory leaks and dangling pointers



When trying to load an non-existing file, the cpu hangs!
Signed-off-by: default avatarRichard Genoud <richard.genoud@posteo.net>
parent 1b1e0c01
...@@ -821,22 +821,37 @@ int sqfs_opendir(const char *filename, struct fs_dir_stream **dirsp) ...@@ -821,22 +821,37 @@ int sqfs_opendir(const char *filename, struct fs_dir_stream **dirsp)
if (!dirs) if (!dirs)
return -EINVAL; return -EINVAL;
/* these should be set to NULL to prevent dangling pointers */
dirs->dir_header = NULL;
dirs->entry = NULL;
dirs->table = NULL;
dirs->inode_table = NULL;
dirs->dir_table = NULL;
ret = sqfs_read_inode_table(&inode_table); ret = sqfs_read_inode_table(&inode_table);
if (ret) if (ret) {
return -EINVAL; ret = -EINVAL;
goto free_dirs;
}
metablks_count = sqfs_read_directory_table(&dir_table, &pos_list); metablks_count = sqfs_read_directory_table(&dir_table, &pos_list);
if (metablks_count < 1) if (metablks_count < 1) {
return -EINVAL; ret = -EINVAL;
goto free_inode_table;
}
/* Tokenize filename */ /* Tokenize filename */
token_count = sqfs_count_tokens(filename); token_count = sqfs_count_tokens(filename);
if (token_count < 0) if (token_count < 0) {
return -EINVAL; ret = -EINVAL;
goto free_inode_table;
}
path = strdup(filename); path = strdup(filename);
if (!path) if (!path) {
return -ENOMEM; ret = -EINVAL;
goto free_inode_table;
}
token_list = malloc(token_count * sizeof(char *)); token_list = malloc(token_count * sizeof(char *));
if (!token_list) { if (!token_list) {
...@@ -882,6 +897,12 @@ free_tokens: ...@@ -882,6 +897,12 @@ free_tokens:
free(pos_list); free(pos_list);
free_path: free_path:
free(path); free(path);
free_inode_table:
if (ret)
free(inode_table);
free_dirs:
if (ret)
free(dirs);
return ret; return ret;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment