Skip to content

Commit

Permalink
Fixed a buffer over flow bug. Issue 119 pointed out by mrc.mgg.
Browse files Browse the repository at this point in the history
  • Loading branch information
higepon committed Dec 3, 2009
1 parent bb6564e commit 3e30672
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 13 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
2009-12-03 higepon <higepon@users.sourceforge.jp>

* src/scanner.re (Scanner::currentToken): Fixed a buffer over flow bug. Issue 119 pointed out by mrc.mgg.

* lib/psyntax/psyntax/main.ss (lambda): Changed a behavior of default current-exception-handler. Issue 117 pointed out by mrc.mgg.

Expand Down
19 changes: 12 additions & 7 deletions src/Reader.y
Original file line number Diff line number Diff line change
Expand Up @@ -170,17 +170,22 @@ int yyerror(char const *str)
{
TextualInputPort* const port = currentVM()->readerContext()->port();
const Object prevError = port->error();
ucs4string currentToken = port->scanner()->currentToken();
if (currentToken.empty()) {
currentToken = UC("<end of file>");
}
if (prevError.isNil()) {
port->setError(format(NULL, UC("~a: ~a near [~a] at ~a:~d. "),
Pair::list5(prevError,
str,
Object::makeString(port->scanner()->currentToken()),
port->setError(format(NULL, UC("~a near [~a] at ~a:~d. "),
Pair::list4(str,
Object::makeString(currentToken),
port->toString(),
Object::makeFixnum(port->getLineNo()))));

} else {
port->setError(format(NULL, UC("~a near [~a] at ~a:~d. "),
Pair::list4(str,
Object::makeString(port->scanner()->currentToken()),
port->setError(format(NULL, UC("~a: ~a near [~a] at ~a:~d. "),
Pair::list5(prevError,
str,
Object::makeString(currentToken),
port->toString(),
Object::makeFixnum(port->getLineNo()))));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Scanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Scanner EXTEND_GC {
void fill(int n);
void emptyBuffer();
int scan(YYSTYPE* yylval);
ucs4char* currentToken() const;
ucs4string currentToken() const;

private:

Expand Down
6 changes: 4 additions & 2 deletions src/Transcoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,9 @@ void Transcoder::putChar(BinaryOutputPort* port, ucs4char c)

void Transcoder::unGetChar(ucs4char c)
{
if (EOF == c) return;
if (EOF == c) {
return;
}
buffer_ += c;
if (c == EolStyle(LF)) {
lineNo_--;
Expand Down Expand Up @@ -237,7 +239,7 @@ ucs4char Transcoder::getChar(BinaryInputPort* port)
case EolStyle(NEL):
case EolStyle(LS):
{
lineNo_++;
lineNo_++;
return EolStyle(LF);
}
case EolStyle(CR):
Expand Down
5 changes: 3 additions & 2 deletions src/scanner.re
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,8 @@ comment:
}
}

ucs4char* Scanner::currentToken() const
ucs4string Scanner::currentToken() const
{
return token_;
MOSH_ASSERT(limit_ > token_);
return ucs4string(token_, limit_ - token_);
}
10 changes: 9 additions & 1 deletion src/work.scm
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
;;;!mosh

(import (rnrs))
(display "\x0;\x1;\x80;\xFF;\xD7FF;\xE000;\x10FFFF;")
(define b 2)
+-3
(define a 3)
;;; end of file
;; Local Variables:
;; coding: utf-8-unix
;; End:

0 comments on commit 3e30672

Please sign in to comment.