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

get_section_by_name requres a String instead of an &str #6

Closed
LunNova opened this issue Dec 31, 2022 · 4 comments
Closed

get_section_by_name requres a String instead of an &str #6

LunNova opened this issue Dec 31, 2022 · 4 comments

Comments

@LunNova
Copy link

LunNova commented Dec 31, 2022

    fn get_section_by_name(&self, name: String) -> Result<&ImageSectionHeader, Error> {
        let sections = self.get_section_table()?;
        let s = name.as_str();

        for section in sections {
            if section.name.as_str() == s {
                return Ok(section);
            }
        }

        Err(Error::SectionNotFound)
    }

Taking an &str would be nicer here and it looks like it's fine since it immediately gets converted to one.

@frank2
Copy link
Owner

frank2 commented Jan 2, 2023

Curse of me starting this crate when I was new to Rust, literally like confusing const char * and std::string. Thanks for reporting this, I'll get this fixed in the next version!

@frank2
Copy link
Owner

frank2 commented Jan 7, 2023

This actually made me realize there's a bug here, so this might take a little longer to come out-- there's a possibility that a section name can not be a valid UTF8 string, and so the str returned by as_str() would cause a panic when the string is used because it's not valid UTF8. This happens because I'm intentionally transmuting a reference that points into the PE file.

Anyway, I've started work on this, I'll update you when I get this bug fixed!

@frank2
Copy link
Owner

frank2 commented Jan 7, 2023

Okay, this issue plus the issue this uncovered have been fixed as of this commit: 02527d9. This will be officially released in 0.5.5. Thanks again for reporting!

@frank2 frank2 closed this as completed Jan 7, 2023
@frank2
Copy link
Owner

frank2 commented Jan 10, 2023

This is live in 0.5.6 (not 0.5.5, no idea what release that was). Thanks again!

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

2 participants