100 Commits

Author SHA1 Message Date
P. J. McDermott
69fa5c199e Add CMake and SCons options to use system Lua 5.4 C++
scons/lua.py makes use of the vestigial luadir option from commit
e94dcecf171.

Like FindLua.cmake, scons/lua.py searches for the Lua headers and
library, instead of using pkg-config like the old scons/lua.py (removed
in commit 9929d3ca1cf) did, because even though distributions typically
provide .pc files for Lua, upstream Lua doesn't.  It's likely that all
distributions that compile Lua as a C++ library will also provide .pc
files, but this check doesn't rely on that (just as the CMake module
doesn't).

Unfortunately, SCons.Conftest.CheckLib() prints up to eight messages
like "Checking for C++ library lua54-c++... no" until a working library
name is found.

Also conditionally include system Lua headers in src/lua/*.h and update
documentation in src/modules/lua_README.md, src/wesnoth_lua_config.h,
and src/wesnoth_lua_config.md.  The two lines about "The primary commit,
after replacing the sources," in src/wesnoth_lua_config.md don't make
sense since the instructions were updated for submodule Lua in commit
d32cfb88c4f and make even less sense now with preceding commits for
updating CMake modules.
2024-02-11 23:21:15 -06:00
P. J. McDermott
b5d073a2ad Rename src/lua/*.h to src/lua/wrapper_*.h
These will be changed to conditionally include system Lua headers,
e.g. "lua.h", instead of submodule Lua headers, e.g. "module/lua/lua.h".
If a header named "lua.h" includes "lua.h", the build will fail due to
recursion.

This can't be solved using angle brackets to include system headers,
because macos builds won't find them:

    In file included from /Users/runner/work/wesnoth/wesnoth/src/ai/registry.cpp:30:
    In file included from /Users/runner/work/wesnoth/wesnoth/src/ai/composite/aspect.hpp:24:
    In file included from /Users/runner/work/wesnoth/wesnoth/src/ai/lua/lua_object.hpp:25:
    /Users/runner/work/wesnoth/wesnoth/src/lua/lua.h:4:14: error: 'lua.h' file not found with <angled> include; use "quotes" instead
        #include <lua.h>
                 ^~~~~~~
                 "lua.h"

Renamed with (requires GNU sed):

    $ for f in src/lua/*.h; do
    >     git mv "${f}" "src/lua/wrapper_${f#src/lua/}";
    > done
    $ git grep -El -- '#[ \t]*include[ \t]+"lua/[^"]+[.]h"' src | \
    > xargs sed -Ei -- '
    > s|(#[ \t]*include[ \t]+"lua/)(lua[.]h")(            )?|\1wrapper_\2|;
    > s|(#[ \t]*include[ \t]+"lua/)(lualib[.]h")(         )?|\1wrapper_\2|;
    > s|(#[ \t]*include[ \t]+"lua/)(lauxlib[.]h")(        )?|\1wrapper_\2|;
    > '
2024-02-11 23:21:15 -06:00
Pentarctagon
1a3498cbf3 Rename nowarn/ to lua/
Also cleanup the includes.
2022-03-09 15:01:37 -06:00
Pentarctagon
5155a74f4f Make lua a submodule.
No changes required to the lua source anymore.
2022-03-09 15:01:37 -06:00
Pentarctagon
573901376a Un-rename lua source files to .c
Being .cpp isn't required to have them be compiled as C++.
2022-03-09 15:01:37 -06:00
Pentarctagon
d4cef6d104 Revert "Reapply static_cast fix from 561cc33dc41d5b1561934d5c9e184f1da8545195"
This reverts commit 778e916b950f367102fa961da0c0e67b2a3e40dc.
2022-03-09 15:01:37 -06:00
Charles Dang
778e916b95 Reapply static_cast fix from 561cc33dc41d5b1561934d5c9e184f1da8545195 2022-02-15 23:16:20 -05:00
Charles Dang
dd509518e0 Upgrade to Lua 5.4.4 2022-02-15 23:09:15 -05:00
Charles Dang
561cc33dc4
Upgrade to Lua 5.4.2 (#5535)
The change to static_cast for the definition of  LUAL_BUFFERSIZE replaces the fix previously used (d0100758f855ec0d8f30dff41e8a8b6ff2d45fda) for Lua 5.3. 5.4 removes the static alternative for LUAL_BUFFERSIZE. A better solution would probably be to disable the old-style-cast warning for luaconf.h, but I can't figure out how to do that so using static_cast is the easiest solution. Do note that change will have to be applied each Lua update like the aforementioned commit.
2021-02-14 02:07:12 +11:00
Charles Dang
b2e22b8aed Reapply d0100758f855ec0d8f30dff41e8a8b6ff2d45fda 2021-01-17 21:28:47 +11:00
Charles Dang
ddf1ed9f0a Upgrade to Lua 5.3.6
Resolves #5452. There were no official patches to apply.
2021-01-17 21:28:47 +11:00
Jyrki Vesterinen
eb36c60fba Lua: implement our own load() instead of monkey-patching Lua code
Monkey-patching has multiple problems. The biggest problem for a security
fix like this is that it's way too easy to forget to re-apply when we
update Lua to a newer version.

Instead, we now have the implementation of load() under our control and can
update Lua without risk of reintroducing CVE-2018-1999023.

(cherry-picked from commit 52ae31efb21b31f5bb0763d1da24709e90393c59)
2018-10-07 03:23:46 +00:00
gfgtdf
120e8d9911 disallow loading lua bytecode via load/dofile (CVE-2018-1999023)
This could otherwise be used to escape the lua sandbox, as described in
multiple sources. For example one can use it to reenable the os.execute
function to do shell commands

The affected functions were
load,loadstring,wesnoth.dofile,wesnoth.require and various places in the
wesnoth source where lua chunks were loaded for example by the ai code.

This commit also changes the lua source to change luas load (which is
the same as loadstring), alternatively we could add a wrapper around the
original load function that always passes "t" as third parameter, i went
this way mostly because it was easier to implement, but also because i
was not 100% sure that is is impossible to query the upvalues of a
function via lua (wesnoth disables debug.getupvalue but still).

There is also an occurance in the application_lua_kernel that was not fixed
because i assumed that umc cannot contian application lua scipts.

As further security measure we might want to disable printing the function
adress in luas tostring for c functions, this cannot be exploited by itself
but it can be used to defeat ASLR in some cases.

(cherry-picked from commit 2554c166dd45bfdee8ee24431224bd25e52bab12)
2018-10-07 03:23:45 +00:00
Charles Dang
7451421db7 Reapply d0100758f855ec0d8f30dff41e8a8b6ff2d45fda
(cherry-picked from commit 8fcd3f2a833682a95c7d175d6a48cc42fa5e0c2d)
2018-10-07 03:23:26 +00:00
Charles Dang
aba5b94b99 Upgrade to Lua 5.3.5
(cherry-picked from commit 264389807c1cb789a3cfc3c386da049becdfbe67)
2018-10-07 03:23:26 +00:00
Matthias Krüger
a2168d2e24 codespell fixes to /src 2018-02-08 21:54:09 +11:00
Charles Dang
d0100758f8 Force static value for LUAL_BUFFERSIZE
In Lua 5.3.3, LUAL_BUFFERSIZE always equaled the constant since LUA_FLOAT_LONGDOUBLE was always defined.
This check changed in 5.3.4 and the alternate path was being used for LUAL_BUFFERSIZE and triggering
old-style cast warnings in Scons + GCC. Hopefully this gets fixed for 5.3.5.

The following patch constitutes the changes (though they were applied by hand):

*** luaconf.h.old       2017-10-09 23:38:22.641645801 -0500
--- luaconf.h   2017-10-09 23:38:56.548577911 -0500
***************
*** 748,758 ****
  ** smaller buffer would force a memory allocation for each call to
  ** 'string.format'.)
  */
