mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-14 05:53:59 +00:00
Fix crash when sprintf width argument overflows u64
Given "printf %18446744073709551616s", we parse the number only in the printf crate, which tells us that we overflowed somwhere (but not where exactly).
This commit is contained in:
parent
9fddc3e887
commit
2543b8198d
2 changed files with 11 additions and 1 deletions
|
@ -239,6 +239,13 @@ impl<'a, 'b> builtin_printf_state_t<'a, 'b> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn handle_sprintf_error(&mut self, err: fish_printf::Error) {
|
||||||
|
match err {
|
||||||
|
fish_printf::Error::Overflow => self.fatal_error(wgettext!("Number out of range")),
|
||||||
|
_ => panic!("unhandled error: {err:?}"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Evaluate a printf conversion specification. SPEC is the start of the directive, and CONVERSION
|
/// Evaluate a printf conversion specification. SPEC is the start of the directive, and CONVERSION
|
||||||
/// specifies the type of conversion. SPEC does not include any length modifier or the
|
/// specifies the type of conversion. SPEC does not include any length modifier or the
|
||||||
/// conversion specifier itself. FIELD_WIDTH and PRECISION are the field width and
|
/// conversion specifier itself. FIELD_WIDTH and PRECISION are the field width and
|
||||||
|
@ -268,7 +275,7 @@ impl<'a, 'b> builtin_printf_state_t<'a, 'b> {
|
||||||
$fmt,
|
$fmt,
|
||||||
&self.locale,
|
&self.locale,
|
||||||
&mut [$($arg.to_arg()),*]
|
&mut [$($arg.to_arg()),*]
|
||||||
).expect("sprintf failed");
|
).err().map(|err| self.handle_sprintf_error(err));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -151,3 +151,6 @@ echo
|
||||||
# This is how mc likes to encode the directory we should cd to.
|
# This is how mc likes to encode the directory we should cd to.
|
||||||
printf '%b\n' '\0057foo\0057bar\0057'
|
printf '%b\n' '\0057foo\0057bar\0057'
|
||||||
# CHECK: /foo/bar/
|
# CHECK: /foo/bar/
|
||||||
|
|
||||||
|
printf %18446744073709551616s
|
||||||
|
# CHECKERR: Number out of range
|
||||||
|
|
Loading…
Reference in a new issue