From b5d9e7ade9aae30f45057bf06638273b77ddfa00 Mon Sep 17 00:00:00 2001 From: Sveinung Kvilhaugsvik Date: Fri, 2 Jul 2021 10:52:53 +0200 Subject: [PATCH] JSON: avoid integer underflow in dir in orders. Reported by Lexxie See osdn #42595 --- freeciv/apply_patches.sh | 2 ++ ...ON-avoid-integer-underflow-on-orders.patch | 33 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 freeciv/patches/0001-JSON-avoid-integer-underflow-on-orders.patch diff --git a/freeciv/apply_patches.sh b/freeciv/apply_patches.sh index f5d7b411e..81eca183d 100755 --- a/freeciv/apply_patches.sh +++ b/freeciv/apply_patches.sh @@ -5,6 +5,7 @@ # Not in the upstream Freeciv server # ---------------------------------- +# 0001-JSON-avoid-integer-underflow-on-orders is osdn #42595 # freeciv_segfauls_fix is a workaround some segfaults in the Freeciv server. Freeciv bug #23884. # message_escape is a patch for protecting against script injection in the message texts. # tutorial_ruleset changes the ruleset of the tutorial to one supported by Freeciv-web. @@ -24,6 +25,7 @@ # endgame-mapimg is used to generate a mapimg at endgame for hall of fame. declare -a PATCHLIST=( + "0001-JSON-avoid-integer-underflow-on-orders" "city_impr_fix2" "city-naming-change" "metachange" diff --git a/freeciv/patches/0001-JSON-avoid-integer-underflow-on-orders.patch b/freeciv/patches/0001-JSON-avoid-integer-underflow-on-orders.patch new file mode 100644 index 000000000..9f3e3ede1 --- /dev/null +++ b/freeciv/patches/0001-JSON-avoid-integer-underflow-on-orders.patch @@ -0,0 +1,33 @@ +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 +