Description
If a file descriptor provided to get_filedescriptor() is out of the allowed range: 0 to 1024(excluded), the method returns Err(), and unwrapping on the returned Err() value later on causes a program to panic.
Cases:
Any syscall, like fcntl or ioctl, that involves file descriptors needs to access a file descriptor table using get_filedescriptor(). The pattern is always the same and involves the following line:
let checkedfd = self.get_filedescriptor(fd).unwrap();
Why this behavior?
By definition, an unwrap method for the Result type should panic when provided with an Err() result.
How is this tested?
Unit tests calling fcntl syscall with out-of-range file descriptors, e.g. negative values or values greater than or equal to 1024, failed with called Result::unwrap() on an Err.
References
https://web.mit.edu/rust-lang_v1.25/arch/amd64_ubuntu1404/share/doc/rust/html/book/first-edition/error-handling.html#unwrapping-explained
Description
If a file descriptor provided to
get_filedescriptor()is out of the allowed range: 0 to 1024(excluded), the method returnsErr(), and unwrapping on the returnedErr()value later on causes a program to panic.Cases:
Any syscall, like
fcntlorioctl, that involves file descriptors needs to access a file descriptor table usingget_filedescriptor(). The pattern is always the same and involves the following line:let checkedfd = self.get_filedescriptor(fd).unwrap();Why this behavior?
By definition, an
unwrapmethod for theResulttype should panic when provided with anErr()result.How is this tested?
Unit tests calling
fcntlsyscall with out-of-range file descriptors, e.g. negative values or values greater than or equal to 1024, failed with called Result::unwrap() on an Err.References
https://web.mit.edu/rust-lang_v1.25/arch/amd64_ubuntu1404/share/doc/rust/html/book/first-edition/error-handling.html#unwrapping-explained