wallet: handle null tx notes consistently across backends
What changed, and why it matters
This commit fixes two consistency problems when saving notes attached to Monero transactions. First, the Java RPC wallet now turns Java `null` notes into empty strings before sending them to the wallet RPC, because the RPC server rejects JSON null values while the local full wallet treats null as 'clear the note.' Second, the native JNI bridge now only releases the string memory when a string actually exists, avoiding a possible crash when a null note is passed from Java to the native C++ wallet. Tests were added to confirm that null clears a note and that the caller's list is not modified.
Treat as a low-severity reliability/defensive fix. Reviewers should verify that no other JNI string-release sites pass null jstring values and that the RPC mapping does not inadvertently change legitimate empty-string semantics elsewhere. No urgent security response is indicated, but the fix should be included in the next release.
Security signals we found
Null-pointer handling gap between RPC and full wallet backends
Potential JVM crash in JNI string release path for null transaction notes
Behavioral normalization of null values to empty strings to match backend expectations
Addition of regression tests for null note handling and sync-callback note access
Evidence from the diff
The patch normalizes null transaction notes across the RPC and JNI/full wallet backends. In MoneroWalletRpc.setTxNotes(), null entries are mapped to “” so the underlying set_tx_notes JSON-RPC call does not receive a rejected null. In monero_jni_bridge.cpp, env->ReleaseStringUTFChars(jstr, _str) is now guarded by if (_str) because passing a null jstr/_str to ReleaseStringUTFChars is undefined and can trigger a JVM crash. Tests cover single-note clearing, mixed null/empty/”null” batches, and reading/writing notes inside a wallet sync callback.
Changed components
src/main/java/monero/wallet/MoneroWalletRpc.javasrc/main/cpp/monero_jni_bridge.cppsrc/test/java/TestMoneroWalletCommon.javasrc/test/java/TestMoneroWalletFull.javaInspect captured patch +32 / −3
### src/main/cpp/monero_jni_bridge.cpp
@@ -1789,7 +1789,7 @@ JNIEXPORT void JNICALL Java_monero_wallet_MoneroWalletFull_setTxNotesJni(JNIEnv*
jstring jstr = (jstring) env->GetObjectArrayElement(jtx_notes, idx);
const char* _str = jstr ? env->GetStringUTFChars(jstr, NULL) : nullptr;
string str = string(_str ? _str : "");
- env->ReleaseStringUTFChars(jstr, _str);
+ if (_str) env->ReleaseStringUTFChars(jstr, _str);
env->DeleteLocalRef(jstr);
notes.push_back(str);
}
### src/main/java/monero/wallet/MoneroWalletRpc.java
@@ -1668,9 +1668,11 @@ public List<String> getTxNotes(List<String> txHashes) {
@Override
public void setTxNotes(List<String> txHashes, List<String> notes) {
+ List<String> rpcNotes = new ArrayList<String>();
+ for (String note : notes) rpcNotes.add(note == null ? "" : note); // wallet rpc rejects json null; the full wallet clears the note
Map<String, Object> params = new HashMap<String, Object>();
params.put("txids", txHashes);
- params.put("notes", notes);
+ params.put("notes", rpcNotes);
rpc.sendJsonRequest("set_tx_notes", params);
}
### src/test/java/TestMoneroWalletCommon.java
@@ -2376,6 +2376,10 @@ public void testSetTxNote() {
for (int i = 0; i < txs.size(); i++) {
assertEquals(wallet.getTxNote(txs.get(i).getHash()), uuid + i);
}
+
+ // null clears the note
+ wallet.setTxNote(txs.get(0).getHash(), null);
+ assertEquals("", wallet.getTxNote(txs.get(0).getHash()));
}
// Can get and set multiple transaction notes
@@ -2390,7 +2394,7 @@ public void testSetTxNotes() {
assertTrue(txs.size() >= 3, "Test requires 3 or more wallet transactions; run send tests");
List<String> txHashes = new ArrayList<String>();
List<String> txNotes = new ArrayList<String>();
- for (int i = 0; i < txHashes.size(); i++) {
+ for (int i = 0; i < txs.size(); i++) {
txHashes.add(txs.get(i).getHash());
txNotes.add(uuid + i);
}
@@ -2402,6 +2406,16 @@ public void testSetTxNotes() {
assertEquals(uuid + i, txNotes.get(i));
}
+ // clear notes in a mixed batch without changing the caller's list
+ txNotes.set(0, null);
+ txNotes.set(1, "");
+ txNotes.set(2, "null");
+ List<String> expectedNotes = new ArrayList<String>(txNotes);
+ expectedNotes.set(0, "");
+ wallet.setTxNotes(txHashes, Collections.unmodifiableList(txNotes));
+ assertNull(txNotes.get(0));
+ assertEquals(expectedNotes, wallet.getTxNotes(txHashes));
+
// TODO: test that get transaction has note
}
### src/test/java/TestMoneroWalletFull.java
@@ -1397,6 +1397,7 @@ private class WalletSyncTester extends SyncProgressTester {
private BigInteger incomingTotal;
private BigInteger outgoingTotal;
private Boolean onNewBlockAfterDone;
+ private boolean testedTxNote;
private BigInteger prevBalance;
private BigInteger prevUnlockedBalance;
@@ -1446,6 +1447,17 @@ public void onOutputReceived(MoneroOutputWallet output) {
assertNull(output.getTx().getInputs());
assertEquals(1, output.getTx().getOutputs().size());
assertTrue(output.getTx().getOutputs().get(0) == output);
+
+ // can read and write tx notes from a sync callback
+ String txHash = output.getTx().getHash();
+ String previousNote = wallet.getTxNote(txHash);
+ try {
+ wallet.setTxNote(txHash, "sync callback");
+ assertEquals("sync callback", wallet.getTxNote(txHash));
+ testedTxNote = true;
+ } finally {
+ wallet.setTxNote(txHash, previousNote);
+ }
// extra is not sent over the jni bridge
assertNull(output.getTx().getExtra());
@@ -1487,6 +1499,7 @@ public void onDone(long chainHeight) {
assertNotNull(walletTesterPrevHeight);
assertNotNull(prevOutputReceived);
assertNotNull(prevOutputSpent);
+ assertTrue(testedTxNote);
BigInteger expectedBalance = incomingTotal.subtract(outgoingTotal);
// output notifications do not include pool fees or outgoing amountWhy this scored 27/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.