Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 26b6ab3

Browse files
committed
[[ Bug 22063 ]] Ensure nothing is a valid optional foreign handler value
This patch ensures that nothing can be passed as an argument to a handler parameter which is typed as an optional foreign handler type. Previously the value passed was being dereferenced as a handler value without checking whether it was kMCNull first.
1 parent 9a5b780 commit 26b6ab3

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

docs/lcb/notes/22063.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# [22063] Ensure nothing can be passed to an optional foreign handler type parameter

libscript/src/script-execute.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1224,7 +1224,8 @@ MCScriptExecuteContext::UnboxingConvert(MCValueRef p_value,
12241224
}
12251225
}
12261226
else if (MCTypeInfoIsHandler(p_slot_type.type) &&
1227-
MCHandlerTypeInfoIsForeign(p_slot_type.type))
1227+
MCHandlerTypeInfoIsForeign(p_slot_type.type) &&
1228+
p_value != kMCNull)
12281229
{
12291230
// If the slot type is a foreign handler, then we fetch a closure
12301231
// from the handler value.

tests/lcb/vm/native-callback.lcb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,23 @@ public handler TestNativeCallback()
5858
test "use function pointer" when sTotal is (1 + 2 + 3 + 4 + 5 + 6)
5959
end handler
6060

61+
--------- NULLPTR FUNCTION PTRS
62+
63+
foreign handler type DummyHandlerType() returns nothing
64+
65+
/* To test whether nothing can be passed as an optional handler type value we
66+
* need any function which takes a pointer, but will ignore it. */
67+
foreign handler MCDataCreateWithBytes(in pPointer as optional DummyHandlerType, in pLength as LCUIndex, out rData as Data) returns CBool binds to "<builtin>"
68+
69+
public handler TestNullptrNativeCallback()
70+
variable tDummyHandler as optional DummyHandlerType
71+
variable tDummyData as optional Data
72+
unsafe
73+
MCDataCreateWithBytes(tDummyHandler, 0, tDummyData)
74+
end unsafe
75+
test "use nothing as optional function pointer" when tDummyData is not nothing
76+
end handler
77+
6178
--------- FOREIGN HANDLER FUNCTION PTRS
6279

6380
-- This test checks that it is possible to pass foreign handlers around as

0 commit comments

Comments
 (0)