From 117d5d5aa4e33bf91243717e40dc4096a52577f3 Mon Sep 17 00:00:00 2001 From: Greg DiCristofaro <gregd@basistech.com> Date: Tue, 27 Sep 2022 09:34:13 -0400 Subject: [PATCH] fixes --- tsk/fs/ntfs_dent.cpp | 64 +++++++++++++++----------------------------- 1 file changed, 21 insertions(+), 43 deletions(-) diff --git a/tsk/fs/ntfs_dent.cpp b/tsk/fs/ntfs_dent.cpp index 456a45960..3bc7a78ff 100644 --- a/tsk/fs/ntfs_dent.cpp +++ b/tsk/fs/ntfs_dent.cpp @@ -1023,9 +1023,9 @@ ntfs_dir_open_meta(TSK_FS_INFO * a_fs, TSK_FS_DIR ** a_fs_dir, return TSK_COR; } - // Taking 128 MiB as an arbitrary upper bound + // Taking 128 MiB as an arbitrary upper bound if (fs_attr_idx->nrd.allocsize > (128 * 1024 * 1024)) { - tsk_error_reset(); + tsk_error_reset(); tsk_error_set_errno(TSK_ERR_FS_INODE_COR); tsk_error_set_errstr ("fs_attr_idx->nrd.allocsize value out of bounds"); @@ -1036,11 +1036,11 @@ ntfs_dir_open_meta(TSK_FS_INFO * a_fs, TSK_FS_DIR ** a_fs_dir, * Copy the index allocation run into a big buffer */ idxalloc_len = fs_attr_idx->nrd.allocsize; - // default to null unless length is greater than 0 - idxalloc = NULL; - if ((idxalloc_len > 0) && ((idxalloc = (char *)tsk_malloc((size_t)idxalloc_len)) == NULL)) { - return TSK_ERR; - } + // default to null unless length is greater than 0 + idxalloc = NULL; + if ((idxalloc_len > 0) && ((idxalloc = (char *)tsk_malloc((size_t)idxalloc_len)) == NULL)) { + return TSK_ERR; + } /* Fill in the loading data structure */ load_file.total = load_file.left = (size_t) idxalloc_len; @@ -1050,21 +1050,17 @@ ntfs_dir_open_meta(TSK_FS_INFO * a_fs, TSK_FS_DIR ** a_fs_dir, tsk_fprintf(stderr, "ntfs_dir_open_meta: Copying $IDX_ALLOC into buffer\n"); - if (tsk_fs_attr_walk(fs_attr_idx, - TSK_FS_FILE_WALK_FLAG_SLACK, tsk_fs_load_file_action, - (void *)&load_file)) { - if (idxalloc != NULL) { - free(idxalloc); - } + if (tsk_fs_attr_walk(fs_attr_idx, + TSK_FS_FILE_WALK_FLAG_SLACK, tsk_fs_load_file_action, + (void *) &load_file)) { + free(idxalloc); tsk_error_errstr2_concat(" - ntfs_dir_open_meta"); return TSK_COR; // this could be an error though } /* Not all of the directory was copied, so we exit */ if (load_file.left > 0) { - if (idxalloc != NULL) { - free(idxalloc); - } + free(idxalloc); tsk_error_reset(); tsk_error_set_errno(TSK_ERR_FS_FWALK); @@ -1099,9 +1095,7 @@ ntfs_dir_open_meta(TSK_FS_INFO * a_fs, TSK_FS_DIR ** a_fs_dir, tsk_error_set_errno(TSK_ERR_FS_INODE_COR); tsk_error_set_errstr ("ntfs_dir_open_meta: Not enough data in idxalloc buffer for an idxrec."); - if (idxalloc != NULL) { - free(idxalloc); - } + free(idxalloc); return TSK_COR; } @@ -1141,9 +1135,7 @@ ntfs_dir_open_meta(TSK_FS_INFO * a_fs, TSK_FS_DIR ** a_fs_dir, /* remove the update sequence in the index record */ if (ntfs_fix_idxrec(ntfs, idxrec_p, rec_len)) { - if (idxalloc != NULL) { - free(idxalloc); - } + free(idxalloc); return TSK_COR; } @@ -1169,9 +1161,7 @@ ntfs_dir_open_meta(TSK_FS_INFO * a_fs, TSK_FS_DIR ** a_fs_dir, tsk_error_set_errstr ("Error: Index list offsets are invalid on entry: %" PRIuINUM, fs_dir->fs_file->meta->addr); - if (idxalloc != NULL) { - free(idxalloc); - } + free(idxalloc); return TSK_COR; } @@ -1185,9 +1175,7 @@ ntfs_dir_open_meta(TSK_FS_INFO * a_fs, TSK_FS_DIR ** a_fs_dir, idxelist->begin_off)); // stop if we get an error, record if we get corruption if (retval_tmp == TSK_ERR) { - if (idxalloc != NULL) { - free(idxalloc); - } + free(idxalloc); return TSK_ERR; } else if (retval_tmp == TSK_COR) { @@ -1216,9 +1204,7 @@ ntfs_dir_open_meta(TSK_FS_INFO * a_fs, TSK_FS_DIR ** a_fs_dir, /* remove the update sequence */ if (ntfs_fix_idxrec(ntfs, idxrec_p, rec_len)) { - if (idxalloc != NULL) { - free(idxalloc); - } + free(idxalloc); return TSK_COR; } @@ -1229,9 +1215,7 @@ ntfs_dir_open_meta(TSK_FS_INFO * a_fs, TSK_FS_DIR ** a_fs_dir, tsk_error_set_errstr ("Error: Index list offsets are invalid on entry: %" PRIuINUM, fs_dir->fs_file->meta->addr); - if (idxalloc != NULL) { - free(idxalloc); - } + free(idxalloc); return TSK_COR; } @@ -1253,9 +1237,7 @@ ntfs_dir_open_meta(TSK_FS_INFO * a_fs, TSK_FS_DIR ** a_fs_dir, tsk_error_set_errstr ("Error: Index list offsets are invalid on entry: %" PRIuINUM, fs_dir->fs_file->meta->addr); - if (idxalloc != NULL) { - free(idxalloc); - } + free(idxalloc); return TSK_COR; } @@ -1268,9 +1250,7 @@ ntfs_dir_open_meta(TSK_FS_INFO * a_fs, TSK_FS_DIR ** a_fs_dir, idxelist->begin_off)); // stop if we get an error, record if we get corruption if (retval_tmp == TSK_ERR) { - if (idxalloc != NULL) { - free(idxalloc); - } + free(idxalloc); return TSK_ERR; } else if (retval_tmp == TSK_COR) { @@ -1278,9 +1258,7 @@ ntfs_dir_open_meta(TSK_FS_INFO * a_fs, TSK_FS_DIR ** a_fs_dir, } } - if (idxalloc != NULL) { - free(idxalloc); - } + free(idxalloc); } -- GitLab