[PATCH] D32968: Add dyld to sanitizer procmaps on darwin

Aleksey Shlyapnikov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 8 14:13:10 PDT 2017


alekseyshl added inline comments.


================
Comment at: lib/sanitizer_common/sanitizer_procmaps_mac.cc:235
+                                 (vm_region_info_t)&info, &count);
+      if (size >= sizeof(struct mach_header) &&
+          info.protection & MemoryMappingLayout::kProtectionRead) {
----------------
Shouldn't we check err == KERN_SUCCESS before accessing vm_region_recurse_64 results?


================
Comment at: lib/sanitizer_common/sanitizer_procmaps_mac.cc:237
+          info.protection & MemoryMappingLayout::kProtectionRead) {
+        dyld_hdr = (struct mach_header *)address;
+        if ((dyld_hdr->magic == MH_MAGIC || dyld_hdr->magic == MH_MAGIC_64) &&
----------------
This means that dyld_hdr at some point contains a pointer to something other than dyld and might even stay that way if something goes wrong in this loop.


================
Comment at: lib/sanitizer_common/sanitizer_procmaps_mac.cc:250
+  return dyld_hdr;
+}
+
----------------
How about using local static var initialization?

  static const struct mach_header *get_dyld_hdr() {
    static struct mach_header *header = get_dyld_image_header();
    return header;
  }

and then use get_dyld_hdr() everywhere instead of dyld_hdr and get_dyld_image_header()?


https://reviews.llvm.org/D32968





More information about the llvm-commits mailing list