Skip to content

this simple function always segfaults - at least on linux amd64

The function eul-safe-eval evaluates input string and always outputs a string, either result of evaluation or error message. The function with "`" input segfaults regardless if interpreted or compiled. Whole session follows:

$ ecl
ECL (Embeddable Common-Lisp) 16.0.0 (git:UNKNOWN)
Copyright (C) 1984 Taiichi Yuasa and Masami Hagiya
Copyright (C) 1993 Giuseppe Attardi
Copyright (C) 2000 Juan J. Garcia-Ripoll
Copyright (C) 2015 Daniel Kochmanski
ECL is free software, and you are welcome to redistribute it
under certain conditions; see file 'Copyright' for details.
Type :h for Help.  
Top level in: #<process TOP-LEVEL>.
>>  (defun eul-safe-eval (str)
  (let ((parsed (multiple-value-list(IGNORE-ERRORS (read-from-string str)))))
  (if (typep (cadr parsed) 'INTEGER) 
    (let ((result (multiple-value-list(IGNORE-ERRORS (EVAL (car parsed))))))
      (if (eql (cdr result) nil) 
        (write-to-string(car result))
        (concatenate 'string "Evaluation error: " (write-to-string (cadr result)))))
   (concatenate 'string "Malformed expression: " (write-to-string(cadr parsed)))
  )))

EUL-SAFE-EVAL
>> (eul-safe-eval "`")

Debugger received error of type: SEGMENTATION-VIOLATION
Detected access to an invalid or protected memory address.
Error flushed.