[Nasm-commits] [nasm:preproc-rewrite] preproc.c: added support for REP_LIMIT

nasm-bot for Keith Kanios keith at kanios.net
Thu Jun 4 19:56:34 PDT 2020


Commit-ID:  e77749400675a3e858d7c88e5a14d19ed70a7403
Gitweb:     http://repo.or.cz/w/nasm.git?a=commitdiff;h=e77749400675a3e858d7c88e5a14d19ed70a7403
Author:     Keith Kanios <keith at kanios.net>
AuthorDate: Sat, 6 Nov 2010 15:13:03 -0500
Committer:  Keith Kanios <keith at kanios.net>
CommitDate: Sat, 6 Nov 2010 15:13:03 -0500

preproc.c: added support for REP_LIMIT



---
 preproc.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/preproc.c b/preproc.c
index 508e09f6..6014c245 100644
--- a/preproc.c
+++ b/preproc.c
@@ -226,9 +226,9 @@ struct ExpDef {
 	Line *last;
 	int linecount;				/* number of lines within expansion */
 	
-	uint32_t def_depth;			/* current number of definition pairs deep */
-    uint32_t cur_depth;         /* current number of expansions */
-    uint32_t max_depth;         /* maximum number of expansions allowed */
+	int64_t def_depth;			/* current number of definition pairs deep */
+    int64_t cur_depth;          /* current number of expansions */
+    int64_t max_depth;          /* maximum number of expansions allowed */
 	
 	int state;					/* condition state */
 	bool ignoring;				/* ignoring definition lines */
@@ -333,6 +333,9 @@ enum {
  */
 #define DEADMAN_LIMIT (1 << 20)
 
+/* max reps */
+#define REP_LIMIT ((INT64_C(1) << 62))
+
 /*
  * Condition codes. Note that we use c_ prefix not C_ because C_ is
  * used in nasm.h for the "real" condition codes. At _this_ level,
@@ -3060,7 +3063,12 @@ issue_error:
                 error(ERR_NONFATAL, "non-constant value given to `%%rep'");
                 return DIRECTIVE_FOUND;
             }
-            count = reloc_value(evalresult) + 1;
+            count = reloc_value(evalresult);
+            if (count >= REP_LIMIT) {
+                error(ERR_NONFATAL, "`%%rep' value exceeds limit");
+                count = 0;
+            } else
+                count++;
         } else {
             error(ERR_NONFATAL, "`%%rep' expects a repeat count");
             count = 0;


More information about the Nasm-commits mailing list