Don't crash if the src or dest d_buf are NULL. Return error and set
libelf errno to ELF_E_INVALID_DATA. Only need to check against src
d_size because that is the lower bound (if dest d_size is zero while
src d_size is not, we'll get an ELF_E_DEST_SIZE error).
* libelf/elf32_xlatetof.c (xlatetof): Check src and dest d_buf
are not NULL if src d_size is not zero.
* libelf/elf32_xlatetom.c (LIBELFBITS,xlatetom): Likewise.
Signed-off-by: Mark Wielaard <[email protected]>
---
libelf/elf32_xlatetof.c | 6 ++++++
libelf/elf32_xlatetom.c | 6 ++++++
2 files changed, 12 insertions(+)
diff --git a/libelf/elf32_xlatetof.c b/libelf/elf32_xlatetof.c
index 44c75ef052fc..2c3e9e0ba1b3 100644
--- a/libelf/elf32_xlatetof.c
+++ b/libelf/elf32_xlatetof.c
@@ -54,6 +54,12 @@ elfw2(LIBELFBITS, xlatetof) (Elf_Data *dest, const Elf_Data
*src,
return NULL;
}
+ if ((src->d_buf == NULL || dest->d_buf == NULL) && src->d_size != 0)
+ {
+ __libelf_seterrno (ELF_E_INVALID_DATA);
+ return NULL;
+ }
+
/* First test whether the input data is really suitable for this
type. This means, whether there is an integer number of records.
Note that for this implementation the memory and file size of the
diff --git a/libelf/elf32_xlatetom.c b/libelf/elf32_xlatetom.c
index a1eea842803e..799c3be729fd 100644
--- a/libelf/elf32_xlatetom.c
+++ b/libelf/elf32_xlatetom.c
@@ -54,6 +54,12 @@ elfw2(LIBELFBITS, xlatetom) (Elf_Data *dest, const Elf_Data
*src,
return NULL;
}
+ if ((src->d_buf == NULL || dest->d_buf == NULL) && src->d_size != 0)
+ {
+ __libelf_seterrno (ELF_E_INVALID_DATA);
+ return NULL;
+ }
+
/* First test whether the input data is really suitable for this
type. This means, whether there is an integer number of records.
Note that for this implementation the memory and file size of the
--
2.56.1