diff options
author | H. Peter Anvin <hpa@zytor.com> | 2007-11-19 12:26:50 -0800 |
---|---|---|
committer | H. Peter Anvin <hpa@zytor.com> | 2007-11-19 12:26:50 -0800 |
commit | cb1cf59312f0694027c0c3ce79293ed19e8b9335 (patch) | |
tree | 0bbb4bee68dd0dd5a823d981815c5e2ea96ef604 /preproc.c | |
parent | a27ccb9f61101091f16902035b3e019604473e24 (diff) | |
download | nasm-cb1cf59312f0694027c0c3ce79293ed19e8b9335.tar.gz nasm-cb1cf59312f0694027c0c3ce79293ed19e8b9335.tar.bz2 nasm-cb1cf59312f0694027c0c3ce79293ed19e8b9335.zip |
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.
Diffstat (limited to 'preproc.c')
-rw-r--r-- | preproc.c | 10 |
1 files changed, 9 insertions, 1 deletions
@@ -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) |