Description
There is a bug in salt generation when counter is set to 0. It breaks compatibility with the official LessPass implementation.
For any counter >= 1, the generated passwords match perfectly. However, for counter = 0, the generated passwords diverge.
Steps to Reproduce
With counter = 0 (Bug):
$ #lesspass "site" "login" "password" -C 0
pkwuO9<-W">g,Zag
$ lesspass-rs "site" "login" "password" -c 0
7q~o>vDo6n(Rf+"g
With counter >= 1 (Works correctly):
$ lesspass "site" "login" "password" -C 1
|KTnP2D^64'`q]Er
$ lesspass-rs "site" "login" "password" -c 1
|KTnP2D^64'`q]Er
$ lesspass "site" "login" "password" -C 2
b/f@D|kl2Rs:9k\^
$ lesspass-rs "site" "login" "password" -c 2
b/f@D|kl2Rs:9k\^
Root Cause
The issue is located in the generate_salt_to_uninit function (line 138). When counter is 0, the while counter != 0 loop condition is immediately false, so the loop never executes. As a result, it returns an empty buffer instead of "0".
let mut counter_buf = [MaybeUninit::uninit(); 8];
let counter = {
let mut counter = counter as usize;
let mut i = counter_buf.len();
// This works for counter >= 1, but fails for counter = 0
while counter != 0 {
counter_buf[i - 1].write(b"0123456789abcdef"[counter & 0xf]);
counter >>= 4;
i -= 1;
}
&counter_buf[i..] // Returns an empty slice &[] when counter is 0
};
Description
There is a bug in salt generation when
counteris set to0. It breaks compatibility with the official LessPass implementation.For any
counter >= 1, the generated passwords match perfectly. However, forcounter = 0, the generated passwords diverge.Steps to Reproduce
With counter = 0 (Bug):
With counter >= 1 (Works correctly):
Root Cause
The issue is located in the
generate_salt_to_uninitfunction (line 138). Whencounteris0, thewhile counter != 0loop condition is immediately false, so the loop never executes. As a result, it returns an empty buffer instead of"0".