[libunwind] [libunwind] Avoid reading OOB for non-existent .eh_frame_hdr (PR #68815)

Saleem Abdulrasool via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 11 09:48:08 PDT 2023


================
@@ -53,8 +53,21 @@ template <typename A> class EHHeaderParser {
 
 template <typename A>
 bool EHHeaderParser<A>::decodeEHHdr(A &addressSpace, pint_t ehHdrStart,
-                                    pint_t ehHdrEnd, EHHeaderInfo &ehHdrInfo) {
+                                    size_t ehHdrSize, EHHeaderInfo &ehHdrInfo) {
   pint_t p = ehHdrStart;
+  pint_t ehHdrEnd = ehHdrStart + ehHdrSize;
+
+  // Ensure that we don't read data beyond the end of .eh_frame_hdr
+  if (ehHdrSize < 4) {
----------------
compnerd wrote:

I kinda feel that its safer - its not changing the semantics of the parameter and can ensure that any downstream forks don't need to worry about the change in the internal call.

https://github.com/llvm/llvm-project/pull/68815


More information about the cfe-commits mailing list