Summary: | Heap use-after-free while using %clear inside a macro. | ||
---|---|---|---|
Product: | NASM | Reporter: | Marco <mvanotti> |
Component: | Assembler | Assignee: | nobody <nobody> |
Status: | OPEN --- | ||
Severity: | normal | CC: | chang.seok.bae, gorcunov, hpa, mvanotti, nasm-bugs |
Priority: | Medium | ||
Version: | 2.16.xx | ||
Hardware: | PC | ||
OS: | Linux | ||
Obtained from: | Built from git using configure | Generated by: | --- |
Bug category: | Breaks existing code: | --- |
Description
Marco
2021-06-03 10:47:28 PDT
This is an error for the same reason %unmacro in a running macro is. This obviously applies specifically to macros; clearing other things like defaliases are totally ok. Thanks for the reply, Peter. So a reasonable fix would be to disallow usage of %clear inside multi-line macros? Something like: * Disable %clear * Disable %clear all * Disable %clear macro I have never used context-local macros, so I am probably missing something there. I'm wondering if we shouldn't simply use the same teardown code as for %unmacro. There is already an invocation counter in the macro structure, so it isn't like we don't need to search the macro stack. Hi Peter, I have some time to give this a go. Here is a patch fixing this issue, and a few related smaller issues (for example, the %clear all never ever worked. It just loops endlessly on my computer). It still needs tests, but I have a couple of test cases that I can add, once I figure out how nasm tests work :) Please take a look when you have some time: https://github.com/netwide-assembler/nasm/commit/54b579b04b2a8c1dbf6a7acf1e26037a78e7a509 While looking at it, I noticed that there is some room for improvement in the handling of the %clear arguments. In particular, it seems to be possible to do something like %clear all all all all all all all all (etc), and something like %clear local defines global defines The documentation mentions that the context should be at the start (if present). With that in mind, the code can be simplified a bit. Like parsing first the context, then the rest of the parameters, and finally, making a single call to do_clear, checking for the mmacros expansion beforehand. Hi, I was wondering if there were any updates on this issue. Does the patch need any more work? |