Fix StringIndexOutOfBoundsException in PackageManagerService

The method packageManagerService.getNextCodePath(String oldCodePath,
String prefix, String suffix) threw StringIndexOutOfBoundsException if
oldCodePath does not contain prefix, and prefix is longer than
oldCodePath, or if the preix and suffix overlap.

Fixes http://b/issue?id=2404232

Change-Id: Ib8abb16f8bfd08f607476d9289f46d170c43a076
This commit is contained in:
Bjorn Bringert
2010-01-29 12:11:30 +00:00
parent 784d53e79b
commit 5fd5bfe942

View File

@ -4369,18 +4369,13 @@ class PackageManagerService extends IPackageManager.Stub {
String idxStr = "";
int idx = 1;
if (oldCodePath != null) {
int eidx = -1;
if (suffix != null) {
eidx = oldCodePath.indexOf(suffix);
String subStr = oldCodePath;
if (subStr.startsWith(prefix)) {
subStr = subStr.substring(prefix.length());
}
if (eidx == -1) {
eidx = oldCodePath.length();
if (subStr.endsWith(suffix)) {
subStr = subStr.substring(0, subStr.length() - suffix.length());
}
int sidx = oldCodePath.indexOf(prefix);
if (sidx == -1) {
sidx = 0;
}
String subStr = oldCodePath.substring(sidx + prefix.length(), eidx);
if (subStr != null) {
if (subStr.startsWith("-")) {
subStr = subStr.substring(1);