From 008ce76d335f269b2c10301b3360ecd0337e454b Mon Sep 17 00:00:00 2001 From: Daniel Trugman Date: Mon, 22 Feb 2021 21:43:55 +0000 Subject: [PATCH] Fix maps parsing when pathname is not a single token This is expected when: - File was deleted: ' (deleted)' is appended at the end - File path contains spaces --- src/parsers/maps.cpp | 11 ++++++++--- test/maps.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/src/parsers/maps.cpp b/src/parsers/maps.cpp index fd1d443..e089893 100644 --- a/src/parsers/maps.cpp +++ b/src/parsers/maps.cpp @@ -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); @@ -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; diff --git a/test/maps.cpp b/test/maps.cpp index ec5b987..538c251 100644 --- a/test/maps.cpp +++ b/test/maps.cpp @@ -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' : '-');