Skip to content

Commit

Permalink
JSON: avoid integer underflow in dir in orders.
Browse files Browse the repository at this point in the history
Reported by Lexxie

See osdn #42595
  • Loading branch information
kvilhaugsvik committed Jul 2, 2021
1 parent c5d4c85 commit b5d9e7a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
2 changes: 2 additions & 0 deletions freeciv/apply_patches.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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"
Expand Down
33 changes: 33 additions & 0 deletions freeciv/patches/0001-JSON-avoid-integer-underflow-on-orders.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
From 0e7309cd1645feb250df3fb211dacb1a23006b61 Mon Sep 17 00:00:00 2001
From: Sveinung Kvilhaugsvik <[email protected]>
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

0 comments on commit b5d9e7a

Please sign in to comment.