From 0e7309cd1645feb250df3fb211dacb1a23006b61 Mon Sep 17 00:00:00 2001 From: Sveinung Kvilhaugsvik Date: Fri, 2 Jul 2021 10:02:30 +0200 Subject: [PATCH] JSON: avoid integer underflow in dir in orders. Reported by Lexxie See osdn #42595 --- common/networking/dataio_json.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/common/networking/dataio_json.c b/common/networking/dataio_json.c index 90eb2a2996..8f8d67a853 100644 --- a/common/networking/dataio_json.c +++ b/common/networking/dataio_json.c @@ -289,7 +289,12 @@ void dio_put_unit_order_json(struct json_data_out *dout, json_object_set_new(obj, "target", json_integer(order->target)); json_object_set_new(obj, "sub_target", json_integer(order->sub_target)); json_object_set_new(obj, "action", json_integer(order->action)); - json_object_set_new(obj, "dir", json_integer(order->dir)); + if (order->dir == -1) { + /* Avoid integer underflow */ + json_object_set_new(obj, "dir", json_integer(-1)); + } else { + json_object_set_new(obj, "dir", json_integer(order->dir)); + } plocation_write_data(dout->json, location, obj); } else { dio_put_unit_order_raw(&dout->raw, order); -- 2.30.2