summaryrefslogtreecommitdiffstats
path: root/src/file_ace.c
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2011-10-15 12:06:55 +0200
committerChristophe Grenier <grenier@cgsecurity.org>2011-10-15 12:06:55 +0200
commitbbd33e63af7fb5f51de719a986f52f00bc6ce614 (patch)
treed1f9c6b1796d845454a0e2e4db1b7a283fb3a92c /src/file_ace.c
parent8fa226e65b0c858cd57e825afad246046f580542 (diff)
PhotoRec: check fseek return value in ACE file validation
Diffstat (limited to 'src/file_ace.c')
-rw-r--r--src/file_ace.c28
1 files changed, 24 insertions, 4 deletions
diff --git a/src/file_ace.c b/src/file_ace.c
index 6309e95..7d70b1a 100644
--- a/src/file_ace.c
+++ b/src/file_ace.c
@@ -70,11 +70,11 @@ typedef struct header_ace ace_header_t;
static void file_check_ace(file_recovery_t *file_recovery)
{
- fseek(file_recovery->handle, 0, SEEK_SET);
-
file_recovery->offset_error = 0;
file_recovery->offset_ok = 0;
file_recovery->file_size = 0;
+ if(fseek(file_recovery->handle, 0, SEEK_SET)<0)
+ return ;
#ifdef DEBUG_ACE
log_trace("file_check_ace\n");
#endif
@@ -83,9 +83,16 @@ static void file_check_ace(file_recovery_t *file_recovery)
ace_header_t h;
if(fread(&h, sizeof(h), 1, file_recovery->handle)!=1)
{
+ file_recovery->offset_error=file_recovery->file_size;
+ file_recovery->file_size=0;
+ return ;
+ }
+ if(fseek(file_recovery->handle, -sizeof(h)+4, SEEK_CUR)<0)
+ {
+ file_recovery->offset_error=file_recovery->file_size;
+ file_recovery->file_size=0;
return ;
}
- fseek(file_recovery->handle, -sizeof(h)+4, SEEK_CUR);
#ifdef DEBUG_ACE
log_trace("file_ace: Block header at 0x%08lx: CRC16=0x%04X size=%u type=%u"
@@ -100,6 +107,8 @@ static void file_check_ace(file_recovery_t *file_recovery)
#ifdef DEBUG_ACE
log_trace("file_ace: Invalid block type %u\n", h.type);
#endif
+ file_recovery->offset_error=file_recovery->file_size;
+ file_recovery->file_size=0;
return ;
}
@@ -109,6 +118,8 @@ static void file_check_ace(file_recovery_t *file_recovery)
#ifdef DEBUG_ACE
log_trace("file_ace: Invalid block size %u\n", le16(h.size));
#endif
+ file_recovery->offset_error=file_recovery->file_size;
+ file_recovery->file_size=0;
return ;
}
@@ -129,6 +140,8 @@ static void file_check_ace(file_recovery_t *file_recovery)
#ifdef DEBUG_ACE
log_trace("file_ace: truncated file\n");
#endif
+ file_recovery->offset_error=file_recovery->file_size;
+ file_recovery->file_size=0;
return ;
}
crc32=get_crc32(buffer, count, crc32);
@@ -139,6 +152,8 @@ static void file_check_ace(file_recovery_t *file_recovery)
#ifdef DEBUG_ACE
log_trace("file_ace: bad CRC32: %04X vs %04X\n", le16(h.crc16), crc32);
#endif
+ file_recovery->offset_error=file_recovery->file_size;
+ file_recovery->file_size=0;
return ;
}
}
@@ -148,7 +163,12 @@ static void file_check_ace(file_recovery_t *file_recovery)
if (le16(h.flags)&1)
{
file_recovery->file_size += le32(h.addsize);
- fseek(file_recovery->handle, file_recovery->file_size, SEEK_SET);
+ if(fseek(file_recovery->handle, file_recovery->file_size, SEEK_SET)<0)
+ {
+ file_recovery->offset_error=file_recovery->file_size;
+ file_recovery->file_size=0;
+ return;
+ }
}
}
}