Validate input at libelf level
[centaur.git] / include / libelfu / generic.h
index f5b0e0f030e7ccba0c8e3746131b15a042f33217..09d2ffc651f0d372815027c5d72896fae5068d6b 100644 (file)
@@ -3,9 +3,22 @@
 
 #include <libelf/gelf.h>
 
+#define OFFS_END(off, sz) ((off) + (sz))
+
+#define OVERLAPPING(off1, sz1, off2, sz2) \
+  (!((off1) == (off2) && ((sz1 == 0) || (sz2 == 0))) \
+   && (((off1) <= (off2) && (off2) < OFFS_END((off1), (sz1))) \
+       || ((off2) <= (off1) && (off1) < OFFS_END((off2), (sz2)))) \
+  )
+
+#define FULLY_OVERLAPPING(off1, sz1, off2, sz2) \
+  (((off1) <= (off2) && OFFS_END((off2), (sz2)) <= OFFS_END((off1), (sz1))) \
+   || ((off2) <= (off1) && OFFS_END((off1), (sz1)) <= OFFS_END((off2), (sz2))))
+
 
-size_t elfu_gScnSizeFile(const GElf_Shdr *shdr);
 
 int elfu_gPhdrContainsScn(GElf_Phdr *phdr, GElf_Shdr *shdr);
 
+size_t elfu_gScnSizeFile(const GElf_Shdr *shdr);
+
 #endif