]> git.pond.sub.org Git - empserver/commit
Fix buffer overruns in fairland for island size zero
authorMarkus Armbruster <armbru@pond.sub.org>
Sat, 5 May 2012 12:16:00 +0000 (14:16 +0200)
committerMarkus Armbruster <armbru@pond.sub.org>
Sat, 5 May 2012 14:13:08 +0000 (16:13 +0200)
commit4801fad4a8e4af835cb6d31922ce078ce8fe43df
treee6d88c7d0ae6f38610c5eebe7773a8eb50697ab5
parent3464a4a9d000923815c752ea3a2ab5c7dd702dee
Fix buffer overruns in fairland for island size zero

Fairland creates islands with size 1 + random() % (2 * is - 1), where
"is" is either chosen by the user (fourth command line argument) or
defaults to half the continent size (second command line argument).
Negative values are silently replaced by zero.

Not only does value zero make no sense, it also breaks the code: the
island size is always one then (because random() % -1 is zero), but
allocate_memory() provides only space for zero sectors in sectx[],
secty[] and sectc[].  This leads to buffer overruns in try_to_grow(),
find_coast(), elevate_land, set_coastal_flags().  Can smash the heap.

Fix by changing the lower bound from zero to one.  Diagnosed with
valgrind.  Has always been broken.
src/util/fairland.c