summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2013-11-01 13:38:06 +0100
committerChristophe Grenier <grenier@cgsecurity.org>2013-11-01 13:38:06 +0100
commit7172224ac4cbe9f4c40db5df505cfe8725108e53 (patch)
tree6b0d5445d46c577975c28b8192c0af39f316d5bc
parent9440623c9768c7e235be10ed595149fdb644a911 (diff)
Fix various issues reported by Coverity scan
-rw-r--r--src/parti386.c3
-rw-r--r--src/phbf.c3
-rw-r--r--src/photorec.c7
-rw-r--r--src/savehdr.c1
-rw-r--r--src/setdate.c12
-rw-r--r--src/swap.c2
6 files changed, 15 insertions, 13 deletions
diff --git a/src/parti386.c b/src/parti386.c
index e70ccba..13374a6 100644
--- a/src/parti386.c
+++ b/src/parti386.c
@@ -540,7 +540,6 @@ static list_part_t *get_ext_data_i386(disk_t *disk_car, list_part_t *list_part,
log_dos_entry(p);
if(is_extended(p->sys_ind))
{
- partition_next_ext=new_partition;
i386_entry2partition(disk_car, partition_main_ext->part_offset, new_partition, p, STATUS_EXT_IN_EXT,order,verbose,saveheader);
aff_part_buffer(AFF_PART_ORDER|AFF_PART_STATUS,disk_car,new_partition);
if(new_partition->errcode!=BAD_NOERR)
@@ -598,6 +597,8 @@ static list_part_t *get_ext_data_i386(disk_t *disk_car, list_part_t *list_part,
list_part=insert_new_partition(list_part, new_partition, 0, &insert_error);
if(insert_error>0)
free(new_partition);
+ else if(is_extended(p->sys_ind))
+ partition_next_ext=new_partition;
}
}
partition_ext=partition_next_ext;
diff --git a/src/phbf.c b/src/phbf.c
index 2fd705d..5091d5f 100644
--- a/src/phbf.c
+++ b/src/phbf.c
@@ -364,7 +364,8 @@ static bf_status_t photorec_bf_pad(struct ph_param *params, file_recovery_t *fil
uint64_t file_size_backup;
nbr=0;
offset_error_tmp=file_recovery->offset_error;
- fseek(file_recovery->handle, file_recovery->file_size, SEEK_SET);
+ if(fseek(file_recovery->handle, file_recovery->file_size, SEEK_SET) < 0)
+ return BF_ENOENT;
#if 1
if(file_recovery->data_check!=NULL)
{
diff --git a/src/photorec.c b/src/photorec.c
index e731ef2..af7bb99 100644
--- a/src/photorec.c
+++ b/src/photorec.c
@@ -71,7 +71,7 @@ static void list_space_used(const file_recovery_t *file_recovery, const unsigned
struct td_list_head *tmp;
uint64_t file_size=0;
uint64_t file_size_on_disk=0;
- if(file_recovery->filename==NULL)
+ if(file_recovery->filename[0]=='\0')
return;
log_info("%s\t",file_recovery->filename);
td_list_for_each(tmp, &file_recovery->location.list)
@@ -617,7 +617,8 @@ static void file_finish_aux(file_recovery_t *file_recovery, struct ph_param *par
params->dir_num=photorec_mkdir(params->recup_dir, params->dir_num+1);
}
if(params->status!=STATUS_EXT2_ON_SAVE_EVERYTHING &&
- params->status!=STATUS_EXT2_OFF_SAVE_EVERYTHING)
+ params->status!=STATUS_EXT2_OFF_SAVE_EVERYTHING &&
+ file_recovery->file_stat!=NULL)
file_recovery->file_stat->recovered++;
}
}
@@ -822,7 +823,7 @@ static alloc_data_t *file_truncate_aux(alloc_data_t *space, alloc_data_t *file,
static alloc_data_t *file_truncate(alloc_data_t *space, file_recovery_t *file, const unsigned int sector_size, const unsigned int blocksize)
{
alloc_data_t *datanext;
- if(file->filename!=NULL)
+ if(file->filename[0]!='\0')
log_info("%s\t", file->filename);
else
log_info("?\t");
diff --git a/src/savehdr.c b/src/savehdr.c
index ebe5b94..6c1a3b6 100644
--- a/src/savehdr.c
+++ b/src/savehdr.c
@@ -145,6 +145,7 @@ backup_disk_t *partition_load(const disk_t *disk_car, const int verbose)
if(pos!=NULL)
{
strncpy(new_backup->description,++pos,sizeof(new_backup->description));
+ new_backup->description[sizeof(new_backup->description)-1]='\0';
}
}
else if(new_backup!=NULL)
diff --git a/src/setdate.c b/src/setdate.c
index dc0c758..d05e716 100644
--- a/src/setdate.c
+++ b/src/setdate.c
@@ -38,23 +38,21 @@
*
* Give a file a particular date and time.
*
- * Return: 1 Success, set the file's date and time
- * 0 Error, failed to change the file's date and time
+ * Return: 0 Success, set the file's date and time
+ * -1 Error, failed to change the file's date and time
*/
int set_date(const char *pathname, time_t actime, time_t modtime)
{
#ifdef HAVE_UTIME
struct utimbuf ut;
if (!pathname)
- return 0;
+ return -1;
ut.actime = actime;
ut.modtime = modtime;
if (utime(pathname, &ut)) {
log_error("ERROR: Couldn't set the file's date and time for %s\n", pathname);
- return 0;
+ return -1;
}
- return 1;
-#else
- return 0;
#endif
+ return 0;
}
diff --git a/src/swap.c b/src/swap.c
index 488142b..3205eec 100644
--- a/src/swap.c
+++ b/src/swap.c
@@ -160,7 +160,7 @@ int recover_Linux_SWAP(const union swap_header *swap_header, partition_t *partit
for(j=7;j>=0;j--)
if((swap_header->magic8k.reserved[i]&(1<<j))!=(char)0)
break;
- partition->part_size=(uint64_t)((8*i+j+1)*PAGE_8K);
+ partition->part_size=(uint64_t)(8*i+j+1)*PAGE_8K;
}
break;
case UP_LINSWAP2_8K: