diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/file.c | 4 | ||||
-rw-r--r-- | src/file.h | 4 | ||||
-rw-r--r-- | src/magic.c | 8 | ||||
-rw-r--r-- | src/readelf.c | 11 |
4 files changed, 17 insertions, 10 deletions
@@ -32,7 +32,7 @@ #include "file.h" #ifndef lint -FILE_RCSID("@(#)$File: file.c,v 1.213 2022/12/26 17:31:14 christos Exp $") +FILE_RCSID("@(#)$File: file.c,v 1.214 2023/02/09 17:45:19 christos Exp $") #endif /* lint */ #include "magic.h" @@ -155,6 +155,8 @@ file_private struct { MAGIC_PARAM_ELF_PHNUM_MAX, 0 }, { "elf_shnum", 0, FILE_ELF_SHNUM_MAX, "max ELF sections processed", MAGIC_PARAM_ELF_SHNUM_MAX, 0 }, + { "elf_shsize", 0, FILE_ELF_SHSIZE_MAX, "max ELF section size", + MAGIC_PARAM_ELF_SHSIZE_MAX, 0 }, { "encoding", 0, FILE_ENCODING_MAX, "max bytes to scan for encoding", MAGIC_PARAM_ENCODING_MAX, 0 }, { "indir", 0, FILE_INDIR_MAX, "recursion limit for indirection", @@ -27,7 +27,7 @@ */ /* * file.h - definitions for file(1) program - * @(#)$File: file.h,v 1.241 2022/12/26 17:31:14 christos Exp $ + * @(#)$File: file.h,v 1.242 2023/02/09 17:45:19 christos Exp $ */ #ifndef __file_h__ @@ -482,12 +482,14 @@ struct magic_set { uint16_t regex_max; size_t bytes_max; /* number of bytes to read from file */ size_t encoding_max; /* bytes to look for encoding */ + size_t elf_shsize_max; #ifndef FILE_BYTES_MAX # define FILE_BYTES_MAX (7 * 1024 * 1024)/* how much of the file to look at */ #endif /* above 0x6ab0f4 map offset for HelveticaNeue.dfont */ #define FILE_ELF_NOTES_MAX 256 #define FILE_ELF_PHNUM_MAX 2048 #define FILE_ELF_SHNUM_MAX 32768 +#define FILE_ELF_SHSIZE_MAX (128 * 1024 * 1024) #define FILE_INDIR_MAX 50 #define FILE_NAME_MAX 50 #define FILE_REGEX_MAX 8192 diff --git a/src/magic.c b/src/magic.c index 80555da3..052f9975 100644 --- a/src/magic.c +++ b/src/magic.c @@ -33,7 +33,7 @@ #include "file.h" #ifndef lint -FILE_RCSID("@(#)$File: magic.c,v 1.120 2022/12/26 17:31:14 christos Exp $") +FILE_RCSID("@(#)$File: magic.c,v 1.121 2023/02/09 17:45:19 christos Exp $") #endif /* lint */ #include "magic.h" @@ -625,6 +625,9 @@ magic_setparam(struct magic_set *ms, int param, const void *val) case MAGIC_PARAM_ELF_SHNUM_MAX: ms->elf_shnum_max = CAST(uint16_t, *CAST(const size_t *, val)); return 0; + case MAGIC_PARAM_ELF_SHSIZE_MAX: + ms->elf_shsize_max = *CAST(const size_t *, val); + return 0; case MAGIC_PARAM_ELF_NOTES_MAX: ms->elf_notes_max = CAST(uint16_t, *CAST(const size_t *, val)); return 0; @@ -661,6 +664,9 @@ magic_getparam(struct magic_set *ms, int param, void *val) case MAGIC_PARAM_ELF_SHNUM_MAX: *CAST(size_t *, val) = ms->elf_shnum_max; return 0; + case MAGIC_PARAM_ELF_SHSIZE_MAX: + *CAST(size_t *, val) = ms->elf_shsize_max; + return 0; case MAGIC_PARAM_ELF_NOTES_MAX: *CAST(size_t *, val) = ms->elf_notes_max; return 0; diff --git a/src/readelf.c b/src/readelf.c index 97d14513..8591f14b 100644 --- a/src/readelf.c +++ b/src/readelf.c @@ -27,7 +27,7 @@ #include "file.h" #ifndef lint -FILE_RCSID("@(#)$File: readelf.c,v 1.187 2022/12/26 17:31:14 christos Exp $") +FILE_RCSID("@(#)$File: readelf.c,v 1.188 2023/02/09 17:45:19 christos Exp $") #endif #ifdef BUILTIN_ELF @@ -60,9 +60,6 @@ file_private uint16_t getu16(int, uint16_t); file_private uint32_t getu32(int, uint32_t); file_private uint64_t getu64(int, uint64_t); -#define MAX_PHNUM 128 -#define MAX_SHNUM 32768 -#define MAX_SHSIZE (64 * 1024 * 1024) #define SIZE_UNKNOWN CAST(off_t, -1) file_private int @@ -1453,10 +1450,10 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num, return -1; return 0; } - if (xsh_size > MAX_SHSIZE) { + if (xsh_size > ms->elf_shsize_max) { file_error(ms, errno, "Note section size too " - "big (%ju > %u)", (uintmax_t)xsh_size, - MAX_SHSIZE); + "big (%ju > %zu)", (uintmax_t)xsh_size, + ms->elf_shsize_max); return -1; } if ((nbuf = malloc(xsh_size)) == NULL) { |