Skip to content

Commit

Permalink
add catch for overly long requests
Browse files Browse the repository at this point in the history
  • Loading branch information
RichardAH committed Sep 13, 2019
1 parent 5d0780d commit b934981
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions example-contract-hpdir/bin/contract.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
process.on("uncaughtException", function(err){
console.log("Uncaught exception raised : " + err);
});
/**
HpDir -- A Hot Pocket smart contract to provide directory services
for other smart contracts
Expand Down Expand Up @@ -36,6 +33,9 @@ const fs = require('fs')
const pipe = require('posix-pipe-fork-exec')

var rom = Buffer.from(pipe.getfdbytes(0)).toString()

console.log(rom)

try {
rom = JSON.parse(rom)
} catch (e) {
Expand All @@ -49,6 +49,7 @@ for (var user in rom.user) {
var fd = rom.user[user]

var input = Buffer.from(pipe.getfdbytes(fd[0])).toString()

console.log('user input: ' + input)
if (input) {
process_user_input(user, fd[0], fd[1], input)
Expand All @@ -71,6 +72,9 @@ function process_user_input(user, fdin, fdout, inp) {

if (!inp) return

if (inp.length > 300)
return error('total length of request must not exceed 300 characters')

try {
inp = JSON.parse(inp)
} catch (e) {
Expand Down

0 comments on commit b934981

Please sign in to comment.