Line 0
Link Here
|
|
|
1 |
diff locate/locate.c.orig locate/locate.c |
2 |
--- locate/locate.c.orig |
3 |
+++ locate/locate.c |
4 |
@@ -1546,12 +1546,19 @@ opendb (const char *name) |
5 |
return fd; |
6 |
} |
7 |
|
8 |
+static void |
9 |
+cleanup_quote_opts (void) |
10 |
+{ |
11 |
+ free (quote_opts); |
12 |
+} |
13 |
+ |
14 |
+ |
15 |
int |
16 |
dolocate (int argc, char **argv, int secure_db_fd) |
17 |
{ |
18 |
- char *path_element; |
19 |
+ char *path_element = NULL; |
20 |
size_t path_element_pos, path_element_len; |
21 |
- const char *locate_path; |
22 |
+ const char *user_selected_locate_path; |
23 |
const char *db_name; |
24 |
const char *path_separators = ":"; |
25 |
unsigned long int found = 0uL; |
26 |
@@ -1565,7 +1572,6 @@ dolocate (int argc, char **argv, int secure_db_fd) |
27 |
int stats = 0; |
28 |
int op_and = 0; |
29 |
FILE *fp; |
30 |
- int they_chose_db = 0; |
31 |
bool did_stdin = false; /* Set to prevent rereading stdin. */ |
32 |
|
33 |
if (argv[0]) |
34 |
@@ -1580,19 +1586,19 @@ dolocate (int argc, char **argv, int secure_db_fd) |
35 |
textdomain (PACKAGE); |
36 |
atexit (close_stdout); |
37 |
|
38 |
+ quote_opts = clone_quoting_options (NULL); |
39 |
+ atexit (cleanup_quote_opts); |
40 |
+ |
41 |
limits.limit = 0; |
42 |
limits.items_accepted = 0; |
43 |
|
44 |
- quote_opts = clone_quoting_options (NULL); |
45 |
print_quoted_filename = true; |
46 |
|
47 |
/* We cannot simultaneously trust $LOCATE_PATH and use the |
48 |
* setuid-access-controlled database,, since that could cause a leak |
49 |
* of private data. |
50 |
*/ |
51 |
- locate_path = getenv ("LOCATE_PATH"); |
52 |
- if (locate_path) |
53 |
- they_chose_db = 1; |
54 |
+ user_selected_locate_path = getenv ("LOCATE_PATH"); |
55 |
|
56 |
check_existence = ACCEPT_EITHER; |
57 |
|
58 |
@@ -1624,8 +1630,8 @@ dolocate (int argc, char **argv, int secure_db_fd) |
59 |
break; |
60 |
|
61 |
case 'd': |
62 |
- locate_path = optarg; |
63 |
- they_chose_db = 1; |
64 |
+ user_selected_locate_path = optarg; |
65 |
+ assert (optarg != NULL); |
66 |
break; |
67 |
|
68 |
case 'e': |
69 |
@@ -1715,7 +1721,7 @@ dolocate (int argc, char **argv, int secure_db_fd) |
70 |
/* If the user gave the -d option or set LOCATE_PATH, |
71 |
* relinquish access to the secure database. |
72 |
*/ |
73 |
- if (they_chose_db) |
74 |
+ if (user_selected_locate_path) |
75 |
{ |
76 |
if (secure_db_fd >= 0) |
77 |
{ |
78 |
@@ -1741,15 +1747,16 @@ dolocate (int argc, char **argv, int secure_db_fd) |
79 |
} |
80 |
} |
81 |
|
82 |
- |
83 |
if (1 == isatty (STDOUT_FILENO)) |
84 |
stdout_is_a_tty = true; |
85 |
else |
86 |
stdout_is_a_tty = false; |
87 |
|
88 |
- if (they_chose_db) |
89 |
- splitstring (locate_path, path_separators, true, |
90 |
- &path_element_pos, &path_element_len); |
91 |
+ if (user_selected_locate_path) |
92 |
+ { |
93 |
+ splitstring (user_selected_locate_path, path_separators, true, |
94 |
+ &path_element_pos, &path_element_len); |
95 |
+ } |
96 |
|
97 |
/* Bail out early if limit already reached. */ |
98 |
while (!use_limit || limits.limit > limits.items_accepted) |
99 |
@@ -1765,10 +1772,11 @@ dolocate (int argc, char **argv, int secure_db_fd) |
100 |
statistics.newline_count = |
101 |
statistics.highbit_filename_count = 0u; |
102 |
|
103 |
- if (they_chose_db) |
104 |
+ if (user_selected_locate_path) |
105 |
{ |
106 |
/* Take the next element from the list of databases */ |
107 |
- if (1 == path_element_len && '-' == locate_path[path_element_pos]) |
108 |
+ if (1 == path_element_len |
109 |
+ && '-' == user_selected_locate_path[path_element_pos]) |
110 |
{ |
111 |
if (did_stdin) |
112 |
{ |
113 |
@@ -1787,13 +1795,13 @@ dolocate (int argc, char **argv, int secure_db_fd) |
114 |
{ |
115 |
if (0 == path_element_len |
116 |
|| (1 == path_element_len |
117 |
- && '.' == locate_path[path_element_pos])) |
118 |
+ && '.' == user_selected_locate_path[path_element_pos])) |
119 |
{ |
120 |
db_name = LOCATE_DB; |
121 |
} |
122 |
else |
123 |
{ |
124 |
- path_element = strndup (&locate_path[path_element_pos], |
125 |
+ path_element = strndup (&user_selected_locate_path[path_element_pos], |
126 |
path_element_len); |
127 |
db_name = path_element; |
128 |
} |
129 |
@@ -1889,11 +1897,20 @@ dolocate (int argc, char **argv, int secure_db_fd) |
130 |
free (path_element); |
131 |
path_element = NULL; |
132 |
} |
133 |
- if (!splitstring (locate_path, path_separators, false, |
134 |
- &path_element_pos, &path_element_len)) |
135 |
- { |
136 |
- break; |
137 |
- } |
138 |
+ |
139 |
+ if (!user_selected_locate_path) |
140 |
+ { |
141 |
+ /* We're not actually iterating through the values in |
142 |
+ $LOCATE_PATH so we don't want to check for the next |
143 |
+ element in user_selected_locate_path (since we manually set db_name = |
144 |
+ LOCATE_DB without using user_selected_locate_path). */ |
145 |
+ break; |
146 |
+ } |
147 |
+ else if (!splitstring (user_selected_locate_path, path_separators, false, |
148 |
+ &path_element_pos, &path_element_len)) |
149 |
+ { |
150 |
+ break; |
151 |
+ } |
152 |
} |
153 |
|
154 |
if (just_count) |