- #if LUA_FLOAT_TYPE == LUA_FLOAT_LONGDOUBLE
  #define LUAL_BUFFERSIZE               8192
- #else
- #define LUAL_BUFFERSIZE   ((int)(0x80 * sizeof(void*) * sizeof(lua_Integer)))
- #endif

  /* }================================================================== */

--- 748,754 ----
2017-10-10 18:04:10 +11:00
Charles Dang
0deaecccf9 Apply Lua.org patch
Dead keys with nil values can stay in weak tables.

reported by 云风 Cloud Wu on 15 Aug 2017. existed since 5.2.

Example:
    See https://www.lua.org/bugs.html#5.3.4-5.
2017-10-10 18:04:10 +11:00
Charles Dang
1c05370e4e Apply Lua.org patch
Lua does not check GC when creating error messages.

reported by Viacheslav Usov on 06 Jul 2017. existed since 5.3.2.

Example:
    See https://www.lua.org/bugs.html#5.3.4-4.
2017-10-10 18:04:10 +11:00
Charles Dang
217d2e1a15 Apply Lua.org patch
Wrong code generated for a 'goto' followed by a label inside an 'if'.

reported by 云风 on 13 Apr 2017. existed since 5.2.

Example:
    See https://www.lua.org/bugs.html#5.3.4-1.
