3 ms·
That only avoids some problems. For example, this is vulnerable to s = MAX_SIZE_T/4 + 1 size_t s = get_size(); int *a = (int *)malloc(s * sizeof(int)); f
by tlb 15y ago
That only avoids some problems. For example, this is vulnerable to s = MAX_SIZE_T/4 + 1
size_t s = get_size();
int *a = (int *)malloc(s * sizeof(int));
for (size_t i=0; i<s; i++) {
a[i] = get_int();
}
I've gotten in the habit of, when reading array sizes over the wire, explicitly limiting to a reasonable value like 1 million. Occasionally things should be allowed to use all available memory, but it's rare.