summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2007-11-19 12:26:50 -0800
committerH. Peter Anvin <hpa@zytor.com>2007-11-19 12:26:50 -0800
commitcb1cf59312f0694027c0c3ce79293ed19e8b9335 (patch)
tree0bbb4bee68dd0dd5a823d981815c5e2ea96ef604
parenta27ccb9f61101091f16902035b3e019604473e24 (diff)
downloadnasm-cb1cf59312f0694027c0c3ce79293ed19e8b9335.tar.gz
BR 812417: Deadman counter for macro expansion
Per BR 812417, certain macro expansions can hang NASM. Allow a deadman counter (currently set to 2^20) to fail out if it gets ridiculous.
-rw-r--r--preproc.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/preproc.c b/preproc.c
index 7af9fdc2..f9c4de36 100644
--- a/preproc.c
+++ b/preproc.c
@@ -2981,6 +2981,8 @@ static Token *expand_mmac_params(Token * tline)
* Tokens from input to output a lot of the time, rather than
* actually bothering to destroy and replicate.)
*/
+#define DEADMAN_LIMIT (1 << 20)
+
static Token *expand_smacro(Token * tline)
{
Token *t, *tt, *mstart, **tail, *thead;
@@ -2992,6 +2994,7 @@ static Token *expand_smacro(Token * tline)
Token *org_tline = tline;
Context *ctx;
char *mname;
+ int deadman = 0;
/*
* Trick: we should avoid changing the start token pointer since it can
@@ -3008,11 +3011,16 @@ static Token *expand_smacro(Token * tline)
org_tline->text = NULL;
}
- again:
+again:
tail = &thead;
thead = NULL;
while (tline) { /* main token loop */
+ if (++deadman > DEADMAN_LIMIT) {
+ error(ERR_NONFATAL, "interminable macro recursion");
+ break;
+ }
+
if ((mname = tline->text)) {
/* if this token is a local macro, look in local context */
if (tline->type == TOK_ID || tline->type == TOK_PREPROC_ID)