summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBen Fennema2017-06-26 17:49:41 -0500
committerandroid-build-merger2017-06-26 17:49:41 -0500
commitcd3584e90b831de51d09b07e2da22b601bd5d255 (patch)
tree2fd4a668697f97d5e70e33ba39bfe61663e2e7fc /libcutils/fs_config.cpp
parentde931dab2dc33ceb8a31f3208c1f68e6a946708a (diff)
parent449bfd7a9347e0c61743162c0fdb445a59e88d6b (diff)
downloadplatform-system-core-cd3584e90b831de51d09b07e2da22b601bd5d255.tar.gz
platform-system-core-cd3584e90b831de51d09b07e2da22b601bd5d255.tar.xz
platform-system-core-cd3584e90b831de51d09b07e2da22b601bd5d255.zip
Merge "libcutils: fs_config: fix "system/<partition>/" aliasing"
am: 449bfd7a93 Change-Id: I9f3d0f0e4dc147d9d2a5a1e41486805ada29d62a
Diffstat (limited to 'libcutils/fs_config.cpp')
-rw-r--r--libcutils/fs_config.cpp39
1 files changed, 19 insertions, 20 deletions
diff --git a/libcutils/fs_config.cpp b/libcutils/fs_config.cpp
index 221dea268..a1dbd7881 100644
--- a/libcutils/fs_config.cpp
+++ b/libcutils/fs_config.cpp
@@ -266,14 +266,27 @@ static bool is_partition(const char* path, size_t len) {
266 return false; 266 return false;
267} 267}
268 268
269static inline bool prefix_cmp(bool partial, const char* prefix, size_t len, const char* path,
270 size_t plen) {
271 return ((partial && plen >= len) || (plen == len)) && !strncmp(prefix, path, len);
272}
273
269// alias prefixes of "<partition>/<stuff>" to "system/<partition>/<stuff>" or 274// alias prefixes of "<partition>/<stuff>" to "system/<partition>/<stuff>" or
270// "system/<partition>/<stuff>" to "<partition>/<stuff>" 275// "system/<partition>/<stuff>" to "<partition>/<stuff>"
271static bool prefix_cmp(const char* prefix, const char* path, size_t len) { 276static bool fs_config_cmp(bool partial, const char* prefix, size_t len, const char* path,
272 if (!strncmp(prefix, path, len)) return true; 277 size_t plen) {
278 // If name ends in * then allow partial matches.
279 if (!partial && prefix[len - 1] == '*') {
280 len--;
281 partial = true;
282 }
283
284 if (prefix_cmp(partial, prefix, len, path, plen)) return true;
273 285
274 static const char system[] = "system/"; 286 static const char system[] = "system/";
275 if (!strncmp(path, system, strlen(system))) { 287 if (!strncmp(path, system, strlen(system))) {
276 path += strlen(system); 288 path += strlen(system);
289 plen -= strlen(system);
277 } else if (len <= strlen(system)) { 290 } else if (len <= strlen(system)) {
278 return false; 291 return false;
279 } else if (strncmp(prefix, system, strlen(system))) { 292 } else if (strncmp(prefix, system, strlen(system))) {
@@ -282,25 +295,11 @@ static bool prefix_cmp(const char* prefix, const char* path, size_t len) {
282 prefix += strlen(system); 295 prefix += strlen(system);
283 len -= strlen(system); 296 len -= strlen(system);
284 } 297 }
285 return is_partition(prefix, len) && !strncmp(prefix, path, len); 298 return is_partition(prefix, len) && prefix_cmp(partial, prefix, len, path, plen);
286}
287
288static bool fs_config_cmp(bool dir, const char* prefix, size_t len, const char* path, size_t plen) {
289 if (dir) {
290 if (plen < len) {
291 return false;
292 }
293 } else {
294 // If name ends in * then allow partial matches.
295 if (prefix[len - 1] == '*') {
296 return prefix_cmp(prefix, path, len - 1);
297 }
298 if (plen != len) {
299 return false;
300 }
301 }
302 return prefix_cmp(prefix, path, len);
303} 299}
300#ifndef __ANDROID_VNDK__
301auto __for_testing_only__fs_config_cmp = fs_config_cmp;
302#endif
304 303
305void fs_config(const char* path, int dir, const char* target_out_path, unsigned* uid, unsigned* gid, 304void fs_config(const char* path, int dir, const char* target_out_path, unsigned* uid, unsigned* gid,
306 unsigned* mode, uint64_t* capabilities) { 305 unsigned* mode, uint64_t* capabilities) {