Open
Description
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.