scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit d2f2f98130f28e9e02a4210f1096c1bd3afffb93
parent 5a522b88668d1295302293de3f86c0b2869ee57a
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Thu, 29 Aug 2019 09:42:30 +0100

[libmach] Fix error codes in readobj()

There were cases where we were not setting errno and we were
returning error in case of having an empty string table.

Diffstat:
Msrc/libmach/coff32/coff32read.c | 14+++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/src/libmach/coff32/coff32read.c b/src/libmach/coff32/coff32read.c @@ -154,13 +154,15 @@ readstr(Obj *obj, FILE *fp) if (fread(buf, 4, 1, fp) != 1) return 0; unpack(ORDER(obj->type), buf, "l", &siz); + coff->strsiz = 0; if (siz == 4) - return 0; + return 1; if (siz > 4) { - if (siz > SIZE_MAX) + if (siz > SIZE_MAX) { + errno = ERANGE; return 0; - str = malloc(siz); - if (!str) + } + if ((str = malloc(siz)) == NULL) return 0; coff->strtbl = str; coff->strsiz = siz; @@ -207,8 +209,10 @@ readreloc(Obj *obj, FILE *fp) if (fread(buf, RELSZ, 1, fp) != 1) return 0; unpack_reloc(ORDER(obj->type), buf, &rp[i]); - if (rp[i].r_symndx >= hdr->f_nsyms) + if (rp[i].r_symndx >= hdr->f_nsyms) { + errno = ERANGE; return 0; + } } }