ref: 1ff5de058cdce8d0c471124369dca23e9fa6a9a7
parent: adc39da8ab9cb40357ddfedeea5e7190f72bcdfd
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Thu Aug 29 17:12:45 EDT 2019
[libmach] Allocate string table always Allocate string table always, even when it is empty. This make the code more orthogonal and avoid errors.
--- a/src/libmach/coff32/coff32read.c
+++ b/src/libmach/coff32/coff32read.c
@@ -155,22 +155,17 @@
return 0;
unpack(ORDER(obj->type), buf, "l", &siz);
coff->strsiz = 0;
- if (siz == 4)
+ if (siz < 4 || siz > SIZE_MAX) {
+ errno = ERANGE;
return 1;
- if (siz > 4) {
- if (siz > SIZE_MAX) {
- errno = ERANGE;
- return 0;
- }
- if ((str = malloc(siz)) == NULL)
- return 0;
- coff->strtbl = str;
- coff->strsiz = siz;
-
- if (fread(str+4, siz-4, 1, fp) != 1)
- return 0;
}
- return 1;
+
+ if ((str = malloc(siz)) == NULL)
+ return 0;
+ coff->strtbl = str;
+ coff->strsiz = siz;
+
+ return fread(str+4, siz-4, 1, fp) != 1;
}
static int