forked from LuaJIT/LuaJIT
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix predict_next() in parser (for real now).
Reported by Sergey Kaplun. (cherry picked from commit f602f01) Before the patch `predict_next()` uses the pc allocation limit (`fs->bclim`) instead of the real limit of the defined bytecodes (`fs->pc`). This leads to the use of undefined value and possible crash. This patch fixes the check. Sergey Kaplun: * added the description and the test for the problem Part of tarantool/tarantool#10709
- Loading branch information
Showing
2 changed files
with
33 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
local tap = require('tap') | ||
local test = tap.test('lj-1226-fix-predict-next') | ||
|
||
test:plan(3) | ||
|
||
-- The resulting bytecode is the following: | ||
-- | ||
-- 0001 KNIL 0 3 | ||
-- 0002 JMP 4 => 0003 | ||
-- 0003 => ITERC 4 2 3 | ||
-- 0004 ITERL 4 => 0003 | ||
-- | ||
-- The parsing of the `for` iterator uses the incorrect check for | ||
-- `fs->bclim`, which allows the usage of an uninitialized value, | ||
-- so the test fails under Valgrind. | ||
local res_f = loadstring([[ | ||
-- This local variable is necessary, because it emits `KPRI` | ||
-- bytecode, with which the next `KPRI` bytecode will be merged. | ||
local _ | ||
for _ in nil do end | ||
]]) | ||
|
||
test:ok(res_f, 'chunk loaded successfully') | ||
|
||
local res, err = pcall(res_f) | ||
|
||
-- Check consistency with PUC Rio Lua 5.1 behaviour. | ||
test:ok(not res, 'loaded function not executed') | ||
test:like(err, 'attempt to call a nil value', 'correct error message') | ||
|
||
test:done(true) |