In usr.bin/locate/locate/locate.c and util.c the variable dbv is defined
as a pointer to char * and is used to access the path to every database
provided to locate. E.g. when running
    
    locate -d /path/to/db1 -d /path/to/db2 -d /path/to/db3 *

*dbv     points to '/path/to/db1'
*(dbv+1) points to '/path/to/db2'
*(dbv+2) points to '/path/to/db3'

However dbv is initialized with the following call

    dbv = malloc(sizeof(char **))

which I believe should be 

    dbv = malloc(sizeof(char *))

The same goes for the variable newdbv. Please find the corresponding
diff below. No binary change on amd64 since sizeof(char **) ==
sizeof(char *). 

Nicolas Bedos



Index: usr.bin/locate/locate/util.c
===================================================================
RCS file: /cvs/src/usr.bin/locate/locate/util.c,v
retrieving revision 1.11
diff -u -p -u -r1.11 util.c
--- usr.bin/locate/locate/util.c        8 Oct 2014 04:04:37 -0000       1.11
+++ usr.bin/locate/locate/util.c        15 Nov 2014 14:08:15 -0000
@@ -89,7 +89,7 @@ colon(dbv, path, dot)
        char **pv;
 
        if (dbv == NULL) {
-               if ((dbv = malloc(sizeof(char **))) == NULL)
+               if ((dbv = malloc(sizeof(char *))) == NULL)
                        err(1, "malloc");
                *dbv = NULL;
        }
@@ -123,7 +123,7 @@ colon(dbv, path, dot)
                        }
                        /* increase dbv with element p */
                        if ((newdbv = reallocarray(dbv, vlen + 2,
-                           sizeof(char **))) == NULL)
+                           sizeof(char *))) == NULL)
                                err(1, "realloc");
                        dbv = newdbv;
                        *(dbv + vlen) = p;

Reply via email to