[PATCH 02/10] libsframe: guard against malformed rep_block_size

Indu Bhagat <[email protected]>
Newsgroups gmane.comp.gnu.binutils
Message-ID <[email protected]>
From: Indu Bhagat <[email protected]>

When checking for an applicable FRE, guard against invalid data in
rep_block_size, lest there be an arithmetic exception caused by division
by zero.  Similar code was flagged by Sashiko in the stacktracer patches
for Linux kernel earlier.
---
 libsframe/sframe.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/libsframe/sframe.c b/libsframe/sframe.c
index 011884c0768..712dd0fdb68 100644
--- a/libsframe/sframe.c
+++ b/libsframe/sframe.c
@@ -600,7 +600,12 @@ sframe_fre_check_range_p (const sframe_decoder_ctx *dctx, uint32_t func_idx,
   /* For SFrame FDEs encoding information for repetitive pattern of insns,
      masking with the rep_block_size is necessary to find the matching FRE.  */
   if (mask_p)
-    pc_offset = pc_offset % rep_block_size;
+    {
+      /* Treat a zero-sized repeat block as malformed input.  */
+      if (rep_block_size == 0)
+	return false;
+      pc_offset = pc_offset % rep_block_size;
+    }
 
   return (start_ip_offset <= pc_offset) && (end_ip_offset >= pc_offset);
 }
-- 
2.43.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.