summaryrefslogtreecommitdiffstats
path: root/src/file_tib.c
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2011-10-15 12:10:51 +0200
committerChristophe Grenier <grenier@cgsecurity.org>2011-10-15 12:10:51 +0200
commitc63960562842934ff3929b2d537ecd901027d5cb (patch)
tree1fcee29237b068465621b109c60ddb63e4597475 /src/file_tib.c
parent76887c43cb31eb37666db1f83466bfd0d63825dc (diff)
PhotoRec: check fseek return value in tib file validation
Diffstat (limited to 'src/file_tib.c')
-rw-r--r--src/file_tib.c19
1 files changed, 7 insertions, 12 deletions
diff --git a/src/file_tib.c b/src/file_tib.c
index 2b0b0c4..ecb2d88 100644
--- a/src/file_tib.c
+++ b/src/file_tib.c
@@ -75,33 +75,28 @@ static void file_check_tib(file_recovery_t *file_recovery)
unsigned char*buffer=(unsigned char*)MALLOC(512);
int64_t file_size=file_recovery->calculated_file_size-512;
file_recovery->file_size = file_recovery->calculated_file_size;
- if(fseek(file_recovery->handle, file_size, SEEK_SET)<0)
- {
- free(buffer);
- return;
- }
- if(fread(buffer, 1, 512, file_recovery->handle)<=0)
+ if(fseek(file_recovery->handle, file_size, SEEK_SET) < 0 ||
+ fread(buffer, 1, 512, file_recovery->handle) <= 0)
{
free(buffer);
+ file_recovery->file_size=0;
return;
}
if(memcmp(&buffer[512 - sizeof(tib2_footer)], tib2_footer, sizeof(tib2_footer))==0)
{
free(buffer);
+ file_recovery->file_size=0;
return;
}
for(; file_size>0; file_size-=512)
{
unsigned int i;
- if(fseek(file_recovery->handle, file_size, SEEK_SET)<0)
- {
- free(buffer);
- return;
- }
- if(fread(buffer, 1, 512, file_recovery->handle)<=0)
+ if(fseek(file_recovery->handle, file_size, SEEK_SET) < 0 ||
+ fread(buffer, 1, 512, file_recovery->handle) <= 0)
{
free(buffer);
+ file_recovery->file_size=0;
return;
}
for(i=0; i<512 && buffer[i]==0; i++);