Skip to content

Commit

Permalink
Add the ability to clear internal buffers for security (fixes #910)
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Dec 21, 2023
1 parent fb35df1 commit ada11ff
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions reader/src/main/java/org/jline/reader/Buffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,9 @@ public interface Buffer {
Buffer copy();

void copyFrom(Buffer buffer);

/**
* Clear any internal buffer.
*/
void zeroOut();
}
5 changes: 5 additions & 0 deletions reader/src/main/java/org/jline/reader/LineReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -777,4 +777,9 @@ String readLine(String prompt, String rightPrompt, MaskingCallback maskingCallba
void setAutosuggestion(SuggestionType type);

SuggestionType getAutosuggestion();

/**
* Clear any internal buffers.
*/
void zeroOut();
}
6 changes: 6 additions & 0 deletions reader/src/main/java/org/jline/reader/impl/BufferImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/
package org.jline.reader.impl;

import java.util.Arrays;
import java.util.Objects;

import org.jline.reader.Buffer;
Expand Down Expand Up @@ -367,4 +368,9 @@ private void moveGapToCursor() {
g1 += l;
}
}

@Override
public void zeroOut() {
Arrays.fill(buffer, 0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6396,4 +6396,10 @@ private void rebind(KeyMap<Binding> keyMap, String operation, String prevBinding
keyMap.bind(ref, Character.toString(newBinding));
}
}

@Override
public void zeroOut() {
buf.zeroOut();
parsedLine = null;
}
}

0 comments on commit ada11ff

Please sign in to comment.