Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unclosed parens followed by EOF cause a crash #71

Open
tari opened this issue Sep 2, 2023 · 0 comments · May be fixed by #72
Open

Unclosed parens followed by EOF cause a crash #71

tari opened this issue Sep 2, 2023 · 0 comments · May be fixed by #72

Comments

@tari
Copy link
Contributor

tari commented Sep 2, 2023

A file containing only the string b( (no newline) causes the assembler to crash. Stack trace looks like this:

Pass one...

Program received signal SIGSEGV, Segmentation fault.
__strlen_avx2 () at ../sysdeps/x86_64/multiarch/strlen-avx2.S:76
76              VPCMPEQ (%rdi), %ymm0, %ymm1
(gdb) where
#0  __strlen_avx2 () at ../sysdeps/x86_64/multiarch/strlen-avx2.S:76
#1  0x00007ffff70606e9 in __printf_buffer (buf=buf@entry=0x7fffffffcbe0, format=0x555555578e88 "The opcode %s was given invalid operands",
    ap=0x7fffffffce80, mode_flags=mode_flags@entry=0) at /usr/src/debug/glibc/glibc/stdio-common/vfprintf-process-arg.c:435
#2  0x00007ffff7081535 in __vsnprintf_internal (mode_flags=0, args=<optimized out>, format=<optimized out>, maxlen=<optimized out>, string=<optimized out>)
    at vsnprintf.c:96
#3  ___vsnprintf (string=<optimized out>, maxlen=<optimized out>, format=<optimized out>, args=<optimized out>) at vsnprintf.c:103
#4  0x0000555555574a9a in SetLastSPASMProblem(DWORD, bool, typedef __va_list_tag __va_list_tag *) (dwErrorCode=272, fIsWarning=false, valist=0x7fffffffce80)
    at errors.cpp:351
#5  0x0000555555574d8f in SetLastSPASMError (dwErrorCode=272) at errors.cpp:395
#6  0x00005555555655bd in handle_opcode_or_macro (ptr=0x5555555aa082 "\n") at pass_one.cpp:344
#7  0x0000555555564f88 in run_first_pass_line_sec (ptr=0x5555555aa080 "b(\n") at pass_one.cpp:204
#8  0x0000555555564eaa in run_first_pass_line (ptr=0x5555555aa080 "b(\n") at pass_one.cpp:173
#9  0x0000555555564def in run_first_pass (ptr=0x5555555aa080 "b(\n") at pass_one.cpp:141
#10 0x000055555556395c in run_assembly () at main.cpp:119
#11 0x000055555556461f in main (argc=2, argv=0x7fffffffe5c8) at main.cpp:449

It looks like this is some kind of varargs misuse, since it seems to bomb out when formatting The opcode %s was given invalid operands and it looks like the parameter is null.

tari added a commit to tari/spasm-ng that referenced this issue Sep 3, 2023
When unable to parse an operand to something that appears
to be a macro, ensure the required string for the error message is
passed. Failing to do so causes undefined behavior when the error
message is formatted, and reliably crashes.

Fixes alberthdev#71.
@tari tari linked a pull request Sep 3, 2023 that will close this issue
tari added a commit to tari/spasm-ng that referenced this issue Sep 3, 2023
When unable to parse an operand to something that appears
to be a macro, ensure the required string for the error message is
passed. Failing to do so causes undefined behavior when the error
message is formatted, and reliably crashes.

Fixes alberthdev#71.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant