Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix/limit http body size #2006

Merged
merged 2 commits into from
Feb 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
try {
String contract = request.getReader().lines()
.collect(Collectors.joining(System.lineSeparator()));
Util.checkBodySize(contract);
AccountPermissionUpdateContract.Builder build = AccountPermissionUpdateContract.newBuilder();
JsonFormat.merge(contract, build);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
try {
String contract = request.getReader().lines()
.collect(Collectors.joining(System.lineSeparator()));
Util.checkBodySize(contract);
JSONObject input = JSONObject.parseObject(contract);
String strTransaction = input.getJSONObject("transaction").toJSONString();
Transaction transaction = Util.packTransaction(strTransaction);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
try {
String input = request.getReader().lines()
.collect(Collectors.joining(System.lineSeparator()));
Util.checkBodySize(input);
Transaction transaction = Util.packTransaction(input);
GrpcAPI.Return retur = wallet.broadcastTransaction(transaction);
response.getWriter().println(JsonFormat.printToString(retur));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
try {
String contract = request.getReader().lines()
.collect(Collectors.joining(System.lineSeparator()));
Util.checkBodySize(contract);
AccountCreateContract.Builder build = AccountCreateContract.newBuilder();
JsonFormat.merge(contract, build);
Transaction tx = wallet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
try {
String input = request.getReader().lines()
.collect(Collectors.joining(System.lineSeparator()));
Util.checkBodySize(input);
BytesMessage.Builder build = BytesMessage.newBuilder();
JsonFormat.merge(input, build);
byte[] address = wallet.createAdresss(build.getValue().toByteArray());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
try {
String contract = request.getReader().lines()
.collect(Collectors.joining(System.lineSeparator()));
Util.checkBodySize(contract);
AssetIssueContract.Builder build = AssetIssueContract.newBuilder();
JsonFormat.merge(contract, build);
Transaction tx = wallet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
try {
String contract = request.getReader().lines()
.collect(Collectors.joining(System.lineSeparator()));
Util.checkBodySize(contract);
WitnessCreateContract.Builder build = WitnessCreateContract.newBuilder();
JsonFormat.merge(contract, build);
Transaction tx = wallet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
try {
String contract = request.getReader().lines()
.collect(Collectors.joining(System.lineSeparator()));
Util.checkBodySize(contract);
CreateSmartContract.Builder build = CreateSmartContract.newBuilder();
JSONObject jsonObject = JSONObject.parseObject(contract);
byte[] ownerAddress = ByteArray.fromHexString(jsonObject.getString("owner_address"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
try {
String input = request.getReader().lines()
.collect(Collectors.joining(System.lineSeparator()));
Util.checkBodySize(input);
EasyTransferByPrivateMessage.Builder build = EasyTransferByPrivateMessage.newBuilder();
JsonFormat.merge(input, build);
byte[] privateKey = build.getPrivateKey().toByteArray();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
try {
String input = request.getReader().lines()
.collect(Collectors.joining(System.lineSeparator()));
Util.checkBodySize(input);
EasyTransferMessage.Builder build = EasyTransferMessage.newBuilder();
JsonFormat.merge(input, build);
byte[] privateKey = wallet.pass2Key(build.getPassPhrase().toByteArray());
Expand Down Expand Up @@ -71,6 +72,8 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
logger.debug("IOException: {}", ioe.getMessage());
}
return;
} catch (Exception e) {
logger.debug("Exception: {}", e.getMessage());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
try {
String contract = request.getReader().lines()
.collect(Collectors.joining(System.lineSeparator()));
Util.checkBodySize(contract);
ExchangeCreateContract.Builder build = ExchangeCreateContract.newBuilder();
JsonFormat.merge(contract, build);
Transaction tx = wallet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
try {
String contract = request.getReader().lines()
.collect(Collectors.joining(System.lineSeparator()));
Util.checkBodySize(contract);
ExchangeInjectContract.Builder build = ExchangeInjectContract.newBuilder();
JsonFormat.merge(contract, build);
Transaction tx = wallet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
try {
String contract = request.getReader().lines()
.collect(Collectors.joining(System.lineSeparator()));
Util.checkBodySize(contract);
ExchangeTransactionContract.Builder build = ExchangeTransactionContract.newBuilder();
JsonFormat.merge(contract, build);
Transaction tx = wallet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
try {
String contract = request.getReader().lines()
.collect(Collectors.joining(System.lineSeparator()));
Util.checkBodySize(contract);
ExchangeWithdrawContract.Builder build = ExchangeWithdrawContract.newBuilder();
JsonFormat.merge(contract, build);
Transaction tx = wallet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,11 @@ public class FreezeBalanceServlet extends HttpServlet {
@Autowired
private Wallet wallet;

protected void doGet(HttpServletRequest request, HttpServletResponse response) {

}

protected void doPost(HttpServletRequest request, HttpServletResponse response) {
try {
String contract = request.getReader().lines()
.collect(Collectors.joining(System.lineSeparator()));
Util.checkBodySize(contract);
FreezeBalanceContract.Builder build = FreezeBalanceContract.newBuilder();
JsonFormat.merge(contract, build);
Transaction tx = wallet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.springframework.stereotype.Component;
import org.tron.common.utils.ByteArray;
import org.tron.core.Wallet;
import org.tron.protos.Contract.AssetIssueContract;
import org.tron.protos.Protocol.Account;

@Component
Expand Down Expand Up @@ -64,6 +63,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
try {
String account = request.getReader().lines()
.collect(Collectors.joining(System.lineSeparator()));
Util.checkBodySize(account);
Account.Builder build = Account.newBuilder();
JsonFormat.merge(account, build);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
try {
String account = request.getReader().lines()
.collect(Collectors.joining(System.lineSeparator()));
Util.checkBodySize(account);
Account.Builder build = Account.newBuilder();
JsonFormat.merge(account, build);
AccountNetMessage reply = wallet.getAccountNet(build.getAddress());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.tron.api.GrpcAPI.AccountResourceMessage;
import org.tron.common.utils.ByteArray;
import org.tron.core.Wallet;
import org.tron.core.db.Manager;


@Component
Expand All @@ -23,9 +22,6 @@ public class GetAccountResourceServlet extends HttpServlet {
@Autowired
private Wallet wallet;

@Autowired
private Manager dbManager;

protected void doGet(HttpServletRequest request, HttpServletResponse response) {
try {
String address = request.getParameter("address");
Expand All @@ -50,6 +46,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
try {
String input = request.getReader().lines()
.collect(Collectors.joining(System.lineSeparator()));
Util.checkBodySize(input);
JSONObject jsonObject = JSONObject.parseObject(input);
String address = jsonObject.getString("address");
AccountResourceMessage reply = wallet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
try {
String account = request.getReader().lines()
.collect(Collectors.joining(System.lineSeparator()));
Util.checkBodySize(account);
Account.Builder build = Account.newBuilder();
JsonFormat.merge(account, build);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
try {
String account = request.getReader().lines()
.collect(Collectors.joining(System.lineSeparator()));
Util.checkBodySize(account);
Account.Builder build = Account.newBuilder();
JsonFormat.merge(account, build);
AssetIssueList reply = wallet.getAssetIssueByAccount(build.getAddress());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
try {
String input = request.getReader().lines()
.collect(Collectors.joining(System.lineSeparator()));
Util.checkBodySize(input);
JSONObject jsonObject = JSONObject.parseObject(input);
String id = jsonObject.getString("value");

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.tron.core.services.http;

import com.alibaba.fastjson.JSONObject;
import com.google.protobuf.ByteString;
import java.io.IOException;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -47,6 +46,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
try {
String input = request.getReader().lines()
.collect(Collectors.joining(System.lineSeparator()));
Util.checkBodySize(input);
BytesMessage.Builder build = BytesMessage.newBuilder();
JsonFormat.merge(input, build);
AssetIssueContract reply = wallet.getAssetIssueByName(build.getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.tron.api.GrpcAPI.BytesMessage;
import org.tron.common.utils.ByteArray;
import org.tron.core.Wallet;
import org.tron.protos.Contract.AssetIssueContract;

@Component
@Slf4j(topic = "API")
Expand Down Expand Up @@ -46,6 +45,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
try {
String input = request.getReader().lines()
.collect(Collectors.joining(System.lineSeparator()));
Util.checkBodySize(input);
BytesMessage.Builder build = BytesMessage.newBuilder();
JsonFormat.merge(input, build);
AssetIssueList reply = wallet.getAssetIssueListByName(build.getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
try {
String input = request.getReader().lines()
.collect(Collectors.joining(System.lineSeparator()));
Util.checkBodySize(input);
BytesMessage.Builder build = BytesMessage.newBuilder();
JsonFormat.merge(input, build);
Block reply = wallet.getBlockById(build.getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
try {
String input = request.getReader().lines()
.collect(Collectors.joining(System.lineSeparator()));
Util.checkBodySize(input);
NumberMessage.Builder build = NumberMessage.newBuilder();
JsonFormat.merge(input, build);
long getNum = build.getNum();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
try {
String input = request.getReader().lines()
.collect(Collectors.joining(System.lineSeparator()));
Util.checkBodySize(input);
BlockLimit.Builder build = BlockLimit.newBuilder();
JsonFormat.merge(input, build);
long startNum = build.getStartNum();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
try {
String input = request.getReader().lines()
.collect(Collectors.joining(System.lineSeparator()));
Util.checkBodySize(input);
NumberMessage.Builder build = NumberMessage.newBuilder();
JsonFormat.merge(input, build);
Block reply = wallet.getBlockByNum(build.getNum());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) {
BytesMessage.Builder build = BytesMessage.newBuilder();
JsonFormat.merge(jsonObject.toJSONString(), build);
SmartContract smartContract = wallet.getContract(build.build());
JSONObject jsonSmartContract = JSONObject.parseObject(JsonFormat.printToString(smartContract));
JSONObject jsonSmartContract = JSONObject
.parseObject(JsonFormat.printToString(smartContract));
response.getWriter().println(jsonSmartContract.toJSONString());
} catch (Exception e) {
logger.debug("Exception: {}", e.getMessage());
Expand All @@ -45,10 +46,12 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
try {
String input = request.getReader().lines()
.collect(Collectors.joining(System.lineSeparator()));
Util.checkBodySize(input);
BytesMessage.Builder build = BytesMessage.newBuilder();
JsonFormat.merge(input, build);
SmartContract smartContract = wallet.getContract(build.build());
JSONObject jsonSmartContract = JSONObject.parseObject(JsonFormat.printToString(smartContract));
JSONObject jsonSmartContract = JSONObject
.parseObject(JsonFormat.printToString(smartContract));
response.getWriter().println(jsonSmartContract.toJSONString());
} catch (Exception e) {
logger.debug("Exception: {}", e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
@Slf4j(topic = "API")
public class GetDelegatedResourceAccountIndexServlet extends HttpServlet {

@Autowired private Wallet wallet;
@Autowired
private Wallet wallet;

protected void doGet(HttpServletRequest request, HttpServletResponse response) {
try {
Expand All @@ -45,6 +46,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
try {
String input = request.getReader().lines()
.collect(Collectors.joining(System.lineSeparator()));
Util.checkBodySize(input);
BytesMessage.Builder build = BytesMessage.newBuilder();
JsonFormat.merge(input, build);
DelegatedResourceAccountIndex reply =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
@Slf4j(topic = "API")
public class GetDelegatedResourceServlet extends HttpServlet {

@Autowired private Wallet wallet;
@Autowired
private Wallet wallet;

protected void doGet(HttpServletRequest request, HttpServletResponse response) {
try {
Expand Down Expand Up @@ -48,6 +49,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
try {
String input =
request.getReader().lines().collect(Collectors.joining(System.lineSeparator()));
Util.checkBodySize(input);
DelegatedResourceMessage.Builder build = DelegatedResourceMessage.newBuilder();
JsonFormat.merge(input, build);
DelegatedResourceList reply =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
try {
String input = request.getReader().lines()
.collect(Collectors.joining(System.lineSeparator()));
Util.checkBodySize(input);
JSONObject jsonObject = JSONObject.parseObject(input);
long id = jsonObject.getLong("id");
response.getWriter()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
try {
String input = request.getReader().lines()
.collect(Collectors.joining(System.lineSeparator()));
Util.checkBodySize(input);
PaginatedMessage.Builder build = PaginatedMessage.newBuilder();
JsonFormat.merge(input, build);
AssetIssueList reply = wallet.getAssetIssueList(build.getOffset(), build.getLimit());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
try {
String input = request.getReader().lines()
.collect(Collectors.joining(System.lineSeparator()));
Util.checkBodySize(input);
PaginatedMessage.Builder build = PaginatedMessage.newBuilder();
JsonFormat.merge(input, build);
ExchangeList reply = wallet.getPaginatedExchangeList(build.getOffset(), build.getLimit());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
try {
String input = request.getReader().lines()
.collect(Collectors.joining(System.lineSeparator()));
Util.checkBodySize(input);
PaginatedMessage.Builder build = PaginatedMessage.newBuilder();
JsonFormat.merge(input, build);
ProposalList reply = wallet.getPaginatedProposalList(build.getOffset(), build.getLimit());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
try {
String input = request.getReader().lines()
.collect(Collectors.joining(System.lineSeparator()));
Util.checkBodySize(input);
JSONObject jsonObject = JSONObject.parseObject(input);
long id = jsonObject.getLong("id");
Proposal reply = wallet.getProposalById(ByteString.copyFrom(ByteArray.fromLong(id)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
try {
String input = request.getReader().lines()
.collect(Collectors.joining(System.lineSeparator()));
Util.checkBodySize(input);
Transaction transaction = Util.packTransaction(input);
TransactionApprovedList reply = wallet.getTransactionApprovedList(transaction);
if (reply != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
try {
String input = request.getReader().lines()
.collect(Collectors.joining(System.lineSeparator()));
Util.checkBodySize(input);
BytesMessage.Builder build = BytesMessage.newBuilder();
JsonFormat.merge(input, build);
Transaction reply = wallet.getTransactionById(build.getValue());
Expand Down
Loading