Skip to content

Commit

Permalink
Fix possible Null pointer dereference issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
jfdelnero committed Nov 9, 2023
1 parent 6d3c2ca commit f660638
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/fs_handles_db.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,11 +276,14 @@ fs_entry * search_entry(fs_handles_db * db, filefoundinfo *fileinfo, uint32_t pa
{
fs_entry * entry_list;

if( !db )
return NULL;

entry_list = db->entry_list;

while( entry_list )
{
if( !( entry_list->flags & ENTRY_IS_DELETED ) && ( entry_list->parent == parent ) && ( entry_list->storage_id == storage_id ) )
if( !( entry_list->flags & ENTRY_IS_DELETED ) && ( entry_list->parent == parent ) && ( entry_list->storage_id == storage_id ) && entry_list->name )
{
if( !strcmp(entry_list->name,fileinfo->filename) )
{
Expand Down Expand Up @@ -540,11 +543,16 @@ char * build_full_path(fs_handles_db * db,char * root_path,fs_entry * entry)

full_path = NULL;

if( !entry )
return full_path;

curentry = entry;
totallen = 0;
do
{
totallen += strlen(curentry->name);
if(curentry->name)
totallen += strlen(curentry->name);

totallen++; // '/'

if( curentry->parent && ( curentry->parent != 0xFFFFFFFF ) )
Expand Down Expand Up @@ -572,11 +580,15 @@ char * build_full_path(fs_handles_db * db,char * root_path,fs_entry * entry)

do
{
namelen = strlen(curentry->name);
if(curentry->name)
namelen = strlen(curentry->name);
else
namelen = 0;

full_path_offset -= namelen;

memcpy(&full_path[full_path_offset],curentry->name,namelen);
if( namelen )
memcpy(&full_path[full_path_offset],curentry->name,namelen);

full_path_offset--;

Expand All @@ -597,7 +609,8 @@ char * build_full_path(fs_handles_db * db,char * root_path,fs_entry * entry)
memcpy(&full_path[0],root_path,strlen(root_path));
}

PRINT_DEBUG("build_full_path : %s -> %s",entry->name, full_path);
if(entry->name)
PRINT_DEBUG("build_full_path : %s -> %s",entry->name, full_path);
}

return full_path;
Expand Down

0 comments on commit f660638

Please sign in to comment.