From gorcunov at gmail.com Wed Nov 4 02:18:10 2020 From: gorcunov at gmail.com (nasm-bot for Cyrill Gorcunov) Date: Wed, 4 Nov 2020 02:18:10 -0800 Subject: [nasm:master] BR3392637: output/outieee: Fix nil dereference Message-ID: Commit-ID: 93c774d482694643cafbc82578ac8b729fb5bc8b Gitweb: http://repo.or.cz/w/nasm.git?a=commitdiff;h=93c774d482694643cafbc82578ac8b729fb5bc8b Author: Cyrill Gorcunov AuthorDate: Wed, 4 Nov 2020 13:08:06 +0300 Committer: Cyrill Gorcunov CommitDate: Wed, 4 Nov 2020 13:08:06 +0300 BR3392637: output/outieee: Fix nil dereference The handling been broken in commit 98578071. Signed-off-by: Cyrill Gorcunov --- output/outieee.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/output/outieee.c b/output/outieee.c index bff2f085..b3ccc5f6 100644 --- a/output/outieee.c +++ b/output/outieee.c @@ -795,6 +795,23 @@ static int32_t ieee_segment(char *name, int *bits) define_label(name, seg->index + 1, 0L, false); ieee_seg_needs_update = NULL; + /* + * In commit 98578071b9d71ecaa2344dd9c185237c1765041e + * we reworked labels significantly which in turn lead + * to the case where seg->name = NULL here and we get + * nil dereference in next segments definitions. + * + * Lets placate this case with explicit name setting + * if labels engine didn't set it yet. + * + * FIXME: Need to revisit this moment if such fix doesn't + * break anything but since IEEE 695 format is veeery + * old I don't expect there are many users left. In worst + * case this should only lead to a memory leak. + */ + if (!seg->name) + seg->name = nasm_strdup(name); + if (seg->use32) *bits = 32; else From gorcunov at gmail.com Wed Nov 4 02:18:14 2020 From: gorcunov at gmail.com (nasm-bot for Cyrill Gorcunov) Date: Wed, 4 Nov 2020 02:18:14 -0800 Subject: [nasm:master] travis: add br3392637 Message-ID: Commit-ID: dc4a6194265962f288b73cca8097b850283bfb5f Gitweb: http://repo.or.cz/w/nasm.git?a=commitdiff;h=dc4a6194265962f288b73cca8097b850283bfb5f Author: Cyrill Gorcunov AuthorDate: Wed, 4 Nov 2020 13:15:52 +0300 Committer: Cyrill Gorcunov CommitDate: Wed, 4 Nov 2020 13:15:52 +0300 travis: add br3392637 Code for testcase provided by Suhwan. Reported-by: Suhwan Signed-off-by: Cyrill Gorcunov --- travis/test/br3392637.asm | 46 +++++++++++++++++++++++++++++++++++++++++++ travis/test/br3392637.json | 21 ++++++++++++++++++++ travis/test/br3392637.o.t | Bin 0 -> 848 bytes travis/test/br3392637.stderr | 15 ++++++++++++++ 4 files changed, 82 insertions(+) diff --git a/travis/test/br3392637.asm b/travis/test/br3392637.asm new file mode 100644 index 00000000..1a5ee975 --- /dev/null +++ b/travis/test/br3392637.asm @@ -0,0 +1,46 @@ +; ----------------------------------------------------------------------------- +; A 64-bit Linux application that writes the first 90 Fibonacci numbers. To +; assemble and run: +; +; nasm -felf64 fib.asm && gcc fib.o && ./a.out +; ----------------------------------------------------------------------------- + + global main + extern printf + + section .text +main: + push rbx ; we have to save this since we use it + + mov ecx, 90 ; ecx will countdown to 0 + xor rax, rax ; rax will hold the current number + xor rbx, rbx ; rbx will hold the next number + inc rbx ; rbx is originally 1 +print: + ; We need to call printf, but we are using rax, rbx, and rcx. printf + ; may destroy rax and rcx so we will save these before the call and + ; restore them afterwards. + + push rax ; caller-save register + push rcx ; caller-save register + + mov rdi, format ; set 1st parameter (format) + mov rsi, rax ; set 2nd parameter (current_number) + xor rax, rax ; because printf is varargs + + ; Stack is already aligned because we pushed three 8 byte registers + call printf ; printf(format, current_number) + + pop rcx ; restore caller-save register + pop rax ; restore caller-save register + + mov rdx, rax ; save the current number + mov rax, rbx ; next number is now current + add rbx, rdx ; get the new next number + dec ecx ; count down + jnz print ; if not done counting, do some more + + pop rbx ; restore rbx before returning + ret +format: + db "%20ld", 10, 0 diff --git a/travis/test/br3392637.json b/travis/test/br3392637.json new file mode 100644 index 00000000..3a3de297 --- /dev/null +++ b/travis/test/br3392637.json @@ -0,0 +1,21 @@ +[ + { + "description": "Test for br3392637 (pass)", + "id": "br3392637", + "source": "br3392637.asm", + "format": "elf64", + "option": "-Ox", + "target": [ + { "output": "br3392637.o" } + ] + }, + { + "description": "Test for br3392637 (nil dereference)", + "ref": "br3392637", + "format": "ieee", + "target": [ + { "stderr": "br3392637.stderr" } + ], + "error" : "expected" + } +] diff --git a/travis/test/br3392637.o.t b/travis/test/br3392637.o.t new file mode 100644 index 00000000..e96bb76b Binary files /dev/null and b/travis/test/br3392637.o.t differ diff --git a/travis/test/br3392637.stderr b/travis/test/br3392637.stderr new file mode 100644 index 00000000..5016bd40 --- /dev/null +++ b/travis/test/br3392637.stderr @@ -0,0 +1,15 @@ +./travis/test/br3392637.asm:13: error: instruction not supported in 16-bit mode +./travis/test/br3392637.asm:16: error: instruction not supported in 16-bit mode +./travis/test/br3392637.asm:17: error: instruction not supported in 16-bit mode +./travis/test/br3392637.asm:18: error: instruction not supported in 16-bit mode +./travis/test/br3392637.asm:24: error: instruction not supported in 16-bit mode +./travis/test/br3392637.asm:25: error: instruction not supported in 16-bit mode +./travis/test/br3392637.asm:27: error: instruction not supported in 16-bit mode +./travis/test/br3392637.asm:28: error: instruction not supported in 16-bit mode +./travis/test/br3392637.asm:29: error: instruction not supported in 16-bit mode +./travis/test/br3392637.asm:34: error: instruction not supported in 16-bit mode +./travis/test/br3392637.asm:35: error: instruction not supported in 16-bit mode +./travis/test/br3392637.asm:37: error: instruction not supported in 16-bit mode +./travis/test/br3392637.asm:38: error: instruction not supported in 16-bit mode +./travis/test/br3392637.asm:39: error: instruction not supported in 16-bit mode +./travis/test/br3392637.asm:43: error: instruction not supported in 16-bit mode