From 1b0a138bbcf4e6319aff0f1b090e7bc1c18dea70 Mon Sep 17 00:00:00 2001 From: Christophe Grenier Date: Wed, 24 Feb 2021 17:34:31 +0100 Subject: [PATCH] src/file_mb.c: add frama-c annotations --- src/file_mb.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/file_mb.c b/src/file_mb.c index 860bc05e..b344ad4a 100644 --- a/src/file_mb.c +++ b/src/file_mb.c @@ -32,6 +32,7 @@ #include "filegen.h" #include "common.h" +/*@ requires \valid(file_stat); */ static void register_header_check_mb(file_stat_t *file_stat); const file_hint_t file_hint_mb= { @@ -50,20 +51,43 @@ struct maya_header char magic2[8]; } __attribute__ ((gcc_struct, __packed__)); +/*@ + @ requires buffer_size >= sizeof(struct maya_header); + @ requires \valid_read(buffer+(0..buffer_size-1)); + @ requires valid_file_recovery(file_recovery); + @ requires \valid(file_recovery_new); + @ requires file_recovery_new->blocksize > 0; + @ requires separation: \separated(&file_hint_mb, buffer+(..), file_recovery, file_recovery_new); + @ assigns *file_recovery_new; + @ ensures \result == 0 || \result == 1; + @ ensures \result!=0 ==> valid_file_recovery(file_recovery_new); + @*/ static int header_check_mb(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 struct maya_header *hdr=(const struct maya_header *)buffer; - if(memcmp(buffer,"FOR4",4)!=0 || be32(hdr->size) < 8) + const unsigned int size=be32(hdr->size); + if(memcmp(buffer,"FOR4",4)!=0 || size < 8) return 0; reset_file_recovery(file_recovery_new); file_recovery_new->extension=file_hint_mb.extension; file_recovery_new->min_filesize=16; - file_recovery_new->calculated_file_size=(uint64_t)be32(hdr->size)+8; + file_recovery_new->calculated_file_size=(uint64_t)size+8; file_recovery_new->data_check=&data_check_size; file_recovery_new->file_check=&file_check_size; return 1; } +/*@ + @ requires buffer_size >= 4; + @ requires \valid_read(buffer+(0..buffer_size-1)); + @ requires valid_file_recovery(file_recovery); + @ requires \valid(file_recovery_new); + @ requires file_recovery_new->blocksize > 0; + @ requires separation: \separated(&file_hint_mb, buffer+(..), file_recovery, file_recovery_new); + @ assigns *file_recovery_new; + @ ensures \result == 0 || \result == 1; + @ ensures \result!=0 ==> valid_file_recovery(file_recovery_new); + @*/ static int header_check_mp(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) { if(memcmp(buffer,"FOR4",4)!=0)