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

Panic when reading process comm values with invalid UTF-8 characters #39

Closed
edigaryev opened this issue Aug 22, 2019 · 5 comments
Closed

Comments

@edigaryev
Copy link
Contributor

comm values can contain pretty much any characters, which breaks /proc/[pid]/stat parsing:

$ echo -e "\xFF" > /proc/$$/comm
$ cargo run --example dump -- $$
    Finished dev [unoptimized + debuginfo] target(s) in 0.01s
     Running `target/debug/examples/dump 15815`
Info for pid=15815
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Incomplete(Some("/proc/15815/stat"))', src/libcore/result.rs:1084:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
@eminence
Copy link
Owner

Thanks for the report. What would you recommend here? I suppose these fields could be converted from String to Vec<u8>, but I'm hesitant to stop using the String type, since it's very convenient. Would using String::from_utf8_lossy() be acceptable for your use-case?

@edigaryev
Copy link
Contributor Author

Would using String::from_utf8_lossy() be acceptable for your use-case?

That'd work for me. At least it won't panic, which is kinda surprising when using a library, but I guess this way more bugs can be unveiled because people will actually report their panic()'s.

@eminence
Copy link
Owner

eminence commented Sep 4, 2019

You're right that a library that panics is a little unusual. It was a deliberate choice on my part as a way to encourage bug reports. I don't know if it was the right choice, though. It has proven useful, at the expense of annoying users. Now that I think about it some more, maybe I could introduce a feature that would suppress panics (and turn them into Result::Err(..) instead).

@idanski
Copy link
Contributor

idanski commented Oct 6, 2019

@eminence I use your library in a project, and I'm also concerned about it panicking in production (not so much annoy but a production deal-breaker).

Maybe having an error type for unexpected data/format (with backtrace) - which your users can report - will be a good middle ground?

I will gladly help turn the package panic free if you decide to go for it.

@eminence
Copy link
Owner

eminence commented Oct 7, 2019

Thanks for the feedback. I've opened a new issue to discuss the general topic of removing as many panics as possible.

I also realized that I've failed to address the original issue brought up by @edigaryev -- I'll plan on doing that work this week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants