summaryrefslogtreecommitdiffstats
path: root/src/file_torrent.c
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2014-08-13 08:43:51 +0200
committerChristophe Grenier <grenier@cgsecurity.org>2014-08-13 08:43:51 +0200
commit3f57b7aa55e4c275a97af3d526d8e6b4f738daee (patch)
treed538829f7af66437627963ea05b9fca38baf68c2 /src/file_torrent.c
parent9d8d1a4367a3fdffd02c70f91af9f475e482f79e (diff)
PhotoRec: stricter check for .torrent
Diffstat (limited to 'src/file_torrent.c')
-rw-r--r--src/file_torrent.c25
1 files changed, 8 insertions, 17 deletions
diff --git a/src/file_torrent.c b/src/file_torrent.c
index 99c1ea0..d0b8dd3 100644
--- a/src/file_torrent.c
+++ b/src/file_torrent.c
@@ -31,7 +31,6 @@
#include "filegen.h"
static void register_header_check_torrent(file_stat_t *file_stat);
-static int header_check_torrent(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new);
const file_hint_t file_hint_torrent= {
.extension="torrent",
@@ -43,24 +42,16 @@ const file_hint_t file_hint_torrent= {
.register_header_check=&register_header_check_torrent
};
-static const unsigned char torrent_header[11]= {
- 'd' , '8' , ':', 'a' , 'n' , 'n' , 'o' , 'u' ,
- 'n' , 'c' , 'e'
-};
-
-static void register_header_check_torrent(file_stat_t *file_stat)
+static int header_check_torrent(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new)
{
- register_header_check(0, torrent_header, sizeof(torrent_header), &header_check_torrent, file_stat);
+ if(buffer[11]<'0' || buffer[11]>'9')
+ return 0;
+ reset_file_recovery(file_recovery_new);
+ file_recovery_new->extension=file_hint_torrent.extension;
+ return 1;
}
-static int header_check_torrent(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new)
+static void register_header_check_torrent(file_stat_t *file_stat)
{
- if(memcmp(&buffer[0], torrent_header, sizeof(torrent_header))==0)
- {
- reset_file_recovery(file_recovery_new);
- file_recovery_new->extension=file_hint_torrent.extension;
- return 1;
- }
- return 0;
+ register_header_check(0, "d8:announce", 11, &header_check_torrent, file_stat);
}
-