Hi,

in locate.c assertions are disabled, because they would fail due to various
off-by-one bugs.

Attached are two patches addressing this:

0004-locate-*: enable assertions to expose the bugs -- many test will FAIL.

0005-locate-*: fix the bugs such that all tests PASS.

I sincerely hope this and my two previous messages (together 5 patches) will
make it into findutils-4.4.X.

Regards
Peter Breitenlohner <[email protected]>
From a571287a155bfa103fe7041a644defefa52f3fd9 Mon Sep 17 00:00:00 2001
From: Peter Breitenlohner <[email protected]>
Date: Mon, 3 Aug 2009 13:30:29 +0200
Subject: [PATCH 4/5] locate: enable assertions to expose bug


Signed-off-by: Peter Breitenlohner <[email protected]>
---
 locate/locate.c |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)

diff --git a/locate/locate.c b/locate/locate.c
index 4f2b1a7..c32db70 100644
--- a/locate/locate.c
+++ b/locate/locate.c
@@ -81,7 +81,6 @@
 
 #include <fcntl.h>
 
-#define NDEBUG
 #include <assert.h>
 #include <string.h>
 
-- 
1.6.4

From 33b3bb4e10ee96bfe5039adffd1cfaa6d2cc23b9 Mon Sep 17 00:00:00 2001
From: Peter Breitenlohner <[email protected]>
Date: Mon, 3 Aug 2009 13:34:08 +0200
Subject: [PATCH 5/5] locate: fix off-by-one bugs and enable assertions


Signed-off-by: Peter Breitenlohner <[email protected]>
---
 ChangeLog       |    5 +++++
 locate/locate.c |   17 ++++++++++++++---
 2 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index caffb69..6e0c530 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2009-08-03  Peter Breitenlohner  <[email protected]>
 
+       * locate/locate.c: Enable assertions and fix the off-by-one
+       bugs that prevented this.
+
+2009-08-03  Peter Breitenlohner  <[email protected]>
+
        * locate/locate.c: Simplify handling of slocate databases.
        Fix the bug assuming second path extends the first one.
        * locate/testsuite/locate.gnu/slocate.{exp,xo}: New testcase
diff --git a/locate/locate.c b/locate/locate.c
index c32db70..d73354c 100644
--- a/locate/locate.c
+++ b/locate/locate.c
@@ -293,7 +293,7 @@ locate_read_str(char **buf, size_t *siz, FILE *fp, int 
delimiter, int offs)
              *buf = pnew;
            }
        }
-      memcpy((*buf)+offs, p, nread);
+      memcpy((*buf)+offs, p, nread + 1);
       free(p);
     }
   return nread;
@@ -583,10 +583,21 @@ visit_locate02_format(struct process_data *procdata, void 
*context)
   nread = locate_read_str (&procdata->original_filename,
                           &procdata->pathsize,
                           procdata->fp, 0, procdata->count);
-  if (nread < 0)
+  if (nread < 1)
     return VISIT_ABORT;
   procdata->c = getc (procdata->fp);
-  procdata->len = procdata->count + nread;
+  procdata->len = procdata->count + nread - 1; /* Number of chars in path. */
+
+  if (procdata->len < 1)
+    {
+      /* This should not happen generally, but since we're
+       * reading in data which is outside our control, we
+       * cannot prevent it.
+       */
+      error(1, 0, _("locate database %s is corrupt or invalid"),
+           quotearg_n_style(0, locale_quoting_style, procdata->dbfile));
+    }
+
   s = procdata->original_filename + procdata->len - 1; /* Move to the last 
char in path.  */
   assert (s[0] != '\0');
   assert (s[1] == '\0'); /* Our terminator.  */
-- 
1.6.4

_______________________________________________
Findutils-patches mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/findutils-patches

Reply via email to