2017-10-10 18:04:10 +11:00
Charles Dang
b5bcee1b2d Upgrade to Lua 5.3.4 2017-10-10 18:04:10 +11:00
Pentarctagon
5b29805554 Have cmake and scons use same lists of source files (#882)
* Use separate files to build scons and to build lua for cmake

Move lists of source files into their own directory
Make scons use the lists of source files
Move lua build step to src/SConscript and delete src/lua/SConscript
Make cmake use the separate file with the list of lua sources to build

* Finish changing over to source lists

scons
  move source files from libraries that don't appear in cmake over to existing source lists - libcampaignd, libcutter, libdummy_video, libtest_utils
  add the defines FIFODIR and WESNOTH_PATH to all compiled source files, as cmake does, and move the single files those defines had previously been defined on into the source lists
  remove WESNOTH_PREFIX, as not used
  added schema_validator sources from cmake
  added OBJPREFIX to - cutter, exploder, campaignd, schema_generator, schema_validator
cmake
  change over to using the source lists
  move source files from libraries that don't appear in scons over to existing source lists - wesnoth-gui_types, wesnoth-gui_event, wesnoth-gui_iterator, wesnoth-gui_placer, wesnoth-gui_tooltip, wesnoth-gui_widget, wesnoth-gui_widget_definition, wesnoth-gui1_widgets, wesnoth-schema_validator
2016-12-15 15:51:29 -05:00
loonycyborg
60329a87a1 Rename Optimize build variant to Optimized for clarity 2016-11-26 14:59:42 +03:00
Sergey Popov
dd1351dc14 Merge pull request #847 from Pentarctagon/Pentarctagon-optimize-build
Add build which uses higher level of optimization
2016-11-26 01:18:22 +03:00
pentarctagon
e4b95ae2fe Use BoolVariable instead of EnumVariable for enable_lto 2016-11-25 10:45:10 -06:00
Pentarctagon
0d419cdc36 Check if LTO is enabled
Check if LTO is enabled

Add LTO flag

Added a flag to enable/disable LTO.  Also pass optimization options to the linker, since older versions of gcc may not automatically use the same options for linking and compiling, and it seems likely clang doesn't do this either.

m3
2016-11-18 01:27:40 -06:00
Pentarctagon
458b9ce62d Update SConstruct
Update SConscript

Update SConscript

m
2016-11-18 01:27:40 -06:00
Gregory A Lundberg
15b7f75b3c Lua cleanup
Deleted two files we NEVER want to allow ANYONE to use.

Updated the howto markdown document.
2016-11-07 14:21:05 -06:00
loonycyborg
9d9cc79cf6 Fix scons -Y build by making wesnoth_lua_config.h path repository-aware 2016-10-18 15:36:47 +03:00
Gregory A Lundberg
f97436b96e Update COPYRIGHT 2016-10-17 10:34:43 -05:00
Gregory A Lundberg
757ffc9e44 README is ancient 2016-10-17 10:34:42 -05:00
Gregory A Lundberg
0c13f7ea20 Update project files
Update for Visual Studio, CMake and SCons.
2016-10-17 10:34:42 -05:00
Gregory A Lundberg
82661505d1 Apply Lua.org patch
Lua can generate wrong code in functions with too many constants.

reported by Marco Schöpl on 17 Jul 2016. existed since 5.3.3.

Example:
    See http://lua-users.org/lists/lua-l/2016-07/msg00303.html.
2016-10-17 10:34:42 -05:00
Gregory A Lundberg
ca883fe7bf Apply Lua.org patch
Checking a format for os.date may read pass the format string.

reported by Nagaev Boris on 10 Jul 2016. existed since 5.3.3.

Example:
    This bug does not seem to happen with regular compilers. It needs an "interceptor" 'memcmp' function that continues reading memory after a difference is found.
2016-10-17 10:34:42 -05:00
Gregory A Lundberg
63be2a0d2e Apply Lua.org patch
Expression list with four or more expressions in a 'for' loop can crash the interpreter.

reported by Marco Schöpl on 17 Jun 2016. existed since 5.2.

Example:
    -- the next loop will probably crash the interpreter
    repeat until load "for _ in _,_,_,_ do local function _() end"
2016-10-17 10:34:41 -05:00
Gregory A Lundberg
90d48e3725 -Wpermissive reports two errors
Reported upstream.
2016-10-17 10:34:41 -05:00
Gregory A Lundberg
841d17af31 Replace Lua 5.2.3 with Lua 5.3.3 2016-10-17 10:34:41 -05:00
Gregory A Lundberg
8e7b28cde2 Move local changes to proper place
luaconf.h provides a place for us to make changes, avoiding the need to change the original definitions. Move everything down there. This encompases the following changes:

1) Disable compatibility with old versions of Lua in the C++. Compatability is maintained only for the Lua runtime. Only one correction was needed: in application_lua_kernel.cpp

