shared/varlink: add missing terminator in json strings

Should finally fix oss-fuzz-14688.
8688c29b5a wasn't enough.

The buffer retrieved from memstream has the size that the same as the written
data. When we write do write(f, s, strlen(s)), then no terminating NUL is written,
and the buffer is not (necessarilly) a proper C string.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2019-05-30 18:45:06 +02:00
parent c2babfc2f5
commit 2a04712c19
3 changed files with 13 additions and 2 deletions
+4
View File
@@ -89,6 +89,7 @@ static void test_variant(const char *data, Test test) {
r = json_variant_format(v, 0, &s);
assert_se(r >= 0);
assert_se(s);
assert_se((size_t) r == strlen(s));
log_info("formatted normally: %s\n", s);
@@ -105,6 +106,7 @@ static void test_variant(const char *data, Test test) {
r = json_variant_format(v, JSON_FORMAT_PRETTY, &s);
assert_se(r >= 0);
assert_se(s);
assert_se((size_t) r == strlen(s));
log_info("formatted prettily:\n%s", s);
@@ -120,12 +122,14 @@ static void test_variant(const char *data, Test test) {
r = json_variant_format(v, JSON_FORMAT_COLOR, &s);
assert_se(r >= 0);
assert_se(s);
assert_se((size_t) r == strlen(s));
printf("Normal with color: %s\n", s);
s = mfree(s);
r = json_variant_format(v, JSON_FORMAT_COLOR|JSON_FORMAT_PRETTY, &s);
assert_se(r >= 0);
assert_se(s);
assert_se((size_t) r == strlen(s));
printf("Pretty with color:\n%s\n", s);
if (test)