Jsonrpc: don't bind inhibit-read-only to t so early

Related to https://github.com/joaotavora/eglot/discussions/1202, where
because of this very wide binding to inhibit-read-only to t, Eglot was
managing to write into read-only buffers from the response handlers
that ran from within the stack of the jsonrpc.el process filter.

This is of course illegal and dangerous, but Eglot wasn't made aware
because of the binding.

* lisp/jsonrpc.el (jsonrpc--process-filter): Don't bind
inhibit-read-only so early.
This commit is contained in:
João Távora 2023-04-07 19:33:12 +01:00
parent cb8c87a423
commit 88847dee12

View file

@ -566,15 +566,14 @@ With optional CLEANUP, kill any associated buffers."
(cl-return-from jsonrpc--process-filter)) (cl-return-from jsonrpc--process-filter))
(when (buffer-live-p (process-buffer proc)) (when (buffer-live-p (process-buffer proc))
(with-current-buffer (process-buffer proc) (with-current-buffer (process-buffer proc)
(let* ((inhibit-read-only t) (let* ((jsonrpc--in-process-filter t)
(jsonrpc--in-process-filter t)
(connection (process-get proc 'jsonrpc-connection)) (connection (process-get proc 'jsonrpc-connection))
(expected-bytes (jsonrpc--expected-bytes connection))) (expected-bytes (jsonrpc--expected-bytes connection)))
;; Insert the text, advancing the process marker. ;; Insert the text, advancing the process marker.
;; ;;
(save-excursion (save-excursion
(goto-char (process-mark proc)) (goto-char (process-mark proc))
(insert string) (let ((inhibit-read-only t)) (insert string))
(set-marker (process-mark proc) (point))) (set-marker (process-mark proc) (point)))
;; Loop (more than one message might have arrived) ;; Loop (more than one message might have arrived)
;; ;;
@ -623,7 +622,8 @@ With optional CLEANUP, kill any associated buffers."
(jsonrpc-connection-receive connection (jsonrpc-connection-receive connection
json-message))))) json-message)))))
(goto-char message-end) (goto-char message-end)
(delete-region (point-min) (point)) (let ((inhibit-read-only t))
(delete-region (point-min) (point)))
(setq expected-bytes nil)))) (setq expected-bytes nil))))
(t (t
;; Message is still incomplete ;; Message is still incomplete