From 9da0f16ccdc262c67fb5b0d08e8392e35c9bcb81 Mon Sep 17 00:00:00 2001 From: Christophe Grenier Date: Wed, 24 Feb 2021 08:10:29 +0100 Subject: [PATCH] src/file_ldf.c: add frama-c annotations --- src/file_ldf.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/file_ldf.c b/src/file_ldf.c index 937120b9..109e7457 100644 --- a/src/file_ldf.c +++ b/src/file_ldf.c @@ -31,9 +31,8 @@ #include "types.h" #include "filegen.h" - +/*@ requires \valid(file_stat); */ static void register_header_check_ldf(file_stat_t *file_stat); -static int header_check_ldf(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_ldf= { .extension="ldf", @@ -44,13 +43,17 @@ const file_hint_t file_hint_ldf= { .register_header_check=®ister_header_check_ldf }; -static const unsigned char ldf_header[4]= { 0x01, 0x0f, 0x00, 0x00 }; - -static void register_header_check_ldf(file_stat_t *file_stat) -{ - register_header_check(0, ldf_header,sizeof(ldf_header), &header_check_ldf, file_stat); -} - +/*@ + @ requires buffer_size >= 0x1c; + @ 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_ldf, buffer+(..), file_recovery, file_recovery_new); + @ ensures \result == 0 || \result == 1; + @ ensures \result!=0 ==> valid_file_recovery(file_recovery_new); + @ assigns *file_recovery_new; + @*/ static int header_check_ldf(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(buffer[0x00]==0x01 && buffer[0x01]==0x0f && buffer[0x02]==0x00 && buffer[0x03]==0x00 && @@ -66,4 +69,10 @@ static int header_check_ldf(const unsigned char *buffer, const unsigned int buff } return 0; } + +static void register_header_check_ldf(file_stat_t *file_stat) +{ + static const unsigned char ldf_header[4]= { 0x01, 0x0f, 0x00, 0x00 }; + register_header_check(0, ldf_header,sizeof(ldf_header), &header_check_ldf, file_stat); +} #endif