On Fri, Aug 25, 2017 at 10:16:36AM -0500, Jamie Strandboge wrote:
> 
> I was looking at valid_cached_file_version() and noticed a mixture of 
> hardcoded
> values (16, 12 and 4) and a define (HEADER_STRING_SIZE (12)).
> 
> This is a small cleanup patch to add VERSION_STRING_SIZE and use only it and
> HEADER_STRING_SIZE in valid_cached_file_version().
> 
> -- 
> Jamie Strandboge             | http://www.canonical.com

> Update parser/policy_cache.c to consistently use defines in
> valid_cached_file_version()
> 
> Signed-Off-By: Jamie Strandboge <[email protected]>

Acked-by: Seth Arnold <[email protected]>

Thanks

> 
> === modified file 'parser/policy_cache.c'
> --- a/parser/policy_cache.c   2015-08-12 17:22:41 +0000
> +++ b/parser/policy_cache.c   2017-08-25 14:34:31 +0000
> @@ -35,16 +35,17 @@
>  
>  const char header_string[] = "\004\010\000version\000\002";
>  #define HEADER_STRING_SIZE 12
> +#define VERSION_STRING_SIZE 4
>  bool valid_cached_file_version(const char *cachename)
>  {
> -     char buffer[16];
> +     char buffer[HEADER_STRING_SIZE + VERSION_STRING_SIZE];
>       autofclose FILE *f;
>       if (!(f = fopen(cachename, "r"))) {
>               PERROR("Error: Could not read cache file '%s', skipping...\n", 
> cachename);
>               return false;
>       }
> -     size_t res = fread(buffer, 1, 16, f);
> -     if (res < 16) {
> +     size_t res = fread(buffer, 1, HEADER_STRING_SIZE + VERSION_STRING_SIZE, 
> f);
> +     if (res < HEADER_STRING_SIZE + VERSION_STRING_SIZE) {
>               if (debug_cache)
>                       pwarn("%s: cache file '%s' invalid size\n", progname, 
> cachename);
>               return false;
> @@ -61,7 +62,7 @@
>                                                     policy_version,
>                                                     parser_abi_version,
>                                                     kernel_abi_version));
> -     if (memcmp(buffer + 12, &version, 4) != 0) {
> +     if (memcmp(buffer + HEADER_STRING_SIZE, &version, VERSION_STRING_SIZE) 
> != 0) {
>               if (debug_cache)
>                       pwarn("%s: cache file '%s' has wrong version\n", 
> progname, cachename);
>               return false;
> 

Attachment: signature.asc
Description: PGP signature

-- 
AppArmor mailing list
[email protected]
Modify settings or unsubscribe at: 
https://lists.ubuntu.com/mailman/listinfo/apparmor

Reply via email to