]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
json: Fix datatype_json() for literal level
authorPhil Sutter <phil@nwl.cc>
Tue, 11 Sep 2018 20:14:24 +0000 (22:14 +0200)
committerFlorian Westphal <fw@strlen.de>
Thu, 13 Sep 2018 08:41:34 +0000 (10:41 +0200)
If a datatype doesn't provide a 'json' callback, datatype_json() uses
fmemopen() to grab the output from 'print' callback. When doing so,
reuse the existing output context instead of creating a dedicated one to
make sure all output-related settings are exactly as expected.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
src/json.c

index 84bdaa39c0d3161884e14650c8059c364161eacb..bb1d0f2d1bfcdadffc923b1a74ffd2196a57a024 100644 (file)
@@ -770,12 +770,13 @@ static json_t *datatype_json(const struct expr *expr, struct output_ctx *octx)
                        return symbolic_constant_json(dtype->sym_tbl,
                                                      expr, octx);
                if (dtype->print) {
-                       struct output_ctx octx = { .numeric = 3 };
                        char buf[1024];
+                       FILE *ofp = octx->output_fp;
 
-                       octx.output_fp = fmemopen(buf, 1024, "w");
-                       dtype->print(expr, &octx);
-                       fclose(octx.output_fp);
+                       octx->output_fp = fmemopen(buf, 1024, "w");
+                       dtype->print(expr, octx);
+                       fclose(octx->output_fp);
+                       octx->output_fp = ofp;
 
                        if (buf[0] == '"') {
                                memmove(buf, buf + 1, strlen(buf));