tracers: avoid panic on invalid arguments (#20612)

* add regression tests for #20611

* eth/tracers: fix panics occurring for invalid params in js-tracers

Co-authored-by: Martin Holst Swende <martin@swende.se>
This commit is contained in:
tintin
2020-02-04 09:55:07 +01:00
committed by GitHub
parent 5a9c96454e
commit 33791dbeb5
2 changed files with 44 additions and 2 deletions

View File

@ -63,6 +63,39 @@ func runTrace(tracer *Tracer) (json.RawMessage, error) {
return tracer.GetResult()
}
// TestRegressionPanicSlice tests that we don't panic on bad arguments to memory access
func TestRegressionPanicSlice(t *testing.T) {
tracer, err := New("{depths: [], step: function(log) { this.depths.push(log.memory.slice(-1,-2)); }, fault: function() {}, result: function() { return this.depths; }}")
if err != nil {
t.Fatal(err)
}
if _, err = runTrace(tracer); err != nil {
t.Fatal(err)
}
}
// TestRegressionPanicSlice tests that we don't panic on bad arguments to stack peeks
func TestRegressionPanicPeek(t *testing.T) {
tracer, err := New("{depths: [], step: function(log) { this.depths.push(log.stack.peek(-1)); }, fault: function() {}, result: function() { return this.depths; }}")
if err != nil {
t.Fatal(err)
}
if _, err = runTrace(tracer); err != nil {
t.Fatal(err)
}
}
// TestRegressionPanicSlice tests that we don't panic on bad arguments to memory getUint
func TestRegressionPanicGetUint(t *testing.T) {
tracer, err := New("{ depths: [], step: function(log, db) { this.depths.push(log.memory.getUint(-64));}, fault: function() {}, result: function() { return this.depths; }}")
if err != nil {
t.Fatal(err)
}
if _, err = runTrace(tracer); err != nil {
t.Fatal(err)
}
}
func TestTracing(t *testing.T) {
tracer, err := New("{count: 0, step: function() { this.count += 1; }, fault: function() {}, result: function() { return this.count; }}")
if err != nil {