DanielGavin / ols

Language server for Odin
MIT License
417 stars 62 forks source link

ols crash #254

Closed noj closed 11 months ago

noj commented 11 months ago

Hi!

I am starting to look in to Odin and wanted to try the language server, trying out the latest release from GitHub, I can easily crash the language server by simply starting the server and pressing enter, like so:

% ./ols-x86_64-darwin

/Users/runner/work/ols/ols/src/server/requests.odin(175:35) Index -1 is out of range 0..<1
zsh: illegal hardware instruction  ./ols-x86_64-darwin

I think this is the fix for the issue, but can't confirm since I am unable to compile ols with the version of Odin shipped with homebrew (odin version dev-2023-08:9453b238)

Proposed fix:

diff --git a/src/server/requests.odin b/src/server/requests.odin
index 257baef..3751842 100644
--- a/src/server/requests.odin
+++ b/src/server/requests.odin
@@ -172,7 +172,7 @@ read_and_parse_header :: proc(reader: ^Reader) -> (Header, bool) {

                message := strings.to_string(builder)

-               if len(message) == 0 || message[len(message) - 2] != '\r' {
+               if len(message) < 2 || message[len(message) - 2] != '\r' {
                        log.error("No carriage return")
                        return header, false
                }
DanielGavin commented 11 months ago

Sure it would fix that case. But the client would never send that. I'll add it for robustness, but it should not make any difference for actual LSP clients.

Thanks.