src: Improve S-expression parsing.
authorJustus Winter <justus@g10code.com>
Thu, 14 Apr 2016 11:53:55 +0000 (13:53 +0200)
committerJustus Winter <justus@g10code.com>
Thu, 14 Apr 2016 14:36:03 +0000 (16:36 +0200)
* src/sexp.c (do_vsexp_sscan): Return an error if a closing
parenthesis is encountered with no matching opening parenthesis.

Signed-off-by: Justus Winter <justus@g10code.com>
src/sexp.c

index 636f922..6077bab 100644 (file)
@@ -1592,6 +1592,13 @@ do_vsexp_sscan (gcry_sexp_t *retsexp, size_t *erroff,
              err = GPG_ERR_SEXP_UNMATCHED_DH;
               goto leave;
            }
+
+         if (level == 0)
+           {
+             *erroff = p - buffer;
+             err = GPG_ERR_SEXP_UNMATCHED_PAREN;
+             goto leave;
+           }
          MAKE_SPACE (0);
          *c.pos++ = ST_CLOSE;
          level--;