Skip to content

Commit

Permalink
TxValidator: Fix fee check crash on invalid JSON response
Browse files Browse the repository at this point in the history
The initialSanityChecks method only checks whether the JSON response is
null (HTTP request failed) or the response is empty (HTTP 200) before
parsing the JSON response. A invalid JSON response would throw a
JsonSyntaxException exception which the callers are not catching.
  • Loading branch information
alvasw committed Jan 9, 2024
1 parent be857cb commit 9f760ed
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
14 changes: 10 additions & 4 deletions core/src/main/java/bisq/core/provider/mempool/TxValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,9 @@ public TxValidator(DaoStateService daoStateService, String txId, FilterManager f

public TxValidator parseJsonValidateMakerFeeTx(String jsonTxt, List<String> btcFeeReceivers) {
this.jsonTxt = jsonTxt;
FeeValidationStatus status = initialSanityChecks(txId, jsonTxt);
FeeValidationStatus status;
try {
status = initialSanityChecks(txId, jsonTxt);
if (status.pass()) {
status = checkFeeAddressBTC(jsonTxt, btcFeeReceivers);
if (status.pass()) {
Expand Down Expand Up @@ -131,8 +132,9 @@ public TxValidator validateBsqFeeTx(boolean isMaker) {

public TxValidator parseJsonValidateTakerFeeTx(String jsonTxt, List<String> btcFeeReceivers) {
this.jsonTxt = jsonTxt;
FeeValidationStatus status = initialSanityChecks(txId, jsonTxt);
FeeValidationStatus status;
try {
status = initialSanityChecks(txId, jsonTxt);
if (status.pass()) {
status = checkFeeAddressBTC(jsonTxt, btcFeeReceivers);
if (status.pass()) {
Expand All @@ -148,10 +150,14 @@ public TxValidator parseJsonValidateTakerFeeTx(String jsonTxt, List<String> btcF
}

public long parseJsonValidateTx() {
if (!initialSanityChecks(txId, jsonTxt).pass()) {
try {
if (!initialSanityChecks(txId, jsonTxt).pass()) {
return -1;
}
return getTxConfirms(jsonTxt, chainHeight);
} catch (JsonSyntaxException e) {
return -1;
}
return getTxConfirms(jsonTxt, chainHeight);
}

///////////////////////////////////////////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ void nullAndEmptyMempoolResponse(String jsonText) {
assertThat(status, is(equalTo(FeeValidationStatus.NACK_JSON_ERROR)));
}

@Test
void invalidJsonResponse() {
String invalidJson = "in\"valid'json',";
TxValidator txValidator1 = txValidator.parseJsonValidateMakerFeeTx(invalidJson, FEE_RECEIVER_ADDRESSES);

FeeValidationStatus status = txValidator1.getStatus();
assertThat(status, is(equalTo(FeeValidationStatus.NACK_JSON_ERROR)));
}

@ParameterizedTest
@ValueSource(strings = {"status", "txid"})
void mempoolResponseWithMissingField(String missingField) throws IOException {
Expand Down

0 comments on commit 9f760ed

Please sign in to comment.