Skip to content

Commit

Permalink
Fix the flag processing of NFTokenModify (#5246)
Browse files Browse the repository at this point in the history
Adds checks for invalid flags.
  • Loading branch information
tequdev authored Jan 16, 2025
1 parent ff8b9aa commit 9e4a7d5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion include/xrpl/protocol/TxFlags.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ constexpr std::uint32_t const tfNFTokenCreateOfferMask =
~(tfUniversal | tfSellNFToken);

// NFTokenCancelOffer flags:
constexpr std::uint32_t const tfNFTokenCancelOfferMask = ~(tfUniversal);
constexpr std::uint32_t const tfNFTokenCancelOfferMask = ~tfUniversal;

// NFTokenAcceptOffer flags:
constexpr std::uint32_t const tfNFTokenAcceptOfferMask = ~tfUniversal;
Expand Down
20 changes: 19 additions & 1 deletion src/test/app/NFToken_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7793,12 +7793,17 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite
env(token::mint(issuer, 0u), txflags(tfMutable));
env.close();

// Set a negative fee. Exercises invalid preflight1.
// Set a negative fee. Exercises invalid preflight1.
env(token::modify(issuer, nftId),
fee(STAmount(10ull, true)),
ter(temBAD_FEE));
env.close();

// Invalid Flags
env(token::modify(issuer, nftId),
txflags(0x00000001),
ter(temINVALID_FLAG));

// Invalid Owner
env(token::modify(issuer, nftId),
token::owner(issuer),
Expand Down Expand Up @@ -7868,6 +7873,19 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite
env.fund(XRP(10000), issuer, alice, bob);
env.close();

// modify with tfFullyCanonicalSig should success
uint256 const nftId{token::getNextID(env, issuer, 0u, tfMutable)};
env(token::mint(issuer, 0u), txflags(tfMutable), token::uri("uri"));
env.close();

env(token::modify(issuer, nftId), txflags(tfFullyCanonicalSig));
env.close();
}
{
Env env{*this, features};
env.fund(XRP(10000), issuer, alice, bob);
env.close();

// lambda that returns the JSON form of NFTokens held by acct
auto accountNFTs = [&env](Account const& acct) {
Json::Value params;
Expand Down
3 changes: 3 additions & 0 deletions src/xrpld/app/tx/detail/NFTokenModify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ NFTokenModify::preflight(PreflightContext const& ctx)
if (NotTEC const ret = preflight1(ctx); !isTesSuccess(ret))
return ret;

if (ctx.tx.getFlags() & tfUniversalMask)
return temINVALID_FLAG;

if (auto owner = ctx.tx[~sfOwner]; owner == ctx.tx[sfAccount])
return temMALFORMED;

Expand Down

0 comments on commit 9e4a7d5

Please sign in to comment.