From c0b597a760ea6fc1ff80e9e2543645b781c6b3e2 Mon Sep 17 00:00:00 2001
From: Peter Breitenlohner
Date: Mon, 3 Aug 2009 13:23:42 +0200
Subject: [PATCH 3/5] slocate: simplify and bug fix
Signed-off-by: Peter Breitenlohner
---
ChangeLog | 8 ++++++++
locate/locate.c | 50 +++++++++-----------------------------------------
2 files changed, 17 insertions(+), 41 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index fd14c44..caffb69 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
2009-08-03 Peter Breitenlohner
+ * 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
+ for slocate databse, exposing this bug.
+ * locate/testsuite/Makefile.am: Add new test case.
+
+2009-08-03 Peter Breitenlohner
+
* doc/find.texi: Remove duplicate paragraph and fix a typo.
2009-07-18 James Youngman
diff --git a/locate/locate.c b/locate/locate.c
index c01f6c2..4f2b1a7 100644
--- a/locate/locate.c
+++ b/locate/locate.c
@@ -330,7 +330,6 @@ struct regular_expression
struct process_data
{
int c; /* An input byte. */
- char itemcount; /* Indicates we're at the beginning of an slocate db. */
int count; /* The length of the prefix shared with the previous database entry. */
int len;
char *original_filename; /* The current input database entry. */
@@ -338,7 +337,6 @@ struct process_data
char *munged_filename; /* path or basename(path) */
FILE *fp; /* The pathname database. */
const char *dbfile; /* Its name, or "" */
- int slocatedb_format; /* Allows us to cope with slocate's format variant */
GetwordEndianState endian_state;
/* for the old database format,
the first and second characters of the most common bigrams. */
@@ -565,37 +563,12 @@ visit_locate02_format(struct process_data *procdata, void *context)
int nread;
(void) context;
- if (procdata->slocatedb_format)
- {
- if (procdata->itemcount == 0)
- {
- ungetc(procdata->c, procdata->fp);
- procdata->count = 0;
- procdata->len = 0;
- }
- else if (procdata->itemcount == 1)
- {
- procdata->count = procdata->len-1;
- }
- else
- {
- if (procdata->c == LOCATEDB_ESCAPE)
- procdata->count += (short)get_short (procdata->fp);
- else if (procdata->c > 127)
- procdata->count += procdata->c - 256;
- else
- procdata->count += procdata->c;
- }
- }
- else
- {
if (procdata->c == LOCATEDB_ESCAPE)
procdata->count += (short)get_short (procdata->fp);
else if (procdata->c > 127)
procdata->count += procdata->c - 256;
else
procdata->count += procdata->c;
- }
if (procdata->count > procdata->len || procdata->count < 0)
{
@@ -622,16 +595,6 @@ visit_locate02_format(struct process_data *procdata, void *context)
procdata->munged_filename = procdata->original_filename;
- if (procdata->slocatedb_format)
- {
- /* Don't increment indefinitely, it might overflow. */
- if (procdata->itemcount < 6)
- {
- ++(procdata->itemcount);
- }
- }
-
-
return VISIT_CONTINUE;
}
@@ -1065,6 +1028,7 @@ search_one_database (int argc,
struct process_data procdata; /* Storage for data shared with visitors. */
int slocate_seclevel;
int oldformat;
+ int slocatedb_format;
struct visitor* pvis; /* temp for determining past_pat_inspector. */
const char *format_name;
enum ExistenceCheckType do_check_existence;
@@ -1085,8 +1049,6 @@ search_one_database (int argc,
oldformat = 0;
procdata.endian_state = GetwordEndianStateInitial;
procdata.len = procdata.count = 0;
- procdata.slocatedb_format = 0;
- procdata.itemcount = 0;
procdata.dbfile = dbfile;
procdata.fp = fp;
@@ -1164,13 +1126,13 @@ search_one_database (int argc,
}
add_visitor(visit_locate02_format, NULL);
format_name = "slocate";
- procdata.slocatedb_format = 1;
+ slocatedb_format = 1;
}
else
{
int nread2;
- procdata.slocatedb_format = 0;
+ slocatedb_format = 0;
extend (&procdata, sizeof(LOCATEDB_MAGIC), 0u);
nread2 = fread (procdata.original_filename+nread, 1, sizeof (LOCATEDB_MAGIC)-nread,
procdata.fp);
@@ -1352,6 +1314,12 @@ search_one_database (int argc,
procdata.c = getc (procdata.fp);
+ if (slocatedb_format && (procdata.c != EOF))
+ {
+ /* Make slocate database look like GNU locate database. */
+ ungetc(procdata.c, procdata.fp);
+ procdata.c = 0;
+ }
/* If we are searching for filename patterns, the inspector list
* will contain an entry for each pattern for which we are searching.
*/
--
1.6.4