pull-job: always implicitly NUL terminate downloaded payload stored in memory

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)
This commit is contained in:
Lennart Poettering
2025-11-08 09:27:46 +01:00
parent f8293452b6
commit bf51a545a4
+2 -2
View File
@@ -343,10 +343,10 @@ static int pull_job_write_uncompressed(const void *p, size_t sz, void *userdata)
}
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;
}