diff options
Diffstat (limited to 'src/stdlib')
| -rw-r--r-- | src/stdlib/c_strings.c | 3 | ||||
| -rw-r--r-- | src/stdlib/lists.c | 14 | ||||
| -rw-r--r-- | src/stdlib/stdlib.c | 2 | ||||
| -rw-r--r-- | src/stdlib/text.c | 3 |
4 files changed, 14 insertions, 8 deletions
diff --git a/src/stdlib/c_strings.c b/src/stdlib/c_strings.c index c153a8a9..860a69ff 100644 --- a/src/stdlib/c_strings.c +++ b/src/stdlib/c_strings.c @@ -64,7 +64,8 @@ static void CString$deserialize(FILE *in, void *out, List_t *pointers, const Typ int64_t len = -1; Int64$deserialize(in, &len, pointers, &Int64$info); char *str = GC_MALLOC_ATOMIC((size_t)len+1); - fread(str, sizeof(char), (size_t)len, in); + if (fread(str, sizeof(char), (size_t)len, in) != (size_t)len) + fail("Not enough data in stream to deserialize"); str[len+1] = '\0'; *(const char**)out = str; } diff --git a/src/stdlib/lists.c b/src/stdlib/lists.c index c73d20dd..c1c119a0 100644 --- a/src/stdlib/lists.c +++ b/src/stdlib/lists.c @@ -297,7 +297,7 @@ static int64_t _default_random_int64(int64_t min, int64_t max, void *userdata) uint64_t min_r = -range % range; uint64_t r; for (;;) { - getrandom(&r, sizeof(r), 0); + assert(getrandom(&r, sizeof(r), 0) == sizeof(r)); if (r >= min_r) break; } return (int64_t)((uint64_t)min + (r % range)); @@ -361,7 +361,7 @@ static double _default_random_num(void *userdata) Num_t num; uint64_t bits; } r = {.bits=0}, one = {.num=1.0}; - getrandom((uint8_t*)&r, sizeof(r), 0); + assert(getrandom((uint8_t*)&r, sizeof(r), 0) == sizeof(r)); // Set r.num to 1.<random-bits> r.bits &= ~(0xFFFULL << 52); @@ -808,10 +808,14 @@ public void List$deserialize(FILE *in, void *obj, List_t *pointers, const TypeIn for (int64_t i = 0; i < len; i++) item_deserialize(in, list.data + i*list.stride, pointers, type->ListInfo.item); } else if (list.stride == type->ListInfo.item->size) { - fread(list.data, (size_t)type->ListInfo.item->size, (size_t)len, in); + if (fread(list.data, (size_t)type->ListInfo.item->size, (size_t)len, in) != (size_t)len) + fail("Not enough data in stream to deserialize"); } else { - for (int64_t i = 0; i < len; i++) - fread(list.data + i*list.stride, (size_t)type->ListInfo.item->size, 1, in); + size_t item_size = (size_t)type->ListInfo.item->size; + for (int64_t i = 0; i < len; i++) { + if (fread(list.data + i*list.stride, item_size, 1, in) != item_size) + fail("Not enough data in stream to deserialize"); + } } *(List_t*)obj = list; } diff --git a/src/stdlib/stdlib.c b/src/stdlib/stdlib.c index 54c7827f..6a855c66 100644 --- a/src/stdlib/stdlib.c +++ b/src/stdlib/stdlib.c @@ -65,7 +65,7 @@ public void tomo_init(void) USE_COLOR = false; setlocale(LC_ALL, ""); - getrandom(TOMO_HASH_KEY, sizeof(TOMO_HASH_KEY), 0); + assert(getrandom(TOMO_HASH_KEY, sizeof(TOMO_HASH_KEY), 0) == sizeof(TOMO_HASH_KEY)); struct sigaction sigact; sigact.sa_sigaction = signal_handler; diff --git a/src/stdlib/text.c b/src/stdlib/text.c index cc8a4daf..2107c1df 100644 --- a/src/stdlib/text.c +++ b/src/stdlib/text.c @@ -1620,7 +1620,8 @@ public void Text$deserialize(FILE *in, void *out, List_t *pointers, const TypeIn int64_t len = -1; Int64$deserialize(in, &len, pointers, &Int64$info); char *buf = GC_MALLOC_ATOMIC((size_t)len+1); - fread(buf, sizeof(char), (size_t)len, in); + if (fread(buf, sizeof(char), (size_t)len, in) != (size_t)len) + fail("Not enough data in stream to deserialize"); buf[len+1] = '\0'; *(Text_t*)out = Text$from_strn(buf, (size_t)len); } |
