Subject: bug#23159: 24.5; --eval bug

From: [email-masked]
Date: Wed, 06 Jul 2016 21:12:44 -0400

[email-masked] writes:

> Devon Sean McCullough <[email-masked]> writes:
>
>> I’d suggest (error "Trailing garbage following expression”)
>> for consistency with the eval-expression function.
>
> Makes sense.

Oops, I didn't actually change warning to error.  One more try.

>From cf22d9210d09b936d8f734aedb6a76e12830c690 Mon Sep 17 00:00:00 2001
From: Noam Postavsky <[email-masked]>
Date: Sat, 2 Jul 2016 20:26:35 -0400
Subject: [PATCH v3] Error if --eval arg has text beyond 1 expression

* lisp/startup.el (command-line-1): If --eval argument has more data
than constitutes a single Lisp expression, signal an error (Bug #23159).
---
 lisp/startup.el | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/lisp/startup.el b/lisp/startup.el
index 761e69e..fcdc376 100644
--- a/lisp/startup.el
+++ b/lisp/startup.el
@@ -2360,7 +2360,14 @@ command-line-1
 
                     ((member argi '("-eval" "-execute"))
                      (setq inhibit-startup-screen t)
-                     (eval (read (or argval (pop command-line-args-left)))))
+                     (let* ((str-expr (or argval (pop command-line-args-left)))
+                            (read-data (read-from-string str-expr))
+                            (expr (car read-data))
+                            (end (cdr read-data)))
+                       (unless (= end (length str-expr))
+                         (error "Trailing garbage following expression: %s"
+                                (substring str-expr end)))
+                       (eval expr)))
 
                     ((member argi '("-L" "-directory"))
                      ;; -L :/foo adds /foo to the _end_ of load-path.
-- 
2.8.0