mirror of
https://github.com/Blah-IM/blahrs.git
synced 2025-05-02 01:01:09 +00:00
fix(webapi/register): fix shift overflow
This would make challenge always fail if difficulty is a multiple of 8.
This commit is contained in:
parent
5afe6af11a
commit
ec7f428519
1 changed files with 2 additions and 1 deletions
|
@ -195,7 +195,8 @@ pub async fn user_register(
|
||||||
let hash = &hash[..];
|
let hash = &hash[..];
|
||||||
// `difficulty` is u8 so it must be < 256
|
// `difficulty` is u8 so it must be < 256
|
||||||
let (bytes, bits) = (expect_bits as usize / 8, expect_bits as usize % 8);
|
let (bytes, bits) = (expect_bits as usize / 8, expect_bits as usize % 8);
|
||||||
let ok = hash[..bytes].iter().all(|&b| b == 0) && hash[bytes] >> (8 - bits) == 0;
|
// NB. Shift by 8 would overflow and wrap around for u8. Convert it to u32 first.
|
||||||
|
let ok = hash[..bytes].iter().all(|&b| b == 0) && (hash[bytes] as u32) >> (8 - bits) == 0;
|
||||||
if !ok {
|
if !ok {
|
||||||
return Err(error_response!(
|
return Err(error_response!(
|
||||||
StatusCode::BAD_REQUEST,
|
StatusCode::BAD_REQUEST,
|
||||||
|
|
Loading…
Add table
Reference in a new issue