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

Do not crash LSP server on malformed Content-Length #2526

Merged
merged 3 commits into from
Apr 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/fstar/FStar.Interactive.Lsp.fst
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,9 @@ let rec parse_header_len (stream: stream_reader) (len: int): int =
match U.read_line stream with
| Some s ->
if U.starts_with s "Content-Length: " then
parse_header_len stream (U.int_of_string (U.substring_from s 16))
match U.safe_int_of_string (U.substring_from s 16) with
| Some new_len -> parse_header_len stream new_len
| None -> raise MalformedHeader
else if U.starts_with s "Content-Type: " then
parse_header_len stream len
else if s = "" then
Expand Down
9 changes: 7 additions & 2 deletions src/ocaml-output/FStar_Interactive_Lsp.ml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ bug-reports \
error-messages \
friends \
incl \
interactive \
ide \
machine_integers \
micro-benchmarks \
prettyprinting \
Expand Down
15 changes: 15 additions & 0 deletions tests/ide/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FSTAR_HOME=../..
include ../../examples/Makefile.include

ALL_TEST_DIRS=\
lsp \
emacs

all: $(addsuffix .all, $(ALL_TEST_DIRS))
clean: $(addsuffix .clean, $(ALL_TEST_DIRS))

%.all: %
+$(MAKE) -C $^ all

%.clean: %
+$(MAKE) -C $^ clean
15 changes: 3 additions & 12 deletions tests/interactive/Makefile → tests/ide/Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -37,29 +37,20 @@ touch:

%.in: .FORCE

FSTAR_HOME = ../..
FSTAR_HOME = ../../..
include $(FSTAR_HOME)/ulib/gmake/z3.mk

ifdef Z3
SMT=--smt $(Z3)
endif

FSTAR:=${FSTAR_HOME}/bin/fstar.exe $(SMT) --ide --warn_error -282


# Feed .in to F* and record output as .out. Output is passed through cleanup.py
# to ensure that the output is deterministic by pretty-printing JSON messages
# (otherwise the order of fields in JSON dictionaries might vary across runs)
# We turn off the .checked file cache so we don't get any races in CI
%.out: %.in $(FSTAR_HOME)/bin/fstar.exe
$(eval FST := $(firstword $(subst ., ,$<)))
$(FSTAR) --cache_off "$(realpath ${FST}.fst)" < "$<" | python cleanup.py "$@"
JSON_CLEANUP:=python ../cleanup.py

# Clean up and accept an existing ‘.out’ file (possibly generated by
# ‘fstar-write-transcript’, or possibly by ‘make build’) and save it as
# ‘.out.expected’.
%.out.accept: %.out
python cleanup.py "$<.expected" < "$<"
$(JSON_CLEANUP) "$<.expected" < "$<"

# Verify that a given output matches the corresponding input
%.out.check: %.out %.out.expected
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
11 changes: 11 additions & 0 deletions tests/ide/emacs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
include ../Makefile.common

FSTAR:=${FSTAR_HOME}/bin/fstar.exe $(SMT) --ide --warn_error -282

# Feed .in to F* and record output as .out. Output is passed through cleanup.py
# to ensure that the output is deterministic by pretty-printing JSON messages
# (otherwise the order of fields in JSON dictionaries might vary across runs)
# We turn off the .checked file cache so we don't get any races in CI
%.out: %.in $(FSTAR_HOME)/bin/fstar.exe
$(eval FST := $(firstword $(subst ., ,$<)))
$(FSTAR) --cache_off "$(realpath ${FST}.fst)" < "$<" | $(JSON_CLEANUP) "$@"
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions tests/ide/lsp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.out
*.out.check
11 changes: 11 additions & 0 deletions tests/ide/lsp/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
include ../Makefile.common

FSTAR:=${FSTAR_HOME}/bin/fstar.exe $(SMT) --lsp --warn_error -282

# Feed .in to F* and record output as .out. Output is passed through cleanup.py
# to ensure that the output is deterministic by pretty-printing JSON messages
# (otherwise the order of fields in JSON dictionaries might vary across runs)
# We turn off the .checked file cache so we don't get any races in CI
%.out: %.in $(FSTAR_HOME)/bin/fstar.exe
$(FSTAR) < "$<" 2>&1 | $(JSON_CLEANUP) "$@"

4 changes: 4 additions & 0 deletions tests/ide/lsp/broken_content_length.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Content-Length: a
Content-Length: 46

{"jsonrpc":"2.0","method":"exit","params":{}}
1 change: 1 addition & 0 deletions tests/ide/lsp/broken_content_length.out.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[E] Malformed Content Header
3 changes: 3 additions & 0 deletions tests/ide/lsp/exit.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Content-Length: 46

{"jsonrpc":"2.0","method":"exit","params":{}}
Empty file added tests/ide/lsp/exit.out.expected
Empty file.