]> git.pond.sub.org Git - empserver/commit
edit: Fix integer argument range checking
authorMarkus Armbruster <armbru@pond.sub.org>
Wed, 16 Jan 2013 19:53:56 +0000 (20:53 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Thu, 6 Jun 2013 17:52:26 +0000 (19:52 +0200)
commit2b80ce93daf4bd86a2041fcc699e17db6c241f38
treea1b4b4d576d06d1f5e3ee7f778ab870970f3a579
parentc0dc4c42b5ac1c8e95ab087a1a42667a347edded
edit: Fix integer argument range checking

Upper bounds corrected:

    cmd  key  struct member   wrong   correct   notes
    -------------------------------------------------
    edit l m  sct_mobil         255       127      1
           t  sct_ptime         255     32767
    edit c b  nat_btu          1024  max_btus
    edit p m  pln_mobil         255       127      1
    edit u F  lnd_harden        255       127    1

Missing bounds supplied, arguments out of bounds are silently clipped
unless noted otherwise:

    cmd  key     struct member   bounds           notes
    ---------------------------------------------------
    edit c t     nat_tgms        0   USHRT_MAX       2
           m     nat_reserve     0   INT_MAX
           T...  nat_level[]     0   infinity
    edit s a     shp_pstage      0   PLG_EXPOSED     3
           b     shp_ptime       0   32767
           M     shp_mobil    -127   127
           c...  shp_item[]      0   load limit      4
    edit u Y     lnd_land       -1   size of table   5
           M     lnd_mobil    -127   127
           S     lnd_ship       -1   size of table   5
           Z     lnd_retreat     0   100
           c...  lnd_item[]      0   load limit      4
    edit p r     pln_range       0   max range
           s     pln_ship       -1   size of table   5
           y     pln_land       -1   size of table   5

Notes:

1. Values between SCHAR_MAX and 255 were cast to signed char, changing
the sign.

2. The real upper bound is the number of telegrams in the mailbox, but
counting them isn't worth it.

3. This check is particularly important, because values out of bounds
make the server refuse to start without -F, and empdump -x warn
"export has errors, not importable as is".

4. Values outside 0..ITEM_MAX got caught and clipped by
item_prewrite().  This check avoids the oops, and tightens the upper
bound for units.

5. Argument out-of-bounds are rejected.  This check is particularly
important, because unit numbers beyond the size of the table trigger
oopses.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
src/lib/commands/edit.c
tests/actofgod/actofgod.xdump
tests/actofgod/journal.log
tests/actofgod/server.log