wallet: handle null tx notes consistently across backends
What changed, and why it matters
This commit fixes two consistency bugs in how transaction notes are saved in a Monero wallet library. First, when using the local JNI wallet backend, passing a null note could cause a crash because the code tried to release a non-existent Java string. Second, when using the remote RPC wallet backend, null notes were sent as JSON null, which the RPC server rejects, while the local backend treats null as 'clear the note.' The patch makes both backends treat null notes as empty strings, and adds tests to confirm the behavior. It is a reliability fix rather than an active security vulnerability.
Treat as a normal bug-fix commit. Reviewers should verify that the null-guard covers all JNI string release paths and that the RPC null-to-empty conversion does not unintentionally alter other wallet RPC methods. No urgent security response is indicated.
Security signals we found
Null-pointer/crash hardening in JNI string handling
Input normalization prevents RPC rejection of null values
Behavioral consistency between wallet backends
No evidence of memory corruption, privilege escalation, or cryptographic weakness
Evidence from the diff
The diff modifies MoneroWalletFull’s JNI bridge and MoneroWalletRpc’s setTxNotes. In monero_jni_bridge.cpp, ReleaseStringUTFChars is now guarded by if (_str), preventing a JNI crash when a null Java string is present in the notes array. In MoneroWalletRpc.java, null entries in the notes list are converted to empty strings before being sent via set_tx_notes, aligning RPC behavior with the full wallet’s ‘null clears note’ semantics. Tests are updated/added to verify null clears notes, mixed null/empty/’null’ batches work without mutating the caller’s list, and tx notes can be read/written from a sync callback.
Changed components
src/main/cpp/monero_jni_bridge.cpp (JNI bridge for MoneroWalletFull)src/main/java/monero/wallet/MoneroWalletRpc.java (RPC wallet implementation)src/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 24/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.