From eee44b74691d31c382a9eab7fd5e10a4ee3bac08 Mon Sep 17 00:00:00 2001 From: Fabian Boehm Date: Sat, 30 Nov 2024 15:40:48 +0100 Subject: [PATCH] ulimit: Fix multiplication overflow --- src/builtins/ulimit.rs | 11 ++++++++++- tests/checks/ulimit.fish | 9 +++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/builtins/ulimit.rs b/src/builtins/ulimit.rs index c467ebeae..a1d322523 100644 --- a/src/builtins/ulimit.rs +++ b/src/builtins/ulimit.rs @@ -305,7 +305,16 @@ pub fn ulimit(parser: &Parser, streams: &mut IoStreams, args: &mut [&wstr]) -> O None => return STATUS_CMD_ERROR, } } else if let Ok(limit) = fish_wcstol(w.argv[w.wopt_index]) { - limit as rlim_t * get_multiplier(what) + let Some(x) = get_multiplier(what).checked_mul(limit as rlim_t) else { + streams.err.append(wgettext_fmt!( + "%ls: Invalid limit '%ls'\n", + cmd, + w.argv[w.wopt_index] + )); + builtin_print_error_trailer(parser, streams.err, cmd); + return STATUS_INVALID_ARGS; + }; + x } else { streams.err.append(wgettext_fmt!( "%ls: Invalid limit '%ls'\n", diff --git a/tests/checks/ulimit.fish b/tests/checks/ulimit.fish index ad3b2f7a2..4f5ae7ab5 100644 --- a/tests/checks/ulimit.fish +++ b/tests/checks/ulimit.fish @@ -5,3 +5,12 @@ ulimit --core-size ulimit --core-size 0 ulimit --core-size #CHECK: 0 + +ulimit 4352353252352352334 +#CHECKERR: ulimit: Invalid limit '4352353252352352334' +#CHECKERR: +#CHECKERR: checks/ulimit.fish (line {{\d+}}): +#CHECKERR: ulimit 4352353252352352334 +#CHECKERR: ^ +#CHECKERR: (Type 'help ulimit' for related documentation) +