Fix len miscalculation in grimoire string replace (#794)

* Fix len miscalculation in grimoire string replace

* ok Rust i was writing JS these days

Co-authored-by: Andrea Fioraldi <andrea.fioraldi@trellix.com>
This commit is contained in:
Andrea Fioraldi 2022-09-21 14:19:54 +02:00 committed by GitHub
parent f6bd99fc4d
commit c0bb1bc1e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -294,7 +294,8 @@ where
if bytes.len() < token_1.len() { if bytes.len() < token_1.len() {
continue; continue;
} }
for i in 0..(bytes.len() - token_1.len()) { let mut i = 0;
while i < bytes.len() - token_1.len() {
if bytes[i..].starts_with(token_1) { if bytes[i..].starts_with(token_1) {
bytes.splice(i..(i + token_1.len()), token_2.clone()); bytes.splice(i..(i + token_1.len()), token_2.clone());
@ -303,6 +304,7 @@ where
break 'first; break 'first;
} }
} }
i += 1;
} }
} }
} }
@ -312,7 +314,8 @@ where
if bytes.len() < token_1.len() { if bytes.len() < token_1.len() {
continue; continue;
} }
for i in 0..(bytes.len() - token_1.len()) { let mut i = 0;
while i < bytes.len() - token_1.len() {
if bytes[i..].starts_with(token_1) { if bytes[i..].starts_with(token_1) {
bytes.splice(i..(i + token_1.len()), token_2.clone()); bytes.splice(i..(i + token_1.len()), token_2.clone());
@ -321,6 +324,7 @@ where
break 'second; break 'second;
} }
} }
i += 1;
} }
} }
} }