[PATCH] src: Improve S-expression parsing.

Justus Winter justus at g10code.com
Thu Apr 14 14:04:49 CEST 2016


* 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 at g10code.com>
---
 src/sexp.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/src/sexp.c b/src/sexp.c
index 636f922..6077bab 100644
--- a/src/sexp.c
+++ b/src/sexp.c
@@ -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--;
-- 
2.1.4




More information about the Gcrypt-devel mailing list