From 651ebcea7dfc8fcf17620011f69e0f06d7e125d1 Mon Sep 17 00:00:00 2001 From: Christophe Grenier Date: Wed, 24 Feb 2021 21:03:28 +0100 Subject: [PATCH] src/file_myo.c: add frama-c annotations --- src/file_myo.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/file_myo.c b/src/file_myo.c index 839ddc7d..e33ffa09 100644 --- a/src/file_myo.c +++ b/src/file_myo.c @@ -31,8 +31,8 @@ #include "types.h" #include "filegen.h" +/*@ requires \valid(file_stat); */ static void register_header_check_myo(file_stat_t *file_stat); -static int header_check_myo(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_myo= { .extension="myo", @@ -43,7 +43,16 @@ const file_hint_t file_hint_myo= { .register_header_check=®ister_header_check_myo }; - +/*@ + @ 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_myo, buffer+(..), file_recovery, file_recovery_new); + @ ensures \result == 0 || \result == 1; + @ ensures \result!=0 ==> valid_file_recovery(file_recovery_new); + @*/ static int header_check_myo(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 uint64_t size=(uint64_t)buffer[0]+(((uint64_t)buffer[1])<<8)+(((uint64_t)buffer[2])<<16)+(((uint64_t)buffer[3])<<24)+1; @@ -63,7 +72,6 @@ static int header_check_myo(const unsigned char *buffer, const unsigned int buff return 1; } - static void register_header_check_myo(file_stat_t *file_stat) { register_header_check(0x9ce, "FC!DEF", 6, &header_check_myo, file_stat);