Just as a safety measure, let's always NUL terminate what we are
downloading, maybe future code will parse it as string, and is sloppy by
accident.
(We have similar logic in read_full_file(), and I think it's a really
good rule, to always implicitly NUL terminate blobs we acquire that
might very well be used as text later on)
}
if (j->disk_fd < 0 || j->force_memory) {
- if (!GREEDY_REALLOC(j->payload, j->payload_size + sz))
+ if (!GREEDY_REALLOC(j->payload, j->payload_size + sz + 1))
return log_oom();
- memcpy(j->payload + j->payload_size, p, sz);
+ *((char*) mempcpy(j->payload + j->payload_size, p, sz)) = 0;
j->payload_size += sz;
}