diff options
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | test/unit/util_test.js | 17 | ||||
-rw-r--r-- | ui/app/send.js | 6 | ||||
-rw-r--r-- | ui/app/util.js | 6 |
4 files changed, 30 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index d6d400b66..738acb6c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Current Master +- Add a check for improper Transaction data. ## 2.13.5 2016-10-18 - Increase default max gas to `100000` over the RPC's `estimateGas` response. diff --git a/test/unit/util_test.js b/test/unit/util_test.js index 45e545e8e..b7d8ba528 100644 --- a/test/unit/util_test.js +++ b/test/unit/util_test.js @@ -227,5 +227,22 @@ describe('util', function() { assert.equal(result.toString(10), '1111000000000000000', 'accepts decimals') }) }) + describe('#isHex', function(){ + it('should return true when given a hex string', function() { + var result = util.isHex('c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2') + assert.equal(result, true) + }) + + it('should return false when given a non-hex string', function() { + var result = util.isHex('c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714imnotreal') + assert.equal(result, false) + }) + + it('should return false when given a string containing a non letter/number character', function() { + var result = util.isHex('c3ab8ff13720!8ad9047dd39466b3c%8974e592c2fa383d4a396071imnotreal') + assert.equal(result, false) + }) + + }) }) }) diff --git a/ui/app/send.js b/ui/app/send.js index 97ed29e4a..d28a6433b 100644 --- a/ui/app/send.js +++ b/ui/app/send.js @@ -7,6 +7,7 @@ const actions = require('./actions') const util = require('./util') const numericBalance = require('./util').numericBalance const addressSummary = require('./util').addressSummary +const isHex = require('./util').isHex const EthBalance = require('./components/eth-balance') const ethUtil = require('ethereumjs-util') const RangeSlider = require('./components/range-slider') @@ -312,6 +313,11 @@ SendTransactionScreen.prototype.onSubmit = function (gasPrice) { return this.props.dispatch(actions.displayWarning(message)) } + if (!isHex(ethUtil.stripHexPrefix(txData)) && txData) { + message = 'Transaction data must be hex string.' + return this.props.dispatch(actions.displayWarning(message)) + } + this.props.dispatch(actions.hideWarning()) var txParams = { diff --git a/ui/app/util.js b/ui/app/util.js index e4b77e2bc..facaef3ee 100644 --- a/ui/app/util.js +++ b/ui/app/util.js @@ -35,6 +35,7 @@ module.exports = { normalizeNumberToWei: normalizeNumberToWei, valueTable: valueTable, bnTable: bnTable, + isHex: isHex, } function valuesFor (obj) { @@ -209,3 +210,8 @@ function readableDate (ms) { var time = `${hours}:${minutes.substr(-2)}:${seconds.substr(-2)}` return `${dateStr} ${time}` } + +function isHex (str) { + if (str.match(/[g-zG-Z]/) || str.match(/\W/)) return false + return true +} |