Fix bug in directory depth counting.
The path "dir//file" has the same depth as "dir/file". Also verify
with local unit tests.
(cherry picked from commit b92de07b63bbcb05ff15a32dda8644ee763acc5d)
Test: /data/nativetest64/installd_utils_test/installd_utils_test
Test: cts-tradefed run commandAndExit cts-dev --abi armeabi-v7a -m CtsAppSecurityHostTestCases -t android.appsecurity.cts.AdoptableHostTest
Bug: 67471251
Merged-In: Iab35b4fe5591ddd42a7121b630cffcd94ad23c40
Change-Id: Iab35b4fe5591ddd42a7121b630cffcd94ad23c40
diff --git a/cmds/installd/utils.cpp b/cmds/installd/utils.cpp
index c21fae5..ca0a82e 100644
--- a/cmds/installd/utils.cpp
+++ b/cmds/installd/utils.cpp
@@ -756,8 +756,11 @@
auto pos = path.find('/', dir.size());
int count = 0;
while (pos != std::string::npos) {
- pos = path.find('/', pos + 1);
- count++;
+ auto next = path.find('/', pos + 1);
+ if (next > pos + 1) {
+ count++;
+ }
+ pos = next;
}
if (count > maxSubdirs) {