Skip to content

Commit 04f436b

Browse files
Merge the fuzz fixes from 66ff681
An abstract cppia function has no function to call rather than a RETURN cast to one, and the fuzz target leaves out the std Unserializer's negative string lengths.
2 parents 66ff681 + 15c3950 commit 04f436b

10 files changed

Lines changed: 71 additions & 10 deletions

File tree

‎src/hx/cppia/Cppia.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,8 @@ struct CppiaFunction : public CppiaOwned<CppiaFunction>
515515
std::vector<ArgInfo> args;
516516
ScriptCallable *funExpr;
517517
// The body as it came. A class's __init__ is an expression of any kind,
518-
// which is not a ScriptCallable, and has no funExpr
518+
// and an abstract function's a bare RETURN: neither is a ScriptCallable,
519+
// and neither has a funExpr
519520
CppiaExpr *body;
520521

521522
CppiaFunction(CppiaModule *inCppia,bool inIsStatic,bool inIsDynamic);

‎src/hx/cppia/CppiaClasses.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1530,7 +1530,7 @@ void CppiaClassInfo::link()
15301530
for(size_t n=0; n<nativeInterfaceFunctions.size(); n++)
15311531
{
15321532
ScriptNamedFunction *host = nativeInterfaceFunctions[n];
1533-
if (host->name && memberFunctions[i]->name==host->name && host->signature &&
1533+
if (func && host->name && memberFunctions[i]->name==host->name && host->signature &&
15341534
!interfaceSignatureMatches(host->signature, func))
15351535
{
15361536
func = createInterfaceAdapter(cppia, host, func);

‎src/hx/cppia/CppiaFunction.cpp‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,16 +1168,14 @@ void CppiaFunction::load(CppiaStream &stream,bool inExpectBody)
11681168
}
11691169
if (inExpectBody)
11701170
{
1171-
// A body is a function, or for an abstract function a bare RETURN. A
1172-
// class's __init__ is an expression of any kind, which the class runs
1173-
// as it is. A malformed file can give any other expression
1171+
// A body is a function, or for an abstract function a bare RETURN, which
1172+
// is never run. A class's __init__ is an expression of any kind, which
1173+
// the class runs as it is. Neither is a ScriptCallable, so neither has
1174+
// a funExpr. A malformed file can give any other expression
11741175
body = createCppiaExpr(stream);
1175-
if (name=="__init__")
1176-
funExpr = 0;
1177-
else if (!dynamic_cast<ScriptCallable *>(body) && std::string(body->getName())!="RetVal")
1176+
funExpr = dynamic_cast<ScriptCallable *>(body);
1177+
if (!funExpr && name!="__init__" && std::string(body->getName())!="RetVal")
11781178
throw "Function body is not a function";
1179-
else
1180-
funExpr = (ScriptCallable *)body;
11811179
}
11821180
stream.module->creatingFunction = 0;
11831181
}

‎test/fuzz/Fuzz.hx‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,11 @@ class Fuzz {
362362
// name prints until the stack overflows, on every target
363363
if (b.toString().indexOf("l") >= 0 && b.toString().indexOf("r") >= 0)
364364
return;
365+
// The std's Unserializer takes a negative string or bytes length
366+
// ("y-10:") as a step back, and parses the same text again until the
367+
// stack overflows, on every target
368+
if (~/[ys]-/.match(b.toString()))
369+
return;
365370
var v1 = attempt(() -> haxe.Unserializer.run(b.toString()));
366371
var s1:String = v1 == null ? null : attempt(() -> serialize(v1));
367372
var v2 = s1 == null ? null : attempt(() -> haxe.Unserializer.run(s1));
765 Bytes
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
bby-0:ai0iy-010:ci1h
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// An abstract function comes in a cppia file with a bare RETURN as its body,
2+
// which is never run. It was kept as a function through a cast, which is
3+
// undefined for an expression that is not one; it has no function now, and
4+
// its class's subclasses still dispatch to their overrides.
5+
function main() {
6+
var script = haxe.io.Path.join([haxe.io.Path.directory(Sys.programPath()), "script.cppia"]);
7+
for (jit in [false, true]) {
8+
cpp.cppia.Host.enableJit(jit);
9+
try {
10+
cpp.cppia.Host.runFile(script);
11+
} catch (e:Dynamic) {
12+
Sys.println("error: " + e);
13+
}
14+
}
15+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
abstract class Shape {
2+
public function new() {}
3+
4+
public abstract function area():Float;
5+
6+
public function describe():String {
7+
return "area " + area();
8+
}
9+
}
10+
11+
class Square extends Shape {
12+
var side:Float;
13+
14+
public function new(side:Float) {
15+
super();
16+
this.side = side;
17+
}
18+
19+
public function area():Float {
20+
return side * side;
21+
}
22+
}
23+
24+
class Script {
25+
static function main() {
26+
var shape:Shape = new Square(3);
27+
Sys.println("an abstract function dispatches to its override: " + (shape.area() == 9));
28+
Sys.println("a base method calls the override: " + (shape.describe() == "area 9"));
29+
}
30+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
--main Script
2+
-cppia bin/script.cppia
3+
--next
4+
--main Main
5+
-cpp bin
6+
-D scriptable
7+
--dce no
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
an abstract function dispatches to its override: true
2+
a base method calls the override: true
3+
an abstract function dispatches to its override: true
4+
a base method calls the override: true

0 commit comments

Comments
 (0)