]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
pull-job: always implicitly NUL terminate downloaded payload stored in memory
authorLennart Poettering <lennart@poettering.net>
Wed, 5 Nov 2025 15:48:24 +0000 (16:48 +0100)
committerLennart Poettering <lennart@poettering.net>
Sat, 8 Nov 2025 08:27:46 +0000 (09:27 +0100)
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)

src/import/pull-job.c

index b457c39ed180003d65c3dedb086c3c95963ae5ee..6c7b328a0c481bb9631e9e636f7112886dd3b5e2 100644 (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;
         }