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:
+8
-2
@@ -1555,6 +1555,9 @@ int json_variant_format(JsonVariant *v, JsonFormatFlags flags, char **ret) {
|
||||
size_t sz = 0;
|
||||
int r;
|
||||
|
||||
/* Returns the length of the generated string (without the terminating NUL),
|
||||
* or negative on error. */
|
||||
|
||||
assert_return(v, -EINVAL);
|
||||
assert_return(ret, -EINVAL);
|
||||
|
||||
@@ -1567,6 +1570,9 @@ int json_variant_format(JsonVariant *v, JsonFormatFlags flags, char **ret) {
|
||||
|
||||
json_variant_dump(v, flags, f, NULL);
|
||||
|
||||
/* Add terminating 0, so that the output buffer is a valid string. */
|
||||
fputc('\0', f);
|
||||
|
||||
r = fflush_and_check(f);
|
||||
}
|
||||
if (r < 0)
|
||||
@@ -1574,8 +1580,8 @@ int json_variant_format(JsonVariant *v, JsonFormatFlags flags, char **ret) {
|
||||
|
||||
assert(s);
|
||||
*ret = TAKE_PTR(s);
|
||||
|
||||
return (int) sz;
|
||||
assert(sz > 0);
|
||||
return (int) sz - 1;
|
||||
}
|
||||
|
||||
void json_variant_dump(JsonVariant *v, JsonFormatFlags flags, FILE *f, const char *prefix) {
|
||||
|
||||
Reference in New Issue
Block a user