bug-grep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Avoid using an invalid memchr result.


From: Paolo Bonzini
Subject: [PATCH] Avoid using an invalid memchr result.
Date: Tue, 22 Dec 2009 10:01:16 +0100

Related to bug 13161.  I cannot find a testcase, but it is better to be
defensive considering that these bug were found in the past.

This version actually compiles. :-)

* src/search.c (EGexecute, Fexecute): Check for memchr return values.
---
 gnulib       |    2 +-
 src/search.c |   18 ++++++++++++------
 2 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/gnulib b/gnulib
index c5588be..60b0c35 160000
--- a/gnulib
+++ b/gnulib
@@ -1 +1 @@
-Subproject commit c5588be343f580be8e87d99e043dcdf3d7606759
+Subproject commit 60b0c353fb7bc5f8dd35e65df983793251e9efed
diff --git a/src/search.c b/src/search.c
index e4698ff..571b580 100644
--- a/src/search.c
+++ b/src/search.c
@@ -334,8 +334,10 @@ EXECUTE_FCT(EGexecute)
              beg += offset;
              /* Narrow down to the line containing the candidate, and
                 run it through DFA. */
-             end = memchr(beg, eol, buflim - beg);
-             end++;
+             if ((end = memchr(beg, eol, buflim - beg)) != NULL)
+               end++;
+              else
+                end = buflim;
 #ifdef MBS_SUPPORT
              if (MB_CUR_MAX > 1 && mb_properties[beg - buf] == 0)
                continue;
@@ -355,8 +357,10 @@ EXECUTE_FCT(EGexecute)
                break;
              /* Narrow down to the line we've found. */
              beg += offset;
-             end = memchr (beg, eol, buflim - beg);
-             end++;
+             if ((end = memchr(beg, eol, buflim - beg)) != NULL)
+               end++;
+              else
+                end = buflim;
              while (beg > buf && beg[-1] != eol)
                --beg;
            }
@@ -594,8 +598,10 @@ EXECUTE_FCT(Fexecute)
   goto out;
 
  success:
-  end = memchr (beg + len, eol, (buf + size) - (beg + len));
-  end++;
+  if ((end = memchr (beg + len, eol, (buf + size) - (beg + len))) != NULL)
+    end++;
+  else
+    end = buf + size;
   while (buf < beg && beg[-1] != eol)
     --beg;
   len = end - beg;
-- 
1.6.5.2





reply via email to

[Prev in Thread] Current Thread [Next in Thread]