]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shared: correctly propagate possible allocation errors
authorFrantisek Sumsal <frantisek@sumsal.cz>
Sun, 21 May 2023 19:00:26 +0000 (21:00 +0200)
committerFrantisek Sumsal <frantisek@sumsal.cz>
Mon, 22 May 2023 10:39:47 +0000 (12:39 +0200)
instead of just asserting in case the memstream couldn't be resized.

Found by Nallocufuzz.

src/shared/json.c

index 8962173b3aefae94bc5d24e51b7a589df2c0e2fd..904b26f9867248039edf8ae8ab7857bc8ce484ea 100644 (file)
@@ -1788,7 +1788,9 @@ int json_variant_format(JsonVariant *v, JsonFormatFlags flags, char **ret) {
                 if (!f)
                         return -ENOMEM;
 
-                json_variant_dump(v, flags, f, NULL);
+                r = json_variant_dump(v, flags, f, NULL);
+                if (r < 0)
+                        return r;
 
                 /* Add terminating 0, so that the output buffer is a valid string. */
                 fputc('\0', f);