• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

A categorical programming language


Commit MetaInfo

Revisão6bcb0678c358220b39f79aacadb3d72ce9b62456 (tree)
Hora2024-10-27 08:52:08
AutorCorbin <cds@corb...>
CommiterCorbin

Mensagem de Log

Further harden the parser.

This is enough to cause afl-fuzz to find nothing after 10 cycles.

Mudança Sumário

Diff

--- a/cammy/cammylib/parser.py
+++ b/cammy/cammylib/parser.py
@@ -1,5 +1,7 @@
11 from cammylib.sexp import sexp
22
3+from rpython.rlib.objectmodel import specialize
4+from rpython.rlib.rstackovf import StackOverflow, check_stack_overflow
35
46 class ParseError(Exception):
57 def __init__(self, message):
@@ -21,6 +23,7 @@ def makeParser(parserName, buildAtom, buildList):
2123 while self.hasMore() and self._s[self._i] in (" ", "\n"):
2224 self._i += 1
2325
26+ @specialize.arg(1)
2427 def canAndDoesEat(self, c):
2528 if self._s[self._i] == c:
2629 self._i += 1
@@ -33,6 +36,8 @@ def makeParser(parserName, buildAtom, buildList):
3336 while self.hasMore() and self._s[self._i] not in (")", "(", " ", "\n"):
3437 self._i += 1
3538 stop = self._i
39+ if start == stop:
40+ raise ParseError("Expected name starting at %d" % start)
3641 return self._s[start:stop]
3742
3843 def takeExpression(self):
@@ -74,11 +79,16 @@ CammyParser = makeParser("CammyParser", buildCammyAtom, buildCammyTemplate)
7479 def parse(s):
7580 "Parse a Cammy expression, preserving any trailing text."
7681 parser = CammyParser(s)
77- sexp = parser.takeExpression()
78- # Parser is now fast-forwarded to the end of the S-expression, so we can
79- # slice from that point and get the docstring/etc.
80- trail = s[parser.position():]
81- return sexp, trail
82+ try:
83+ sexp = parser.takeExpression()
84+ # Parser is now fast-forwarded to the end of the S-expression, so we can
85+ # slice from that point and get the docstring/etc.
86+ trail = s[parser.position():]
87+ return sexp, trail
88+ except MemoryError: raise ParseError("Out of memory")
89+ except StackOverflow:
90+ check_stack_overflow()
91+ raise ParseError("Stack overflow")
8292
8393
8494 def parseTypes(s):
--- a/cammy/main.py
+++ b/cammy/main.py
@@ -39,16 +39,16 @@ def main(argv):
3939 if len(argv) != l: return help(stderr, exe, "%s takes %d arguments" % (k, l))
4040 try: return action.do(argv)
4141 except ParseError as pe:
42- printErr(stderr, "Could not parse input:", pe.message)
42+ printErr(stderr, "Could not parse input", pe.message)
4343 return 1
4444 except BuildProblem as bp:
45- printErr(stderr, "Could not build arrow:", bp.message)
45+ printErr(stderr, "Could not build arrow", bp.message)
4646 return 1
4747 except UnificationFailed as uf:
48- printErr(stderr, "Could not check type:", uf.message)
48+ printErr(stderr, "Could not check type", uf.message)
4949 return 1
5050 except TypeFail as tf:
51- printErr(stderr, "Type failure:", tf.reason)
51+ printErr(stderr, "Type failure", tf.reason)
5252 return 1
5353 else:
5454 help(stderr, exe, "unknown command: " + command)