From ab698a59124030c8479b8bd06d3cafc319e7a218 Mon Sep 17 00:00:00 2001 From: Zsolt Felfoldi Date: Thu, 30 Mar 2017 14:16:24 +0200 Subject: [PATCH] eth/gasprice: added security checks for gpo params --- eth/gasprice/gasprice.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/eth/gasprice/gasprice.go b/eth/gasprice/gasprice.go index 39399bd83f..088253342b 100644 --- a/eth/gasprice/gasprice.go +++ b/eth/gasprice/gasprice.go @@ -48,13 +48,24 @@ type GasPriceOracle struct { // NewGasPriceOracle returns a new oracle. func NewGasPriceOracle(backend ethapi.Backend, params GpoParams) *GasPriceOracle { + blocks := params.GpoBlocks + if blocks < 1 { + blocks = 1 + } + percent := params.GpoPercentile + if percent < 0 { + percent = 0 + } + if percent > 100 { + percent = 100 + } return &GasPriceOracle{ backend: backend, lastPrice: params.GpoDefault, - checkBlocks: params.GpoBlocks, - minBlocks: (params.GpoBlocks + 1) / 2, - maxBlocks: params.GpoBlocks * 5, - percentile: params.GpoPercentile, + checkBlocks: blocks, + minBlocks: (blocks + 1) / 2, + maxBlocks: blocks * 5, + percentile: percent, } }