mirror of
https://codeberg.org/libreboot/lbmk.git
synced 2026-07-18 14:12:44 +02:00
util/nvmutil: safer pointer comparison
technically we're never supposed to do arithmetic on pointers (there's uintptr for that) very anal fix Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
+13
-4
@@ -218,6 +218,7 @@ also consider:
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
#include <stddef.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -1800,13 +1801,21 @@ static ssize_t
|
|||||||
rw_gbe_file_exact(int fd, u8 *mem, size_t nrw,
|
rw_gbe_file_exact(int fd, u8 *mem, size_t nrw,
|
||||||
off_t off, int rw_type)
|
off_t off, int rw_type)
|
||||||
{
|
{
|
||||||
|
size_t mem_addr;
|
||||||
|
size_t buf_addr;
|
||||||
|
size_t buf_end;
|
||||||
|
|
||||||
if (mem == NULL)
|
if (mem == NULL)
|
||||||
goto err_rw_gbe_file_exact;
|
goto err_rw_gbe_file_exact;
|
||||||
|
|
||||||
if (mem != (void *)pad
|
mem_addr = (size_t)(void *)mem;
|
||||||
&& mem != (void *)rnum
|
buf_addr = (size_t)(void *)buf;
|
||||||
&& (mem < buf || mem >= (buf + GBE_FILE_SIZE)))
|
buf_end = buf_addr + GBE_FILE_SIZE;
|
||||||
goto err_rw_gbe_file_exact;
|
|
||||||
|
if (mem != (void *)pad &&
|
||||||
|
mem != (void *)rnum &&
|
||||||
|
(mem_addr < buf_addr || mem_addr >= buf_end))
|
||||||
|
goto err_rw_gbe_file_exact;
|
||||||
|
|
||||||
if (off < 0 || off >= gbe_file_size)
|
if (off < 0 || off >= gbe_file_size)
|
||||||
goto err_rw_gbe_file_exact;
|
goto err_rw_gbe_file_exact;
|
||||||
|
|||||||
Reference in New Issue
Block a user