Fix signalling simple error with #\~ in format string

(Alan Ruttenberg)

Signaling an simple error would signal another error if the message
happened to have a ~ in it, since in simple cases there are no format
args, but format is called with the message string.

We fix this by changing all cases in the source where there were calls
to setFormatControl(x) are followed by setFormatArguments(NIL). In
such cases we changed setFormatControl(x) ->
setFormatControl(x.replaceAll("~","~~")), which is the CL:FORMAT
recipe for escaping a #\~ character.

To replicate this error, place the following in a file
<file:~/work/abcl/double-error.lisp>.

    (defun foo (x) (funcall x))

then

    CL-USER> (compile-file "~/work/abcl/double-error")
    ; Compiling /Users/evenson/work/abcl/double-error.lisp ...
    ; (DEFUN FOO ...)
    ; Wrote /Users/evenson/work/abcl/double-error.abcl (0.015 seconds)
    #P"/Users/evenson/work/abcl/double-error.abcl"
    NIL
    NIL
    CL-USER> (foo '~)

gives

    Error (FORMAT-ERROR) during printing: #<PROGRAM-ERROR {264F63C5}>
       [Condition of type PROGRAM-ERROR]

Merges <https://github.com/armedbear/abcl/pull/41>.
parent 00d81d39
......@@ -72,7 +72,7 @@ public class ArithmeticError extends LispError
public ArithmeticError(String message)
{
super(StandardClass.ARITHMETIC_ERROR);
setFormatControl(message);
setFormatControl(message.replaceAll("~","~~"));
setFormatArguments(NIL);
setOperation(NIL);
setOperands(NIL);
......
......@@ -98,7 +98,7 @@ public class Condition extends StandardObject
{
super(StandardClass.CONDITION);
Debug.assertTrue(slots.length == 2);
setFormatControl(message);
setFormatControl(message.replaceAll("~","~~"));
setFormatArguments(NIL);
}
......
......@@ -46,7 +46,7 @@ public final class ControlError extends LispError
public ControlError(String message)
{
super(StandardClass.CONTROL_ERROR);
setFormatControl(message);
setFormatControl(message.replaceAll("~","~~"));
setFormatArguments(NIL);
}
......
......@@ -67,7 +67,7 @@ public final class FileError extends LispError
public FileError(String message)
{
super(StandardClass.FILE_ERROR);
setFormatControl(message);
setFormatControl(message.replaceAll("~","~~"));
setFormatArguments(NIL);
setPathname(NIL);
}
......@@ -76,7 +76,7 @@ public final class FileError extends LispError
{
super(StandardClass.FILE_ERROR);
setFormatControl(message);
setFormatControl(message.replaceAll("~","~~"));
setFormatArguments(NIL);
setPathname(pathname);
}
......
......@@ -43,7 +43,7 @@ public final class IllegalMonitorState extends ProgramError
// This is really just an ordinary PROGRAM-ERROR, broken out into its
// own Java class as a convenience for the implementation.
super(StandardClass.PROGRAM_ERROR);
setFormatControl(getMessage());
setFormatControl(getMessage().replaceAll("~","~~"));
setFormatArguments(NIL);
}
......@@ -55,7 +55,7 @@ public final class IllegalMonitorState extends ProgramError
if (message != null) {
this.message = message;
}
setFormatControl(getMessage());
setFormatControl(getMessage().replaceAll("~","~~"));
setFormatArguments(NIL);
}
......
......@@ -40,7 +40,7 @@ public final class ParseError extends LispError
public ParseError(String message)
{
super(StandardClass.PARSE_ERROR);
setFormatControl(message);
setFormatControl(message.replaceAll("~","~~"));
setFormatArguments(NIL);
}
......
......@@ -57,7 +57,7 @@ public class ProgramError extends LispError
public ProgramError(String message)
{
super(StandardClass.PROGRAM_ERROR);
setFormatControl(message);
setFormatControl(message.replaceAll("~","~~"));
setFormatArguments(NIL);
}
......
......@@ -40,14 +40,14 @@ public final class ReaderError extends StreamError
public ReaderError(String message)
{
super(StandardClass.READER_ERROR);
setFormatControl(message);
setFormatControl(message.replaceAll("~","~~"));
setFormatArguments(NIL);
}
public ReaderError(String message, Stream stream)
{
super(StandardClass.READER_ERROR);
setFormatControl(message);
setFormatControl(message.replaceAll("~","~~"));
setFormatArguments(NIL);
setStream(stream);
}
......
......@@ -54,7 +54,7 @@ public final class SimpleError extends LispError
public SimpleError(String message)
{
super(StandardClass.SIMPLE_ERROR);
setFormatControl(message);
setFormatControl(message.replaceAll("~","~~"));
setFormatArguments(NIL);
}
......
......@@ -48,7 +48,7 @@ public class StreamError extends LispError
public StreamError(String message)
{
super(StandardClass.STREAM_ERROR);
setFormatControl(message);
setFormatControl(message.replaceAll("~","~~"));
setFormatArguments(NIL);
setStream(NIL);
cause = null;
......@@ -64,7 +64,7 @@ public class StreamError extends LispError
public StreamError(String message, Stream stream)
{
super(StandardClass.STREAM_ERROR);
setFormatControl(message);
setFormatControl(message.replaceAll("~","~~"));
setFormatArguments(NIL);
setStream(stream != null ? stream : NIL);
cause = null;
......@@ -95,7 +95,7 @@ public class StreamError extends LispError
public StreamError(Stream stream, String message)
{
super(StandardClass.STREAM_ERROR);
setFormatControl(message);
setFormatControl(message.replaceAll("~","~~"));
setFormatArguments(NIL);
setStream(stream != null ? stream : NIL);
cause = null;
......@@ -106,7 +106,7 @@ public class StreamError extends LispError
super(StandardClass.STREAM_ERROR);
setStream(stream != null ? stream : NIL);
String message = cause.getMessage();
setFormatControl(message != null ? message : cause.toString());
setFormatControl(message != null ? message.replaceAll("~","~~") : cause.toString().replaceAll("~","~~"));
setFormatArguments(NIL);
this.cause = cause;
}
......
......@@ -56,7 +56,7 @@ public final class WrongNumberOfArgumentsException extends ProgramError
this.expectedMinArgs = expectedMin;
this.expectedMaxArgs = expectedMax;
this.actualArgs = args;
setFormatControl(getMessage());
setFormatControl(getMessage().replaceAll("~","~~"));
setFormatArguments(NIL);
}
......@@ -80,7 +80,7 @@ public final class WrongNumberOfArgumentsException extends ProgramError
throw new NullPointerException("message can not be null");
}
this.message = message;
setFormatControl(getMessage());
setFormatControl(getMessage().replaceAll("~","~~"));
setFormatArguments(NIL);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment