libmach: Use long for offset - scc - simple c99 compiler
HTML git clone git://git.simple-cc.org/scc
DIR Log
DIR Files
DIR Refs
DIR Submodules
DIR README
DIR LICENSE
---
DIR commit e776065632d998cb8491dded4d3c809ac272f5fc
DIR parent 11f2d4ad18c54ed4b3147efb7554820173edd38c
HTML Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Thu, 20 Feb 2025 10:31:50 +0100
libmach: Use long for offset
As we use standard fseek() and ftell() we cannot support
files that cannot be addressed with longs, so it is better
to check for these problems when reading files and use
long after that point.
Diffstat:
M include/bits/scc/mach.h | 3 +--
M src/libmach/elf/elfread.c | 2 ++
2 files changed, 3 insertions(+), 2 deletions(-)
---
DIR diff --git a/include/bits/scc/mach.h b/include/bits/scc/mach.h
@@ -84,7 +84,7 @@ struct section {
unsigned long long base;
unsigned long long load;
unsigned long long size;
- unsigned long long offset;
+ long offset;
unsigned flags;
int index;
@@ -112,7 +112,6 @@ struct map {
struct mapsec *seg;
};
-
/**
* @stype: Used internally by libmach
* @dtype: Coff debug type
DIR diff --git a/src/libmach/elf/elfread.c b/src/libmach/elf/elfread.c
@@ -436,6 +436,8 @@ readphdr(Obj *obj, FILE *fp)
if (fread(buf, hdr->phentsize, 1, fp) != 1)
goto err1;
(*u->phdr)(ORDER(obj->type), buf, &phdr[i]);
+ if (phdr[i].offset > LONG_MAX)
+ goto err1;
}
r = 1;