Skip to content

Commit

Permalink
Merge pull request #92 from ethereumjs/fix-rpc-crash
Browse files Browse the repository at this point in the history
Fix crash on some invalid RPC params
  • Loading branch information
vpulim authored Feb 21, 2019
2 parents 793220d + d3a5d9f commit dfd3797
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ async function run () {

process.on('SIGINT', async () => {
logger.info('Caught interrupt signal. Shutting down...')
if (server) await server.stop()
if (server) server.http().close()
await node.stop()
logger.info('Exiting.')
process.exit()
Expand Down
15 changes: 15 additions & 0 deletions lib/rpc/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ module.exports = {
*/
hex (params, index) {
let err
if (typeof params[index] !== 'string') {
return {
code: INVALID_PARAMS,
message: `invalid argument ${index}: argument must be a hex string`
}
}

if (params[index].substr(0, 2) !== '0x') {
err = {
code: INVALID_PARAMS,
Expand All @@ -60,6 +67,14 @@ module.exports = {
*/
blockHash (params, index) {
let err

if (typeof params[index] !== 'string') {
return {
code: INVALID_PARAMS,
message: `invalid argument ${index}: argument must be a hex string`
}
}

let blockHash = params[index].substring(2)

if (!/^[0-9a-fA-F]+$/.test(blockHash) | blockHash.length !== 64) {
Expand Down

0 comments on commit dfd3797

Please sign in to comment.