Skip to content

Commit

Permalink
Fix maps parsing when pathname is not a single token
Browse files Browse the repository at this point in the history
This is expected when:
- File was deleted: ' (deleted)' is appended at the end
- File path contains spaces
  • Loading branch information
dtrugman committed Feb 22, 2021
1 parent b291587 commit 008ce76
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/parsers/maps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ mem_region parse_maps_line(const std::string& line)
};

auto tokens = utils::split(line);
if (tokens.size() < MIN_COUNT || tokens.size() > COUNT)
if (tokens.size() < MIN_COUNT)
{
throw parser_error("Corrupted maps line - Unexpected tokens count",
line);
Expand All @@ -183,9 +183,14 @@ mem_region parse_maps_line(const std::string& line)

region.inode = parse_mem_region_inode(tokens[INODE]);

if (tokens.size() > PATHNAME)
for (size_t i = PATHNAME; i < tokens.size(); ++i)
{
region.pathname = tokens[PATHNAME];
if (!region.pathname.empty())
{
region.pathname += " ";
}

region.pathname += tokens[i];
}

return region;
Expand Down
40 changes: 40 additions & 0 deletions test/maps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,46 @@ TEST_CASE("Parse maps", "[task][maps]")
pathname = "/lib/x86_64-linux-gnu/ld-2.27.so";
}

SECTION("Deleted")
{
start = 0x7fcbe4bc0000;
end = 0x7f0b476c6000;

can_read = true;
can_write = false;
can_execute = true;
is_private = true;

offset = 0x00000000;

dev_major = 0xfd;
dev_minor = 0x00;

inode = 2097624;

pathname = "/lib/x86_64-linux-gnu/libm-2.27.so (deleted)";
}

SECTION("Pathname with spaces")
{
start = 0x7f3fcf467000;
end = 0x7f3fcf666000;

can_read = false;
can_write = false;
can_execute = false;
is_private = true;

offset = 0x0019d000;

dev_major = 0xfd;
dev_minor = 0x00;

inode = 3801114;

pathname = "/tmp/lib m 2.25.so";
}

std::ostringstream out;
out << std::hex << start << "-" << end << std::dec << " ";
out << (can_read ? 'r' : '-');
Expand Down

0 comments on commit 008ce76

Please sign in to comment.