2) Change how the backpointer is defined, for forward compatability with Lua 5.3. This effected only one line: in lua_kernel_base.cpp. Using the Lua 5.3 macro caused a GCC warning, suppressed it for that line.

3) Certain Windows-only features are no longer available in the Lua runtime. These features are all in the Lua io module, which we don't allow access to, so this is a non-change for the runtime.

4) Lua will behave as if it is a standard C environment. This, again, mainly effects the Windows environment and features we don't allow access to in the runtime.
2016-10-17 10:34:41 -05:00
Gregory A Lundberg
f00357d7db Revert change
Rather than change the source, if the proplem still exists, use a compiler flag to suppress the messages.

This reverts the commit

commit 12a7a5a1e0fee21e0c88042c6b3c7be1c73f30e3
Author: Mark de Wever <koraq@xs4all.nl>
Date:   Sun Oct 6 17:35:11 2013 +0200

    Remove unused const variables.

    The issue was detected by the upcomming Clang 3.4.
2016-10-17 10:34:41 -05:00
Gregory A Lundberg
b8244b0694 Correct the calls instead
Do not change the released Lua source code. Lua is written as standard C, but we compile it as C++ so we can use exceptions. Change the call sites to avoid the warnings about using a C cast instead of static_cast<int>().

NB: The changes to Wesnoth C++ code will be required to upgrade to Lua 5.3, anyway.

This reverts:

commit cee3ab208401a439e15004b79b4fa5c5bf9a9e5a
Author: Mark de Wever <koraq@xs4all.nl>
Date:   Sun Feb 5 19:55:32 2012 +0000

    Fix compiler warnings.
2016-10-17 10:34:41 -05:00
Gregory A Lundberg
f88c3b22b8 Refactor lua_jailbreak_exception
Revert the changes to the stock Lua source code and move them into the Wesnoth-specific header.
2016-10-17 10:34:41 -05:00
GregoryLundberg
160a4611d6 Use strcmp instead of strcoll
This works for Visual Studio, CMake and SCons.
Still need to get it working on: CodeBlocks and Xcode
2016-10-17 10:34:41 -05:00
Gregory A Lundberg
299b0cc55c No need to redefine PI
Lua, as released, has the correct definition of PI for 'double' (64-bit) floats. It is as precise as possible. If the Boost 128- or 256-bit definitions produce a different value than what Lua provides either (1) we're no longer on 64-bit double floats, (2) there is a typo in Boost, or (3) there is a bug in your compiler.

This reverts the Lua portion of the following commit:

commit f5e673e6443220c57e40cea31d430870b4f73925
Author: fendrin <fabianmueller5@gmx.de>
Date:   Thu Sep 19 01:06:23 2013 +0200

    Replace all kinds of the constant pi representations.

    Replaces every appearance of the circle constant pi I could find with
    the representation from boost/math/constants/constants.hpp.
2016-10-10 10:19:41 -05:00
Gregory A Lundberg
be43e6c730 Fix bug: Index out of bounds
Revert this commit. There was no off-by-one but this commit created one.

Commit commit 299a29f99a84767731dbadd540712d1a37e5e10d
Author: Alexander van Gessel <ai0867@gmail.com>
Date:   Mon Dec 2 17:55:02 2013 +0100

    Fix an off-by-one past-the-end buffer read in lua

    Found by coverity
2016-10-10 10:19:41 -05:00
Gregory A Lundberg
196a044dd6 Revert spurious change to whitespace 2016-10-10 10:19:41 -05:00
Gregory A Lundberg
1528a8bb5a Refactor luaL_typerror
Lua deprecated luaL_typerror. Wesnoth needs it. Traditionally this was handled as a by-hand edit to the Lua source kit. Refactored into Wesnoth as luaW_type_error.
2016-10-10 10:19:41 -05:00
Andreas Löf
d350d91c40 Make strict compilation under scons behave like cmake
This adds -Wold-style-cast to the CCFLAGS when compiling everything
but lua. Lua requires an exception from the flags and there's thus a
workaround added.
2016-06-01 20:57:43 +12:00
gfgtdf
1094db6871 fix msvc build 2016-03-21 17:34:14 +01:00
Charles Dang
83ee4f6087 Convert most includes to src/-relative
This excludes includes that need backtrack path specifiers in order to resolve
name clashes.
2016-03-19 19:35:17 +11:00
Andreas Löf
358bd1235f Remove SDL1.2 code
This removes all legacy SDL1.2 code. It was done by invoking:
coan source --replace --no-transients -D"SDL_VERSION_ATLEAST(X, Y, Z)"=1 <file>
on each file.
2016-03-13 11:34:34 +13:00