chiark / gitweb /
gamestate: Implement an overall pieces limit
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 11 Mar 2021 20:05:06 +0000 (20:05 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 11 Mar 2021 21:30:33 +0000 (21:30 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
daemon/cmdlistener.rs

index a9c576384ffe2ce2a2a840e18568e4e89f00b8aa..c167326b0af444e17504e0ddea995ecf06a32722 100644 (file)
@@ -26,6 +26,7 @@ use MgmtResponse::Fine;
 
 const USERLIST: &str = "/etc/userlist";
 const CREATE_PIECES_MAX: u32 = 300;
+const OVERALL_PIECES_MAX: usize = 100_000; // don't make not fit in i32
 
 const DEFAULT_POS_START: Pos = PosC([20,20]);
 const DEFAULT_POS_DELTA: Pos = PosC([5,5]);
@@ -611,7 +612,10 @@ fn execute_game_insn<'cs, 'igr, 'ig: 'igr>(
       };
 
       let count_len = count.len();
-      if count.len() > CREATE_PIECES_MAX as usize { throw!(ME::LimitExceeded) }
+      if count_len > CREATE_PIECES_MAX as usize { throw!(ME::LimitExceeded) }
+      if gs.pieces.len() + count_len > OVERALL_PIECES_MAX {
+        throw!(ME::LimitExceeded)
+      }
       let posd = posd.unwrap_or(DEFAULT_POS_DELTA);
 
       let mut updates = Vec::with_capacity(count_len);