empserver/tests
Markus Armbruster 9aaf609359 give: Fix integer overflows on silly third arguments
give() silently caps the resulting number of items to 0..ITEM_MAX.

However, its test for "< 0" suffers integer overflow on two's
complement machines (i.e. practically everywhere) when the amount
argument is INT_MIN.  give() proceeds as if the result was in range:
it sets the number of items to (short)(n + INT_MIN), telexes the owner
that INT_MIN items were stolen (obviously bogus), and tells the deity
that there are now n + INT_MIN items in X,Y.

On common machines, (short)(n + INT_MIN) == n, i.e. nothing is given.

On an oddball machine with short as wide as int, the cast to short
does nothing, item_prewrite() oopses, and corrects the number of items
to zero.

In both cases, output and telegram lie.

Likewise, its test for "> ITEM_MAX" suffers integer overflow for
sufficiently big amount arguments.  Again, give() proceeds as if the
result was in range: it sets the number of items to (short)(n + amt),
telexes the owner that -amt items were stolen (obviously bogus), and
tells the deity that there are now close to INT_MIN items in X,Y.

On common machines, (short)(n + amt) = n + INT_MAX - amt - 1,
i.e. some items are stolen.

On an oddball machine with short as wide as int, the cast to short
does nothing, item_prewrite() oopses, and corrects the number of items
to zero.

Again, output and telegram lie.

Aside: setsector can suffer similar overflows, but it reports the
resulting change correctly.  Good enough.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2013-06-06 19:52:26 +02:00
..
actofgod give: Fix integer overflows on silly third arguments 2013-06-06 19:52:26 +02:00
fairland Change fairland island size probability distribution 2013-05-08 06:57:55 +02:00
files Use int instead of signed char for pln_flags 2013-05-08 06:57:54 +02:00
smoke tests: Capture player output via journal instead of client 2013-05-31 10:52:50 +02:00
actofgod-test tests/actofgod: New, disabled for now because it oopses 2013-06-06 19:52:20 +02:00
fairland-test Switch PRNG from BSD random() to Mersenne Twister 2013-05-08 06:55:21 +02:00
files-test Add files test to make check 2013-05-08 06:55:18 +02:00
normalize.pl tests: Cut off log file timestamp instead of normalizing it 2013-05-31 09:54:50 +02:00
smoke-test tests: Capture player output via journal instead of client 2013-05-31 10:52:50 +02:00
test-common.sh tests: Capture player output via journal instead of client 2013-05-31 10:52:50 +02:00