aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCyrill Gorcunov <gorcunov@gmail.com>2020-12-31 16:50:25 +0300
committerCyrill Gorcunov <gorcunov@gmail.com>2020-12-31 16:50:25 +0300
commit79ac0d686dbf99758c9589fc4db6be4a2c5476e4 (patch)
treebad97d0ed402fdebf2b63d3fe6015e9c566b47a1
parentdc4a6194265962f288b73cca8097b850283bfb5f (diff)
parentf95c7e983c00d6b9f46fde7c702c0e5351b7dffa (diff)
downloadnasm-79ac0d686dbf99758c9589fc4db6be4a2c5476e4.tar.gz
nasm-79ac0d686dbf99758c9589fc4db6be4a2c5476e4.tar.xz
nasm-79ac0d686dbf99758c9589fc4db6be4a2c5476e4.zip
Merge branch 'nasm-2.15.xx'
* nasm-2.15.xx: preproc: prohibit unmacro while macro expansion
-rw-r--r--asm/preproc.c13
-rw-r--r--travis/test/br3392531.asmbin0 -> 366 bytes
-rw-r--r--travis/test/br3392531.json12
-rw-r--r--travis/test/br3392531.stderr29
-rw-r--r--travis/test/br3392716.asmbin0 -> 237 bytes
-rw-r--r--travis/test/br3392716.json13
-rw-r--r--travis/test/br3392716.stderr37
7 files changed, 104 insertions, 0 deletions
diff --git a/asm/preproc.c b/asm/preproc.c
index 69543174..ab229c9c 100644
--- a/asm/preproc.c
+++ b/asm/preproc.c
@@ -4330,6 +4330,19 @@ issue_error:
goto done;
}
mmac_p = (MMacro **) hash_findi(&mmacros, spec.name, NULL);
+
+ /* Check the macro to be undefined is not being expanded */
+ list_for_each(l, istk->expansion) {
+ if (l->finishes == *mmac_p) {
+ nasm_nonfatal("`%%unmacro' can't undefine the macro being expanded");
+ /*
+ * Do not release the macro instance to avoid using the freed
+ * memory while proceeding the expansion.
+ */
+ goto done;
+ }
+ }
+
while (mmac_p && *mmac_p) {
mmac = *mmac_p;
if (mmac->casesense == spec.casesense &&
diff --git a/travis/test/br3392531.asm b/travis/test/br3392531.asm
new file mode 100644
index 00000000..6ef2c689
--- /dev/null
+++ b/travis/test/br3392531.asm
Binary files differ
diff --git a/travis/test/br3392531.json b/travis/test/br3392531.json
new file mode 100644
index 00000000..1a4c7bf6
--- /dev/null
+++ b/travis/test/br3392531.json
@@ -0,0 +1,12 @@
+[
+ {
+ "description": "%unmacro is forbidden for macro being expanded",
+ "id": "br3392531",
+ "format": "bin",
+ "source": "br3392531.asm",
+ "error": "expected",
+ "target": [
+ { "stderr": "br3392531.stderr" }
+ ]
+ }
+]
diff --git a/travis/test/br3392531.stderr b/travis/test/br3392531.stderr
new file mode 100644
index 00000000..84810b64
--- /dev/null
+++ b/travis/test/br3392531.stderr
@@ -0,0 +1,29 @@
+./travis/test/br3392531.asm:1: error: label or instruction expected at start of line
+./travis/test/br3392531.asm:4: error: invalid decorator token inside braces
+./travis/test/br3392531.asm:4: error: label or instruction expected at start of line
+./travis/test/br3392531.asm:5: error: parser: instruction expected
+./travis/test/br3392531.asm:7: error: `%macro' expects a parameter count
+./travis/test/br3392531.asm:11: warning: unterminated string [-w+other]
+./travis/test/br3392531.asm:14: error: parser: instruction expected
+./travis/test/br3392531.asm:17: error: `%$LRG': context stack is empty
+./travis/test/br3392531.asm:17: error: `%$LRG': context stack is empty
+./travis/test/br3392531.asm:17: error: label or instruction expected at start of line
+./travis/test/br3392531.asm:18: error: label or instruction expected at start of line
+./travis/test/br3392531.asm:19: error: parser: instruction expected
+./travis/test/br3392531.asm:20: error: `%1': not in a macro call
+./travis/test/br3392531.asm:20: error: label or instruction expected at start of line
+./travis/test/br3392531.asm:21: error: label or instruction expected at start of line
+./travis/test/br3392531.asm:8: ... from macro `section' defined here
+./travis/test/br3392531.asm:21: error: parser: instruction expected
+./travis/test/br3392531.asm:9: ... from macro `section' defined here
+./travis/test/br3392531.asm:21: error: label or instruction expected at start of line
+./travis/test/br3392531.asm:10: ... from macro `section' defined here
+./travis/test/br3392531.asm:21: error: invalid macro parameter: `%4stru@namB'
+./travis/test/br3392531.asm:11: ... from macro `section' defined here
+./travis/test/br3392531.asm:21: error: parser: instruction expected
+./travis/test/br3392531.asm:11: ... from macro `section' defined here
+./travis/test/br3392531.asm:21: error: `%unmacro' expects a parameter count
+./travis/test/br3392531.asm:12: ... from macro `section' defined here
+./travis/test/br3392531.asm:21: error: `%unmacro' can't undefine the macro being expanded
+./travis/test/br3392531.asm:12: ... from macro `section' defined here
+./travis/test/br3392531.asm:22: error: parser: instruction expected
diff --git a/travis/test/br3392716.asm b/travis/test/br3392716.asm
new file mode 100644
index 00000000..ac480f30
--- /dev/null
+++ b/travis/test/br3392716.asm
Binary files differ
diff --git a/travis/test/br3392716.json b/travis/test/br3392716.json
new file mode 100644
index 00000000..b3d4e0b1
--- /dev/null
+++ b/travis/test/br3392716.json
@@ -0,0 +1,13 @@
+[
+ {
+ "description": "%unmacro is forbidden for macro being expanded",
+ "id": "br3392716",
+ "format": "macho64",
+ "source": "br3392716.asm",
+ "option": "-g",
+ "error": "expected",
+ "target": [
+ { "stderr": "br3392716.stderr" }
+ ]
+ }
+]
diff --git a/travis/test/br3392716.stderr b/travis/test/br3392716.stderr
new file mode 100644
index 00000000..049bcb94
--- /dev/null
+++ b/travis/test/br3392716.stderr
@@ -0,0 +1,37 @@
+./travis/test/br3392716.asm:1: error: label or instruction expected at start of line
+./travis/test/br3392716.asm:2: error: `%unmacro' expects a parameter count
+./travis/test/br3392716.asm:3: warning: unterminated string [-w+other]
+./travis/test/br3392716.asm:3: error: `%unmacro' expects a macro name
+./travis/test/br3392716.asm:4: warning: unterminated string [-w+other]
+./travis/test/br3392716.asm:4: error: label or instruction expected at start of line
+./travis/test/br3392716.asm:5: error: `%macro' expects a parameter count
+./travis/test/br3392716.asm:15: warning: unterminated string [-w+other]
+./travis/test/br3392716.asm:20: warning: unterminated string [-w+other]
+./travis/test/br3392716.asm:20: warning: multi-line macro `sst' exists, but not taking 1 parameter [-w+macro-params-multi]
+./travis/test/br3392716.asm:20: error: parser: instruction expected
+./travis/test/br3392716.asm:21: error: `%%cTo': not in a macro call
+./travis/test/br3392716.asm:21: error: label or instruction expected at start of line
+./travis/test/br3392716.asm:6: ... from macro `sst' defined here
+./travis/test/br3392716.asm:21: error: `%unmacro' expects a parameter count
+./travis/test/br3392716.asm:7: ... from macro `sst' defined here
+./travis/test/br3392716.asm:21: error: `%unmacro' can't undefine the macro being expanded
+./travis/test/br3392716.asm:7: ... from macro `sst' defined here
+./travis/test/br3392716.asm:21: error: label or instruction expected at start of line
+./travis/test/br3392716.asm:8: ... from macro `sst' defined here
+./travis/test/br3392716.asm:21: error: parser: instruction expected
+./travis/test/br3392716.asm:10: ... from macro `sst' defined here
+./travis/test/br3392716.asm:21: error: label or instruction expected at start of line
+./travis/test/br3392716.asm:11: ... from macro `sst' defined here
+./travis/test/br3392716.asm:21: error: `%unmacro' expects a parameter count
+./travis/test/br3392716.asm:12: ... from macro `sst' defined here
+./travis/test/br3392716.asm:21: error: `%unmacro' can't undefine the macro being expanded
+./travis/test/br3392716.asm:12: ... from macro `sst' defined here
+./travis/test/br3392716.asm:21: error: label or instruction expected at start of line
+./travis/test/br3392716.asm:13: ... from macro `sst' defined here
+./travis/test/br3392716.asm:21: error: parser: instruction expected
+./travis/test/br3392716.asm:15: ... from macro `sst' defined here
+./travis/test/br3392716.asm:21: error: `%macro' expects a macro name
+./travis/test/br3392716.asm:16: ... from macro `sst' defined here
+./travis/test/br3392716.asm:21: error: parser: instruction expected
+./travis/test/br3392716.asm:17: ... from macro `sst' defined here
+./travis/test/br3392716.asm:22: error: label or instruction expected at start of line