@@ -294,6 +294,10 @@ TskAutoDbJava::addPoolInfoAndVS(const TSK_POOL_INFO *pool_info, int64_t parObjId
294294 poolObjIdj, TSK_VS_TYPE_APFS, pool_info->img_offset , (uint64_t )pool_info->block_size );
295295 objId = (int64_t )objIdj;
296296
297+ if (objId < 0 ) {
298+ return TSK_ERR;
299+ }
300+
297301 saveObjectInfo (objId, poolObjId, TSK_DB_OBJECT_TYPE_VS);
298302 return TSK_OK;
299303}
@@ -671,13 +675,14 @@ TskAutoDbJava::addFile(TSK_FS_FILE* fs_file,
671675 // See github issue #756 on why initsize and not size.
672676 // - The data is not compressed
673677 if ((fs_attr != NULL )
678+ && (fs_file->meta != NULL )
674679 && ((strlen (name) > 0 ) && (!TSK_FS_ISDOT (name)))
675680 && (!(fs_file->meta ->flags & TSK_FS_META_FLAG_COMP))
676681 && (fs_attr->flags & TSK_FS_ATTR_NONRES)
677682 && (fs_attr->nrd .allocsize > fs_attr->nrd .initsize )) {
678- strncat (name, " -slack" , 6 );
683+ strncat (name, " -slack" , nlen - strlen (name) - 1 );
679684 if (strlen (extension) > 0 ) {
680- strncat (extension, " -slack" , 6 );
685+ strncat (extension, " -slack" , sizeof (extension) - strlen (extension) - 1 );
681686 }
682687 jstring slackNamej;
683688 if (createJString (name, slackNamej) != TSK_OK) {
@@ -1098,6 +1103,13 @@ TskAutoDbJava::addImageDetails(const char* deviceId)
10981103
10991104 for (int i = 0 ; i < m_img_info->num_img ; i++) {
11001105 char * img2 = (char *)tsk_malloc (1024 * sizeof (char ));
1106+ if (img2 == NULL ) {
1107+ for (int j = 0 ; j < i; j++) {
1108+ free (img_ptrs[j]);
1109+ }
1110+ free (img_ptrs);
1111+ return 1 ;
1112+ }
11011113 UTF8 *ptr8;
11021114 UTF16 *ptr16;
11031115
@@ -1112,11 +1124,16 @@ TskAutoDbJava::addImageDetails(const char* deviceId)
11121124 tsk_error_reset ();
11131125 tsk_error_set_errno (TSK_ERR_AUTO_UNICODE);
11141126 tsk_error_set_errstr (" Error converting image to UTF-8\n " );
1127+ free (img2);
1128+ for (int j = 0 ; j < i; j++) {
1129+ free (img_ptrs[j]);
1130+ }
1131+ free (img_ptrs);
11151132 return 1 ;
11161133 }
11171134 img_ptrs[i] = img2;
11181135 }
1119- #else
1136+ #else
11201137 img_ptrs = m_img_info->images ;
11211138#endif
11221139
@@ -1417,9 +1434,12 @@ uint8_t
14171434 }
14181435
14191436 if (m_imageWriterEnabled) {
1420- tsk_img_writer_create (m_img_info, m_imageWriterPath);
1437+ if (tsk_img_writer_create (m_img_info, m_imageWriterPath)) {
1438+ registerError ();
1439+ return 1 ;
1440+ }
14211441 }
1422-
1442+
14231443 if (m_addFileSystems) {
14241444 return addFilesInImgToDb ();
14251445 } else {
@@ -1497,7 +1517,10 @@ uint8_t
14971517 return 1 ;
14981518 }
14991519 if (m_imageWriterEnabled) {
1500- tsk_img_writer_create (m_img_info, m_imageWriterPath);
1520+ if (tsk_img_writer_create (m_img_info, m_imageWriterPath)) {
1521+ registerError ();
1522+ return 1 ;
1523+ }
15011524 }
15021525
15031526 if (m_addFileSystems) {
@@ -1682,7 +1705,8 @@ TSK_WALK_RET_ENUM TskAutoDbJava::fsWalkUnallocBlocksCb(const TSK_FS_BLOCK *a_blo
16821705 TskAutoDbJava & tskAutoDbJava = unallocBlockWlkTrack->tskAutoDbJava ;
16831706 if (tskAutoDbJava.addUnallocBlockFile (tskAutoDbJava.m_curUnallocDirId ,
16841707 unallocBlockWlkTrack->fsObjId , unallocBlockWlkTrack->size , unallocBlockWlkTrack->ranges , fileObjId, tskAutoDbJava.m_curImgId ) == TSK_ERR) {
1685- // @@@ Handle error -> Don't have access to registerError() though...
1708+ tskAutoDbJava.registerError ();
1709+ return TSK_WALK_STOP;
16861710 }
16871711
16881712 // reset
@@ -1748,17 +1772,19 @@ TSK_RETVAL_ENUM TskAutoDbJava::addFsInfoUnalloc(const TSK_DB_FS_INFO & dbFsInfo)
17481772 return TSK_OK;
17491773 }
17501774
1751- // handle creation of the last range
1752- // make range inclusive from curBlockStart to prevBlock
1753- const uint64_t byteStart = unallocBlockWlkTrack.curRangeStart * fsInfo->block_size + fsInfo->offset ;
1754- const uint64_t byteLen = (1 + unallocBlockWlkTrack.prevBlock - unallocBlockWlkTrack.curRangeStart ) * fsInfo->block_size ;
1755- unallocBlockWlkTrack.ranges .push_back (TSK_DB_FILE_LAYOUT_RANGE (byteStart, byteLen, unallocBlockWlkTrack.nextSequenceNo ++));
1756- int64_t fileObjId = 0 ;
1775+ // handle creation of the last range (only if the walk visited at least one block)
1776+ if (!unallocBlockWlkTrack.isStart ) {
1777+ // make range inclusive from curBlockStart to prevBlock
1778+ const uint64_t byteStart = unallocBlockWlkTrack.curRangeStart * fsInfo->block_size + fsInfo->offset ;
1779+ const uint64_t byteLen = (1 + unallocBlockWlkTrack.prevBlock - unallocBlockWlkTrack.curRangeStart ) * fsInfo->block_size ;
1780+ unallocBlockWlkTrack.ranges .push_back (TSK_DB_FILE_LAYOUT_RANGE (byteStart, byteLen, unallocBlockWlkTrack.nextSequenceNo ++));
1781+ int64_t fileObjId = 0 ;
17571782
1758- if (addUnallocBlockFile (m_curUnallocDirId, dbFsInfo.objId , unallocBlockWlkTrack.size , unallocBlockWlkTrack.ranges , fileObjId, m_curImgId) == TSK_ERR) {
1759- registerError ();
1760- tsk_fs_close (fsInfo);
1761- return TSK_ERR;
1783+ if (addUnallocBlockFile (m_curUnallocDirId, dbFsInfo.objId , unallocBlockWlkTrack.size , unallocBlockWlkTrack.ranges , fileObjId, m_curImgId) == TSK_ERR) {
1784+ registerError ();
1785+ tsk_fs_close (fsInfo);
1786+ return TSK_ERR;
1787+ }
17621788 }
17631789
17641790 // cleanup
@@ -1941,11 +1967,7 @@ TSK_RETVAL_ENUM TskAutoDbJava::addUnallocImageSpaceToDb() {
19411967 return TSK_ERR;
19421968 }
19431969 else {
1944- TSK_DB_FILE_LAYOUT_RANGE tempRange (0 , imgSize, 0 );
19451970 // add unalloc block file for the entire image
1946- vector<TSK_DB_FILE_LAYOUT_RANGE> ranges;
1947- ranges.push_back (tempRange);
1948- int64_t fileObjId = 0 ;
19491971 if (TSK_ERR == addUnallocBlockFileInChunks (0 , imgSize, m_curImgId, m_curImgId)) {
19501972 return TSK_ERR;
19511973 }
0 commit comments