commit 72c4ba730f7a0013439dc6d8b6c77536999798c0
parent 9da053dd5d48d8045193f5377ac442b50ecdebae
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:
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;
+ }
}
}