summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBen Fennema2017-06-22 17:15:56 -0500
committerBen Fennema2017-06-26 16:13:52 -0500
commitacd7b7b0c037b1f7e5feaf8c33e08ea88a071b38 (patch)
tree695d1254d3c6bcf07a07812b29c122e499e029f5 /libcutils/fs_config.cpp
parent75752c19114b1aeed16d99bc817b9477ccb15098 (diff)
downloadplatform-system-core-acd7b7b0c037b1f7e5feaf8c33e08ea88a071b38.tar.gz
platform-system-core-acd7b7b0c037b1f7e5feaf8c33e08ea88a071b38.tar.xz
platform-system-core-acd7b7b0c037b1f7e5feaf8c33e08ea88a071b38.zip
libcutils: fs_config: fix "system/<partition>/" aliasing
Pull prefix checking into fs_config_cmp and make prefix_cmp be a glorified partial ? strncmp() : strcmp() Results before: [ RUN ] fs_config.system_alias [ ERROR ] system/core/libcutils/tests/fs_config.cpp:143:: vendor/lib/hw didn't match system/vendor/lib [ ERROR ] system/core/libcutils/tests/fs_config.cpp:143:: system/vendor/bin/wifi didn't match vendor/bin/wifi [ ERROR ] system/core/libcutils/tests/fs_config.cpp:143:: system/odm/bin/wifi didn't match odm/bin/wifi [ ERROR ] system/core/libcutils/tests/fs_config.cpp:143:: system/oem/bin/wifi didn't match oem/bin/wifi system/core/libcutils/tests/fs_config.cpp:247: Failure Value of: check_fs_config_cmp(fs_config_cmp_tests) Actual: true Expected: false [ FAILED ] fs_config.system_alias (6 ms) Results after: [ RUN ] fs_config.system_alias [ OK ] fs_config.system_alias (0 ms) Bug: 62204623 Test: gTest libcutils-unit-test --gtest_filter=fs_config.* Change-Id: I8282827002816e86ea3014fed29eabf43b837815 Signed-off-by: Ben Fennema <fennema@google.com>
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 919b65bc3..13c4abf98 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) {