LibAFL icon indicating copy to clipboard operation
LibAFL copied to clipboard

Use `std::io::Error::last_os_error().raw_os_error().unwrap()` which gives us the errno string

Open andreafioraldi opened this issue 2 years ago • 9 comments

          There is `std::io::Error::last_os_error().raw_os_error().unwrap()` which gives us the errno string if I read this correctly, so that could be used for `Error` here

Originally posted by @domenukk in https://github.com/AFLplusplus/LibAFL/pull/1389#discussion_r1287043229

andreafioraldi avatar Aug 08 '23 13:08 andreafioraldi

Hi , I am new here. Can you assign me this issue? I plan to replace all perror with the error string returning line you mentioned in libafl_bolts/src/shmem.rs

gerceboss avatar Jan 26 '24 21:01 gerceboss

Feel free to do it :)

domenukk avatar Jan 26 '24 22:01 domenukk

@domenukk while running the cargo clippy --all command I ran in one error , all other things were fine. Can you please guide me on this ? before I run the next set of commands to generate a PR. I checked the folder where it points the error to, I do have the build_nyx_support.sh file in there.

clippy error

gerceboss avatar Jan 28 '24 10:01 gerceboss

@gerceboss No such file or directory might refer to the shell script's interpreter in the shebang in this case (Linux's error messages for process spawning issues are a bit weird..). Are you running on a system that does not provide bash under /bin/bash? Feel free to update the shebang to use #!/usr/bin/env bash instead, which should be more portable since /usr/bin/env is available on all Linux distros and avoids the hardcoded path to bash.

Mrmaxmeier avatar Jan 28 '24 13:01 Mrmaxmeier

@domenukk , I switched to linux for the repository. I am having this error while running cargo clippy --all , can you help me in this, please?

Screenshot from 2024-02-07 03-21-37

gerceboss avatar Feb 06 '24 21:02 gerceboss

I don't see the actual error, but can you try if this works: LLVM_CONFIG_PATH=/usr/bin/llvm-config cargo build?

domenukk avatar Feb 07 '24 13:02 domenukk

@domenukk can I just generate the PR? I think this error is occuring are related to the LLVM and clang installation . It says failed to build custom command for libafl_cc v0.11.2

gerceboss avatar Feb 07 '24 21:02 gerceboss

Sure, the CI will check it anyway - but you probably want to fix your LLVM install at some point ;)

domenukk avatar Feb 08 '24 13:02 domenukk

Surely, I will fix it soon.

gerceboss avatar Feb 08 '24 13:02 gerceboss

I'm looking into this. I found that std::io::Error::last_os_error().raw_os_error().unwrap() is of type std::io::RawOsError, which is an alias to i32 type, and there doesn't seem to be a convenient way to convert it to a descriptive string.

Instead, as suggested in the deprecation warning of std::io::Error::description(), we can use std::io::Error::last_os_error().to_string(). This uses the Display trait and returns something like {sys::os::error_string(code)} (os error {code}) (src). For example, "No such file or directory (os error 2)".

This stack overflow question said that it does not seem "easy" to get rid of the "(os error {code})" part.

am009 avatar Mar 13 '24 17:03 am009

we don't need to get rid of it https://github.com/am009/LibAFL/commit/bb2b63851ee38391c60865d0766bdf34b0f0de7f this is fine but we could add another enum like Error::UnixOSError(), instead of Error::unknown see libafl_bolts::Error

tokatoka avatar Mar 13 '24 17:03 tokatoka