-
Notifications
You must be signed in to change notification settings - Fork 31
Closed
Description
There's at least 1 instance of this pitfall (rust-lang/rust-clippy#16213):
posixutils-rs/display/printf.rs
Line 843 in eba0585
| match i64::from_str_radix(hex, 16) { |
The previous lines seem to imply it's safe:
posixutils-rs/display/printf.rs
Lines 828 to 842 in eba0585
| // Handle sign | |
| let (is_negative, num_str) = if let Some(rest) = arg_str.strip_prefix('-') { | |
| (true, rest) | |
| } else if let Some(rest) = arg_str.strip_prefix('+') { | |
| (false, rest) | |
| } else { | |
| (false, arg_str) | |
| }; | |
| // Parse the number | |
| let (value, fully_consumed) = if let Some(hex) = num_str | |
| .strip_prefix("0x") | |
| .or_else(|| num_str.strip_prefix("0X")) | |
| { | |
| // Hexadecimal |
But it would still parse stuff like "+0x+55" as 0x55.
I suspect there's many other places where from_str_radix is used wrong:
Output of git grep -Fwl from_str_radix:
calc/bc_util/number.rs
cc/parse/parser.rs
cc/token/lexer.rs
cc/token/preprocess.rs
dev/lex/lexfile.rs
dev/yacc/lexer.rs
display/printf.rs
file/find.rs
file/magic.rs
file/od.rs
i18n/iconv.rs
man/man_util/formatter.rs
pax/formats/cpio.rs
pax/formats/pax.rs
pax/formats/ustar.rs
pax/main.rs
pax/modes/append.rs
pax/multivolume.rs
plib/src/modestr.rs
process/batch.rs
process/fuser.rs
sh/builtin/umask.rs
sh/wordexp/arithmetic.rs
sys/ipcrm.rs
text/tr.rs
xform/uudecode.rs
Copilot
Metadata
Metadata
Assignees
Labels
No labels