Skip to content

Commit

Permalink
fix mmap twice
Browse files Browse the repository at this point in the history
  • Loading branch information
yoloyyh committed Nov 6, 2024
1 parent c33aafa commit 457a5e8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
5 changes: 3 additions & 2 deletions rasp/librasp/src/golang.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use log::*;
use memmap::Mmap;
use std::fs::File;
use std::{fs, path::PathBuf, process::Command};
use regex::Regex;
Expand Down Expand Up @@ -160,9 +161,9 @@ pub fn parse_version(version: &String) -> Result<String> {
return Err(anyhow::anyhow!("Failed to extract version number, from: {}", version));
}

pub fn golang_version(file: &File, elf: &Elf) -> Result<String> {
pub fn golang_version(file: &File, elf: &Elf, bin: &Mmap) -> Result<String> {

if let Ok(version) = find_by_section(&elf, &file) {
if let Ok(version) = find_by_section(&elf, &file, &bin) {
return parse_version(&version);
} else {
if let Ok(version) = find_by_symbol(&elf, &file) {
Expand Down
6 changes: 1 addition & 5 deletions rasp/librasp/src/parse_elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ pub fn find_by_symbol(elf: &Elf, file: &File) -> Result<String> {
}
}

pub fn find_by_section(elf: &Elf, file: &File) -> Result<String> {
pub fn find_by_section(elf: &Elf, file: &File, mmap: &Mmap) -> Result<String> {
let mut version: String = String::new();

// find .go.buildinfo
Expand All @@ -159,10 +159,6 @@ pub fn find_by_section(elf: &Elf, file: &File) -> Result<String> {
let end = (go_buildinfo_section.sh_offset + go_buildinfo_section.sh_size) as usize;

// Memory map the specific section
let mmap = match unsafe { Mmap::map(file) } {
Ok(m) => m,
Err(e) => {return Err(anyhow!(e));}// Return empty string if mmap fails
};
if mmap.len() < end {
return Err(anyhow!("mmap length invaild")); // Return empty string if the section is out of bounds
}
Expand Down

0 comments on commit 457a5e8

Please sign in to comment.