Re: [PATCH v1 4/5] ima-evm-utils: Fix file2bin stat and fopen relations

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, 2019-07-13 at 00:28 +0300, Vitaly Chikunov wrote:

<snip>

> @@ -186,18 +187,32 @@ static unsigned char *file2bin(const char *file, const char *ext, int *size)
> 
>  	log_info("Reading to %s\n", name);
> 
> -	len = get_filesize(name);
>  	fp = fopen(name, "r");
>  	if (!fp) {
>  		log_err("Failed to open: %s\n", name);
>  		return NULL;
>  	}
> +	if (fstat(fileno(fp), &stats) == -1) {
> +		log_err("Failed to fstat: %s (%s)\n", name, strerror(errno));
> +		fclose(fp);
> +		return NULL;
> +	}
> +	len = stats.st_size;
> +
>  	data = malloc(len);
> -	if (!fread(data, len, 1, fp))
> -		len = 0;
> +	if (!data) {
> +		log_err("Failed to malloc %zu bytes: %s\n", len, name);

Missing "free(data)"

> +		fclose(fp);
> +		return NULL;
> +	}
> +	if (fread(data, len, 1, fp) != len) {
> +		log_err("Failed to fread %zu bytes: %s\n", len, name);
> +		fclose(fp);

and here
> +		return NULL;
> +	}
>  	fclose(fp);
> 
> -	*size = len;
> +	*size = (int)len;
>  	return data;
>  }
> 




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux Kernel]     [Linux Kernel Hardening]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux SCSI]

  Powered by Linux