diff --git a/src/test/app/Escrow_test.cpp b/src/test/app/Escrow_test.cpp index 52abf61fc6..49d7fb216d 100644 --- a/src/test/app/Escrow_test.cpp +++ b/src/test/app/Escrow_test.cpp @@ -1888,6 +1888,33 @@ struct Escrow_test : public beast::unit_test::suite ter(temBAD_LIMIT)); } + { + uint32_t const allowance = 10'000; + Env env(*this); + env.fund(XRP(5000), alice, carol); + auto const seq = env.seq(alice); + XRPAmount const createFee = env.current()->fees().base + 1000; + + // Escrow with FinishFunction + Condition + auto escrowCreate = escrow(alice, carol, XRP(1000)); + env(escrowCreate, + finish_function(reqNonexistentField), + condition(cb1), + cancel_time(env.now() + 100s), + fee(createFee)); + env.close(); + env.close(); + + // Rejected as wasm code request nonexistent memo field + XRPAmount const txnFees = env.current()->fees().base * 34 + 1000; + env(finish(alice, alice, seq), + condition(cb1), + fulfillment(fb1), + comp_allowance(allowance), + fee(txnFees), + ter(tecWASM_REJECTED)); + } + Env env(*this); // Run past the flag ledger so that a Fee change vote occurs and diff --git a/src/test/app/wasm_fixtures/fixtures.cpp b/src/test/app/wasm_fixtures/fixtures.cpp index 7dbc4fdc2f..10330f93bf 100644 --- a/src/test/app/wasm_fixtures/fixtures.cpp +++ b/src/test/app/wasm_fixtures/fixtures.cpp @@ -11683,3 +11683,29 @@ extern std::string const hostFunctions2Hex = "65745f6665617475726573042b0f6d757461626c652d676c6f62616c732b" "087369676e2d6578742b0f7265666572656e63652d74797065732b0a6d75" "6c746976616c7565"; + +extern std::string const reqNonexistentField = + "0061736d0100000001120360027f7f0060047f7f7f7f017f6000017f02200108686f73745f" + "6c6962136765745f74785f6e65737465645f6669656c640001030403020000050301001006" + "19037f01418080c0000b7f00418080c0000b7f00418080c0000b072e04066d656d6f727902" + "000666696e69736800010a5f5f646174615f656e6403010b5f5f686561705f626173650302" + "0abc04035f01037f230041d0206b220124002001410c6a220241802010032001418c206a22" + "0041c400100320004189803c10022000410010022000418a803810022000418d801c100220" + "0020012802cc2020024180201000200141d0206a240041004a0b6101027f230041106b2103" + "024020002802402202413d6b41bf7f490d002003200136020c4100210103402002413f4b0d" + "01200020026a2003410c6a20016a2d00003a00002000200028024041016a22023602402001" + "41016a22014104470d000b0b0bf70201037f200141104f044002402000410020006b410371" + "22036a220220004d0d0020030440200321040340200041003a0000200041016a2100200441" + "016b22040d000b0b200341016b4107490d000340200041003a0000200041076a41003a0000" + "200041066a41003a0000200041056a41003a0000200041046a41003a0000200041036a4100" + "3a0000200041026a41003a0000200041016a41003a0000200041086a22002002470d000b0b" + "2002200120036b2201417c716a220020024b0440034020024100360200200241046a220220" + "00490d000b0b200141037121010b02402000200020016a22034f0d00200141077122020440" + "0340200041003a0000200041016a2100200241016b22020d000b0b200141016b4107490d00" + "0340200041003a0000200041076a41003a0000200041066a41003a0000200041056a41003a" + "0000200041046a41003a0000200041036a41003a0000200041026a41003a0000200041016a" + "41003a0000200041086a22002003470d000b0b0b004d0970726f64756365727302086c616e" + "6775616765010452757374000c70726f6365737365642d6279010572757374631d312e3835" + "2e31202834656231363132353020323032352d30332d31352900490f7461726765745f6665" + "617475726573042b0f6d757461626c652d676c6f62616c732b087369676e2d6578742b0f72" + "65666572656e63652d74797065732b0a6d756c746976616c7565"; diff --git a/src/test/app/wasm_fixtures/fixtures.h b/src/test/app/wasm_fixtures/fixtures.h index acf2de906e..308c2668bd 100644 --- a/src/test/app/wasm_fixtures/fixtures.h +++ b/src/test/app/wasm_fixtures/fixtures.h @@ -54,3 +54,5 @@ extern std::string const sp1_wasm; extern std::string const xrplStdExampleHex; extern std::string const hostFunctions2Hex; + +extern std::string const reqNonexistentField; diff --git a/src/xrpld/app/misc/WasmHostFuncImpl.cpp b/src/xrpld/app/misc/WasmHostFuncImpl.cpp index 1da8c38a2d..9e2ec00d18 100644 --- a/src/xrpld/app/misc/WasmHostFuncImpl.cpp +++ b/src/xrpld/app/misc/WasmHostFuncImpl.cpp @@ -74,39 +74,50 @@ Bytes getAnyFieldData(STBase const& obj) { // auto const& fname = obj.getFName(); - if (STI_ACCOUNT == obj.getSType()) + auto const stype = obj.getSType(); + switch (stype) { - auto const& super(static_cast(obj)); - auto const& data = super.value(); - return {data.begin(), data.end()}; - } - else if (STI_AMOUNT == obj.getSType()) - { - auto const& super(static_cast(obj)); - int64_t const data = super.xrp().drops(); - auto const* b = reinterpret_cast(&data); - auto const* e = reinterpret_cast(&data + 1); - return {b, e}; - } - else if (STI_VL == obj.getSType()) - { - auto const& super(static_cast(obj)); - auto const& data = super.value(); - return {data.begin(), data.end()}; - } - else if (STI_UINT256 == obj.getSType()) - { - auto const& super(static_cast const&>(obj)); - auto const& data = super.value(); - return {data.begin(), data.end()}; - } - else if (STI_UINT32 == obj.getSType()) - { - auto const& super(static_cast const&>(obj)); - std::uint32_t const data = super.value(); - auto const* b = reinterpret_cast(&data); - auto const* e = reinterpret_cast(&data + 1); - return {b, e}; + case STI_UNKNOWN: + case STI_NOTPRESENT: + return {}; + break; + case STI_ACCOUNT: { + auto const& super(static_cast(obj)); + auto const& data = super.value(); + return {data.begin(), data.end()}; + } + break; + case STI_AMOUNT: { + auto const& super(static_cast(obj)); + int64_t const data = super.xrp().drops(); + auto const* b = reinterpret_cast(&data); + auto const* e = reinterpret_cast(&data + 1); + return {b, e}; + } + break; + case STI_VL: { + auto const& super(static_cast(obj)); + auto const& data = super.value(); + return {data.begin(), data.end()}; + } + break; + case STI_UINT256: { + auto const& super(static_cast const&>(obj)); + auto const& data = super.value(); + return {data.begin(), data.end()}; + } + break; + case STI_UINT32: { + auto const& super( + static_cast const&>(obj)); + std::uint32_t const data = super.value(); + auto const* b = reinterpret_cast(&data); + auto const* e = reinterpret_cast(&data + 1); + return {b, e}; + } + break; + default: + break; } Serializer msg;