Polish PasswordEncoderUtils do not leak length
Fix possible / 0 if expected is empty String. Issue gh-255
This commit is contained in:
parent
d3685d89c5
commit
e62596f36d
|
@ -38,7 +38,7 @@ class PasswordEncoderUtils {
|
|||
|
||||
int result = expectedLength == actualLength ? 0 : 1;
|
||||
for (int i = 0; i < actualLength; i++) {
|
||||
byte expectedByte = expectedBytes == null ? 0 : expectedBytes[i % expectedLength];
|
||||
byte expectedByte = expectedLength <= 0 ? 0 : expectedBytes[i % expectedLength];
|
||||
byte actualByte = actualBytes[i % actualLength];
|
||||
result |= expectedByte ^ actualByte;
|
||||
}
|
||||
|
|
|
@ -47,6 +47,12 @@ public class PasswordEncoderUtilsTests {
|
|||
assertThat(PasswordEncoderUtils.equals("", null)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equalsWhenNotEmptyAndEmptyThenFalse() {
|
||||
assertThat(PasswordEncoderUtils.equals("abc", "")).isFalse();
|
||||
assertThat(PasswordEncoderUtils.equals("", "abc")).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equalsWhenEmtpyAndEmptyThenTrue() {
|
||||
assertThat(PasswordEncoderUtils.equals("", "")).isTrue();
|
||||
|
|
Loading…
Reference in New Issue