diff --git a/CHANGES.txt b/CHANGES.txt index d13e4e07..e231aebf 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -106,6 +106,7 @@ * Fix linking to external libraries outside of project folder * Improve processing of ld.so.conf (Cameron Hart) * Patch 154: Fix .def file support for VS2010 (Riccardo Ghetta) +* Patch 159: Validate all values passed to options (Moi_ioM) ------- diff --git a/src/base/option.lua b/src/base/option.lua index 4243a424..8dd9d050 100644 --- a/src/base/option.lua +++ b/src/base/option.lua @@ -1,25 +1,25 @@ -- -- option.lua -- Work with the list of registered options. --- Copyright (c) 2002-2009 Jason Perkins and the Premake project +-- Copyright (c) 2002-2013 Jason Perkins and the Premake project -- - premake.option = { } + premake.option = {} -- -- The list of registered options. -- - premake.option.list = { } - + premake.option.list = {} + -- -- Register a new option. -- -- @param opt -- The new option object. --- +-- function premake.option.add(opt) -- some sanity checking @@ -29,11 +29,11 @@ missing = field end end - + if (missing) then error("option needs a " .. missing, 3) end - + -- add it to the master list premake.option.list[opt.trigger] = opt end @@ -64,7 +64,7 @@ table.insert(keys, option.trigger) end table.sort(keys) - + local i = 0 return function() i = i + 1 @@ -89,18 +89,24 @@ if (not opt) then return false, "invalid option '" .. key .. "'" end - + -- does it need a value? if (opt.value and value == "") then return false, "no value specified for option '" .. key .. "'" end - + -- is the value allowed? - if (opt.allowed) then + if opt.allowed then + local found = false for _, match in ipairs(opt.allowed) do - if (match[1] == value) then return true end + if match[1] == value then + found = true + break + end + end + if not found then + return false, string.format("invalid value '%s' for option '%s'", value, key) end - return false, "invalid value '" .. value .. "' for option '" .. key .. "'" end end return true