Skip to content

Give a cppia call to a host function its type before it links - #510

Open
dimensionscape wants to merge 2 commits into
mainfrom
fix/cppia-callhaxe-return-type
Open

dimensionscape wants to merge 2 commits into
mainfrom
fix/cppia-callhaxe-return-type

Conversation

@dimensionscape

Copy link
Copy Markdown
Member

CallHaxe set returnType in link, after it checked the argument count. A call with the wrong count records the miss and returns early, so its type stayed uninitialized, and an expression that asks the type while it links read it: an addition, a comparison, a negation or a switch. The fuzz job on #500 caught it:

src/hx/cppia/Cppia.cpp:1968:47: runtime error: load of value 80, which is not a valid value for type 'ExprType'
    #0 hx::CallHaxe::getType()
    #1 hx::Call::link(hx::CppiaModule&)

#500 added that read in Call::link; on main, OpAdd, OpCompareBase, OpNeg, BinOp and SwitchExpr read it the same way. The constructor now sets the type from the host's signature, so it is known before link and on the early return.

CppiaHostMismatch gets a script that adds 1 to the result of such a call. It fails to load naming the call, interpreted and under the JIT. UBSan only reports the read when the leftover value is out of range, so the test cannot catch the old code every time; a probe in main's getType showed the new script reaching the read.

Checked with GCC 13 and UBSan on Linux: CppiaHostMismatch matches stdout.txt with the change.

CallHaxe set returnType in link, after checking the argument count, so a
call with the wrong count, which records the miss and returns early, kept
an uninitialized type. An expression that asks while it links, as an
addition, a comparison, a negation or a switch does, read it: undefined,
and UBSan reported it in the fuzz job of #500 as a load of
80 into ExprType. The constructor sets the type from the host's signature
now. CppiaHostMismatch adds to the result of such a call.
@dimensionscape dimensionscape added this to the 6.1.0 milestone Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant