Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ve1nard opened this issue Jun 13, 2024 · 1 comment
Open

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

ve1nard opened this issue Jun 13, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@ve1nard
Copy link
Contributor

ve1nard commented Jun 13, 2024

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

@Anway-Agte
Copy link
Contributor

Should a match condition be written to handle the Err() value before unwrapping it?

@rupeshkoushik07 rupeshkoushik07 mentioned this issue Sep 13, 2024
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants