Skip to content

Unwrapping on an Err() causes a program to panic #263

Open
@ve1nard

Description

@ve1nard

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

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions