URL:
  <http://gna.org/bugs/?17577>

                 Summary: Invalid wesnoth.set_terrain() in [lua] will crash
Wesnoth
                 Project: Battle for Wesnoth
            Submitted by: aethaeryn
            Submitted on: Wed 26 Jan 2011 05:37:17 AM GMT
                Category: Bug
                Severity: 3 - Normal
                Priority: 5 - Normal
              Item Group: WML
                  Status: None
                 Privacy: Public
             Assigned to: None
        Originator Email: 
             Open/Closed: Open
         Discussion Lock: Any
                 Release: 1.9.4+svn r48376
        Operating System: Fedora 14

    _______________________________________________________

Details:

I'm using 1.9.4+svn r48376 on Fedora 14 compiled with scons and I happened to
find an interesting bug accidentally when playing around with Lua for an
add-on of mine. Invalid terrain (specifically, in this case, setting a terrain
that is of the form of something like "Asdf^asdf^asdf") will crash the Wesnoth
client on the latest trunk, at least for me. Obviously, errors in Lua code
shouldn't be able to interfere with the integrity of the game client itself.

Since I must provide reproducible evidence, here's a quick example of a
function that can crash Wesnoth (and should work by simply copying and pasting
it into a working [lua] tag):

[lua]
code = <<
    function crash_wesnoth()
       local crash_this_terrain = wesnoth.get_terrain(1, 1)
       local crash_this_terrain = crash_this_terrain.."^Vhs".."^Vhs"
       wesnoth.set_terrain(1, 1, crash_this_terrain)
    end

    crash_wesnoth()
>>
[/lua]

While malicious add-ons might possibly exist, it's more likely that a general
function can crash Wesnoth accidentally by simply not including a check for an
overlay terrain that may already exist on that particular hex before adding
another overlay terrain via Lua. Here's an example of a probably-more-innocent
function that can also crash Wesnoth:

    function overlay_set(terrain_symbol, change_terrain)
       for i, terrain in ipairs(change_terrain) do
          local terrain_type = wesnoth.get_terrain(terrain[1], terrain[2])
          local terrain_symbol = terrain_type..terrain_symbol
          wesnoth.set_terrain(terrain[1], terrain[2], terrain_symbol)
       end
    end

   change_terrain = wesnoth.get_locations({x = 14, y = 14, radius = 2})

   overlay_set("^Vhs", change_terrain)

This code (or a slight variant of it) should crash Wesnoth if any of the
hexes in its radius have a terrain overlay (e.g. forest). I realize the proper
way to do this is to first check to see if there's any overlays and if there
are, to replace them instead of just append, but my point is that sloppy Lua
coding shouldn't be able to crash the Wesnoth client.

Sorry if my writing is a little incoherent (or if I made a typo in my Lua).
I'm tired and in a bit of a hurry, but I hope the code is clear and speaks for
itself. It is possible that there's a more general issue here with
wesnoth.set_terrain(), but this is just all I have had time to test for.

Thanks,
Aeth




    _______________________________________________________

Reply to this item at:

  <http://gna.org/bugs/?17577>

_______________________________________________
  Message sent via/by Gna!
  http://gna.org/


_______________________________________________
Wesnoth-bugs mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-bugs

Reply via email to