From 9af76ef0753ab244cfd5eee3a090b71331e29c81 Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Fri, 24 Apr 2020 09:58:15 +0200 Subject: [PATCH] xattr: use checked_mul to increase size Signed-off-by: Wolfgang Bumiller --- src/tools/xattr.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/tools/xattr.rs b/src/tools/xattr.rs index f5e2ed75..dda5fc95 100644 --- a/src/tools/xattr.rs +++ b/src/tools/xattr.rs @@ -22,8 +22,7 @@ pub fn flistxattr(fd: RawFd) -> Result, nix::errno::Errno> { match err { Errno::ERANGE => { // Buffer was not big enough to fit the list, retry with double the size - if size * 2 < size { return Err(Errno::ENOMEM); } - size *= 2; + size = size.checked_mul(2).ok_or(Errno::ENOMEM)?; }, _ => return Err(err), } @@ -49,8 +48,7 @@ pub fn fgetxattr(fd: RawFd, name: &[u8]) -> Result, nix::errno::Errno> { match err { Errno::ERANGE => { // Buffer was not big enough to fit the value, retry with double the size - if size * 2 < size { return Err(Errno::ENOMEM); } - size *= 2; + size = size.checked_mul(2).ok_or(Errno::ENOMEM)?; }, _ => return Err(err), }