From f429080064c42b0eebe89da289e6055381e3aeec Mon Sep 17 00:00:00 2001 From: Christophe Grenier Date: Sat, 10 Apr 2021 10:53:57 +0200 Subject: [PATCH] src/file_pnm.c: add Frama-C annotations --- src/file_pnm.c | 51 ++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 41 insertions(+), 10 deletions(-) diff --git a/src/file_pnm.c b/src/file_pnm.c index 77909196..40645d03 100644 --- a/src/file_pnm.c +++ b/src/file_pnm.c @@ -32,41 +32,72 @@ #include "types.h" #include "filegen.h" +/*@ requires \valid(file_stat); */ static void register_header_check_pnm(file_stat_t *file_stat); -const file_hint_t file_hint_pnm= { - .extension="pnm", - .description="Netpbm (PBM/PGM/PPM)", - .max_filesize=PHOTOREC_MAX_FILE_SIZE, - .recover=1, - .enable_by_default=1, - .register_header_check=®ister_header_check_pnm +const file_hint_t file_hint_pnm = { + .extension = "pnm", + .description = "Netpbm (PBM/PGM/PPM)", + .max_filesize = PHOTOREC_MAX_FILE_SIZE, + .recover = 1, + .enable_by_default = 1, + .register_header_check = ®ister_header_check_pnm }; +/*@ + @ requires buffer_size >= 8; + @ 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_pnm, buffer+(..), file_recovery, file_recovery_new); + @ ensures \result!=0 ==> valid_file_recovery(file_recovery_new); + @ assigns *file_recovery_new; + @*/ static int header_check_pbm(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(!isprint(buffer[5]) || !isprint(buffer[6]) || !isprint(buffer[7])) return 0; reset_file_recovery(file_recovery_new); - file_recovery_new->extension="pbm"; + file_recovery_new->extension = "pbm"; return 1; } +/*@ + @ requires buffer_size >= 8; + @ 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_pnm, buffer+(..), file_recovery, file_recovery_new); + @ ensures \result!=0 ==> valid_file_recovery(file_recovery_new); + @ assigns *file_recovery_new; + @*/ static int header_check_pgm(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(!isprint(buffer[5]) || !isprint(buffer[6]) || !isprint(buffer[7])) return 0; reset_file_recovery(file_recovery_new); - file_recovery_new->extension="pgm"; + file_recovery_new->extension = "pgm"; return 1; } +/*@ + @ requires buffer_size >= 8; + @ 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_pnm, buffer+(..), file_recovery, file_recovery_new); + @ ensures \result!=0 ==> valid_file_recovery(file_recovery_new); + @ assigns *file_recovery_new; + @*/ static int header_check_ppm(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(!isprint(buffer[5]) || !isprint(buffer[6]) || !isprint(buffer[7])) return 0; reset_file_recovery(file_recovery_new); - file_recovery_new->extension="ppm"; + file_recovery_new->extension = "ppm"; return 1; }