[Libguestfs] [PATCH] common/mlpcre: fix access to freed memory

Pino Toscano ptoscano at redhat.com
Fri Apr 27 14:30:11 UTC 2018


free_last_match() frees the memory of the match passed as argument, so
accessing it is not possible after free_last_match().  Since all we
need is the return code, save it locally for later usage.
---
 common/mlpcre/pcre-c.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/common/mlpcre/pcre-c.c b/common/mlpcre/pcre-c.c
index da982025f..0762a8341 100644
--- a/common/mlpcre/pcre-c.c
+++ b/common/mlpcre/pcre-c.c
@@ -207,8 +207,9 @@ guestfs_int_pcre_matches (value rev, value strv)
 
   m->r = pcre_exec (re, NULL, m->subject, len, 0, 0, m->vec, veclen);
   if (m->r < 0 && m->r != PCRE_ERROR_NOMATCH) {
+    int ret = m->r;
     free_last_match (m);
-    raise_pcre_error ("pcre_exec", m->r);
+    raise_pcre_error ("pcre_exec", ret);
   }
 
   /* This error would indicate that pcre_exec ran out of space in the
-- 
2.14.3




More information about the Libguestfs mailing list