bug-findutils
[Top][All Lists]
Advanced

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

Locate: Diverse issues (with patches).


From: Bas van Gompel
Subject: Locate: Diverse issues (with patches).
Date: Thu, 23 Dec 2004 09:49:42 +0100 (MET)
User-agent: slrn/0.9.8.1 (Win32) Hamster/2.0.6.0 Korrnews/4.2

Hallo,

Following patches address some issues with locate.c:
(The patches can be applied in sequence, from top down.
(They start at the cvs-version (1.28).))


First, when the next filename is shorter, the tail can
still be matched when ignoring case and not globbing:

--
$ echo '12
a' |frcode >testdb
$ locate -id testdb 2
12
a
--

This is caused by lc_strcpy not zero-terminating its output.


2004-12-23  Bas van Gompel  <address@hidden>

        * locate.c (lc_strcpy): Zero-terminate result.


--- findutils-4.2.10-6/locate/locate.c  2004-12-23 01:59:46.000000000 +0100
+++ findutils-4.2.10-6/locate/locate.c  2004-12-23 03:10:14.000000000 +0100
@@ -222,6 +222,7 @@ lc_strcpy(char *dest, const char *src)
       *dest++ = TOLOWER(*src);
       ++src;
     }
+  *dest = '\0';
 }
 
 enum visit_result


Second, only the first and last ``visitor'' would get executed, because
``lastinspector'' did not get updated.


2004-12-23  Bas van Gompel  <address@hidden>

        * locate.c (add_visitor): Update lastinspector.


--- findutils-4.2.10-6/locate/locate.c  2004-12-23 01:59:46.000000000 +0100
+++ findutils-4.2.10-6/locate/locate.c  2004-12-23 03:10:14.000000000 +0100
@@ -303,6 +303,7 @@ add_visitor(visitfunc fn, void *context)
   else
     {
       lastinspector->next = p;
+      lastinspector = p;
     }
 }
 

Then, in visit_substring_match_casefold there is a buffer for which
len+1 bytes were allocated, but the check was for len.


2004-12-23  Bas van Gompel  <address@hidden>

        * locate.c (visit_substring_match_casefold): fix one-off.


--- findutils-4.2.10-6/locate/locate.c  2004-12-23 01:59:46.000000000 +0100
+++ findutils-4.2.10-6/locate/locate.c  2004-12-23 03:10:14.000000000 +0100
@@ -355,7 +355,7 @@ visit_substring_match_casefold(const cha
   size_t len = strlen(testname);
 
   (void) printname;
-  if (len > p->buffersize)
+  if (len+1 > p->buffersize)
     {
       p->buffer = xrealloc(p->buffer, len+1);
       p->buffersize = len+1;


Next, in the spirit of find, try to stat as little as possible.


2004-12-23  Bas van Gompel  <address@hidden>

        * locate.c (new_locate): Move visit_exists down.


@@ -479,9 +479,6 @@ new_locate (char *pathpart,
     }
   else
     {
-      if (check_existence)
-       add_visitor(visit_exists, NULL);
-
       if (contains_metacharacter(pathpart))
        {
          if (ignore_case)
@@ -504,7 +507,10 @@ new_locate (char *pathpart,
              add_visitor(visit_substring_match_nocasefold, pathpart);
            }
        }
-      
+
+      if (check_existence)
+       add_visitor(visit_exists, NULL);
+
       if (enable_print)
        add_visitor(visit_justprint, NULL);
     }


Finally, the flags-combo -iS would cause a segfault.


2004-12-23  Bas van Gompel  <address@hidden>

        * locate.c (new_locate): Don't fold case when getting stats.


@@ -558,7 +558,7 @@ new_locate (char *pathpart,
   /* If we ignore case, convert it to lower first so we don't have to
    * do it every time
    */
-  if (ignore_case)
+  if (!stat && ignore_case)
     {
       lc_strcpy(pathpart, pathpart);
     }


I hope this mail is bit more useful than the last one.


L8r,

Buzz.
-- 
  ) |  | ---/ ---/  Yes, this | This message consists of true | I do not
--  |  |   /    /   really is |   and false bits entirely.    | mail for
  ) |  |  /    /    a 72 by 4 +-------------------------------+ any1 but
--  \--| /--- /---  .sigfile. |   |perl -pe "s.u(z)\1.as."    | me. 4^re




reply via email to

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