]> git.pond.sub.org Git - empserver/commit
Fix buy not to wipe out concurrent updates
authorMarkus Armbruster <armbru@pond.sub.org>
Sun, 17 Apr 2011 04:44:21 +0000 (06:44 +0200)
committerMarkus Armbruster <armbru@pond.sub.org>
Sun, 17 Apr 2011 15:48:18 +0000 (17:48 +0200)
commit40b11c098c0d2346eae3e258b937544a57e6fb69
treefae2e2b723a089c4e251b5a2413617748f679a4e
parent0563101703df7ec3d6e5d754434c97f013279558
Fix buy not to wipe out concurrent updates

buy() reads the lot, prompts for input, then writes back the lot,
triggering a generation oops.  Any updates made by other threads while
buy() waits for input are wiped out, triggering a seqno mismatch oops.

Since commodities are taken from the seller when he puts them on the
market, and given to the buyer when the trade executes, the wiped out
lot's seller loses his goods without compensation, the other seller
gets to keep his goods, and the buyer receives their duplicates.

This can be abused by two conspiring countries to duplicate
commodities.  The seller puts them on the market (say 100 gold bars).
The buyer starts a buy command, and waits at its last prompt for the
lot to be replaced.  The seller takes them off the market (possible,
since there's no bid, yet), and sells something else (say one food)
quickly enough to get the same lot number assigned.  The buyer then
completes the buy command.  The seller loses one food, the buyer gains
100 gold bars.

Replaces a partial fix from v4.0.1, which only caught lots gone away,
not lots replaced by new ones.
src/lib/commands/buy.c