From 5fb1e492fb32e664364603c34044c3e573501781 Mon Sep 17 00:00:00 2001 From: Frankie Date: Wed, 19 Oct 2016 14:33:30 -0700 Subject: [PATCH 1/8] Add valdations to txData param --- ui/app/send.js | 6 ++++++ ui/app/util.js | 6 ++++++ 2 files changed, 12 insertions(+) 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 +} From 4366f72fe1d9f0c3a94f27e5f23bd826f8cf69e0 Mon Sep 17 00:00:00 2001 From: Frankie Date: Wed, 19 Oct 2016 15:22:56 -0700 Subject: [PATCH 2/8] Add unit test for isHex and add to CHANGELOG.md --- CHANGELOG.md | 1 + test/unit/util_test.js | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4f6e82e94..db876e5ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Current Master +- Add a check for improper Transaction data. - Increase default max gas to `100000` over the RPC's `estimateGas` response. ## 2.13.4 2016-10-17 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) + }) + + }) }) }) From 7140c04ef9239ea66c7b3f512c2f4c868778c2fe Mon Sep 17 00:00:00 2001 From: Frankie Date: Wed, 19 Oct 2016 15:26:19 -0700 Subject: [PATCH 3/8] Fix CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 738acb6c4..f2c442050 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,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. From ac7dca22c3a630d4623e44abe1e86d1cc51f3acc Mon Sep 17 00:00:00 2001 From: Frankie Date: Wed, 19 Oct 2016 17:39:41 -0700 Subject: [PATCH 4/8] Fix up wording --- ui/app/send.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/app/send.js b/ui/app/send.js index d28a6433b..b8af19028 100644 --- a/ui/app/send.js +++ b/ui/app/send.js @@ -191,7 +191,7 @@ SendTransactionScreen.prototype.render = function () { marginBottom: '16px', }, }, [ - 'Transactional Data (optional)', + 'Transaction Data (optional)', ]), // 'data' field From aa4746f4c723857710d61482a73960d863a8a098 Mon Sep 17 00:00:00 2001 From: Frankie Date: Wed, 19 Oct 2016 19:35:44 -0700 Subject: [PATCH 5/8] Add test and ability for isHex to handle hex strings with hex-prefix --- test/unit/util_test.js | 5 +++++ ui/app/util.js | 1 + 2 files changed, 6 insertions(+) diff --git a/test/unit/util_test.js b/test/unit/util_test.js index b7d8ba528..eec3183fe 100644 --- a/test/unit/util_test.js +++ b/test/unit/util_test.js @@ -243,6 +243,11 @@ describe('util', function() { assert.equal(result, false) }) + it('should return true when given a hex string with hex-prefix', function() { + var result = util.isHex('0xc3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2') + assert.equal(result, true) + }) + }) }) }) diff --git a/ui/app/util.js b/ui/app/util.js index facaef3ee..a519ab5b4 100644 --- a/ui/app/util.js +++ b/ui/app/util.js @@ -212,6 +212,7 @@ function readableDate (ms) { } function isHex (str) { + if (str.startsWith('0x')) str = str.replace('0x', '') if (str.match(/[g-zG-Z]/) || str.match(/\W/)) return false return true } From d4c0a4949bd8331e965ad17c5ac04af7b6fb90ea Mon Sep 17 00:00:00 2001 From: Frankie Date: Thu, 20 Oct 2016 12:26:35 -0700 Subject: [PATCH 6/8] Clean up tests --- test/unit/util_test.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/unit/util_test.js b/test/unit/util_test.js index eec3183fe..00528b905 100644 --- a/test/unit/util_test.js +++ b/test/unit/util_test.js @@ -230,22 +230,22 @@ describe('util', function() { describe('#isHex', function(){ it('should return true when given a hex string', function() { var result = util.isHex('c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2') - assert.equal(result, true) + assert(result) }) it('should return false when given a non-hex string', function() { var result = util.isHex('c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714imnotreal') - assert.equal(result, false) + assert(!result) }) 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) + assert(!result) }) it('should return true when given a hex string with hex-prefix', function() { var result = util.isHex('0xc3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2') - assert.equal(result, true) + assert(result) }) }) From d79424e9c04fb409843c3a08b8f6eabc1036b7b6 Mon Sep 17 00:00:00 2001 From: Frankie Date: Fri, 21 Oct 2016 16:05:39 -0700 Subject: [PATCH 7/8] clean up the isHex function --- ui/app/util.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ui/app/util.js b/ui/app/util.js index a519ab5b4..72b3af465 100644 --- a/ui/app/util.js +++ b/ui/app/util.js @@ -212,7 +212,8 @@ function readableDate (ms) { } function isHex (str) { - if (str.startsWith('0x')) str = str.replace('0x', '') - if (str.match(/[g-zG-Z]/) || str.match(/\W/)) return false - return true + if (str.startsWith('0x')) { + return !str.substring(2).match(/([g-zG-Z]|\W)/) + } + return !str.match(/([g-zG-Z]|\W)/) } From 7d9e295b759ccd1ca77e286651c3da71284631e3 Mon Sep 17 00:00:00 2001 From: Frankie Date: Fri, 21 Oct 2016 16:39:14 -0700 Subject: [PATCH 8/8] Change regex in isHex function --- ui/app/util.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/ui/app/util.js b/ui/app/util.js index 72b3af465..7a56bf6a0 100644 --- a/ui/app/util.js +++ b/ui/app/util.js @@ -212,8 +212,5 @@ function readableDate (ms) { } function isHex (str) { - if (str.startsWith('0x')) { - return !str.substring(2).match(/([g-zG-Z]|\W)/) - } - return !str.match(/([g-zG-Z]|\W)/) + return Boolean(str.match(/^(0x)?[0-9a-fA-F]+$/)) }