tree-sitter-grammars / tree-sitter-hcl

HCL grammar for tree-sitter
https://tree-sitter-grammars.github.io/tree-sitter-hcl/
Apache License 2.0
92 stars 20 forks source link

fix(scanner): fix segfault #40

Closed mhoffm-aiven closed 10 months ago

mhoffm-aiven commented 10 months ago

@amaanq can you have a look please? I copied over the macros from bash and fixed the string handling in the contexts ( i think ).

Valgrind seems happy and gdb seems happy with the repro

$ docker run --env TREE_SITTER_HCL_REF="mhoffm-fix-segfault" -it emacs-29-bugreport-pgtk:latest     gdb --args emacs --batch -l minimal-reproduce.el
GNU gdb (GDB) Fedora Linux 13.2-6.fc38
Copyright (C) 2023 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from emacs...
(gdb) r
Starting program: /usr/local/bin/emacs --batch -l minimal-reproduce.el
warning: Error disabling address space randomization: Operation not permitted
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
Missing separate debuginfo for /lib64/libwayland-client.so.0
Try: dnf --enablerepo='*debug*' install /usr/lib/debug/.build-id/8f/223d7d413dd53824844e75fd05ae04a70176c0.debug
Missing separate debuginfo for /lib64/libwayland-egl.so.1
Try: dnf --enablerepo='*debug*' install /usr/lib/debug/.build-id/f9/f3cc8549fe242cd014a4645b53ca3504d5f25e.debug
Cloning repository
[Detaching after vfork from child process 19]
Compiling library
[Detaching after vfork from child process 30]
[Detaching after vfork from child process 33]
[Detaching after vfork from child process 36]
Library installed to ~/.emacs.d/tree-sitter/libtree-sitter-hcl.so
[Inferior 1 (process 16) exited normally]
Missing separate debuginfos, use: dnf debuginfo-install liblerc-4.0.0-3.fc38.x86_64 lz4-libs-1.9.4-2.fc38.x86_64 ncurses-libs-6.4-3.20230114.fc38.x86_64 nettle-3.8-3.fc38.x86_64 systemd-libs-253.10-1.fc38.x86_64
(gdb)
MichaHoffmann commented 10 months ago

@erik-overdahl can you check this branch out and verify please?

MichaHoffmann commented 10 months ago

@amaanq the memcpy in context_new looked fishy to me! maybe a "STRING_GROW" would have fixed it too though.

amaanq commented 10 months ago

That makes sense, I sorta translated the C++ scanner to C almost verbatim and didn't think about bits that shouldn't have made it through or should've been tweaked a bit...good catch! (But Bash is just very different in general because heredocs can be nested)

I have no idea what's up with the windows gcc CI failure

mhoffm-aiven commented 10 months ago

Yeah but the macros probably should be fairly similar! The windows ci failure is the action not being able to start. I assume it's too old of a version, I'll fix it in subsequent PR

amaanq commented 10 months ago

Yep I agree they should be similar, I think not putting in default strings in a new context is the actual fix, but this and your other macro changes to be similar to bash LGTM!