0
0
mirror of https://github.com/netwide-assembler/nasm.git synced 2025-10-10 00:25:06 -04:00

BR3041451: Implement upper bound for %rep counter

Since %rep counter is a 64 bit signed integer we have to use some
"maximum possible value" limit (upper bound) otherwise there may be
a situation when %rep counter is 0 or even negative while user
has been passing big positive integer value.

Reported-by: nasm64developer
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
This commit is contained in:
Cyrill Gorcunov
2010-08-09 13:58:22 +04:00
parent fe55e918fa
commit e091d6ed62
3 changed files with 15 additions and 1 deletions

View File

@@ -9,6 +9,9 @@ since 2007.
\S{cl-2.09} Version 2.09 \S{cl-2.09} Version 2.09
\b Fixed assignment the magnitude of \c{%rep} counter. It is limited
to 62 bits now.
\b Fixed NULL dereference if argument of \c{%strlen} resolves \b Fixed NULL dereference if argument of \c{%strlen} resolves
to whitespace. For example if nonexistent macro parameter is used. to whitespace. For example if nonexistent macro parameter is used.

View File

@@ -3211,6 +3211,9 @@ infinite loop in the preprocessor, which (on multitasking or
multi-user systems) would typically cause all the system memory to multi-user systems) would typically cause all the system memory to
be gradually used up and other applications to start crashing. be gradually used up and other applications to start crashing.
Note a maximum repeat count is limited by 62 bit number, though it
is hardly possible that you ever need anything bigger.
\H{files} Source Files and Dependencies \H{files} Source Files and Dependencies

View File

@@ -326,6 +326,9 @@ enum {
*/ */
#define DEADMAN_LIMIT (1 << 20) #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 * 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, * used in nasm.h for the "real" condition codes. At _this_ level,
@@ -2895,7 +2898,12 @@ issue_error:
error(ERR_NONFATAL, "non-constant value given to `%%rep'"); error(ERR_NONFATAL, "non-constant value given to `%%rep'");
return DIRECTIVE_FOUND; return DIRECTIVE_FOUND;
} }
count = reloc_value(evalresult) + 1; count = reloc_value(evalresult);
if (count >= REP_LIMIT) {
error(ERR_NONFATAL, "`%%rep' evalue exceeds limit");
count = 0;
} else
count++;
} else { } else {
error(ERR_NONFATAL, "`%%rep' expects a repeat count"); error(ERR_NONFATAL, "`%%rep' expects a repeat count");
count = 0; count = 0;