diff options
author | Todd Kennedy <toddke@google.com> | 2016-10-12 15:26:08 -0700 |
---|---|---|
committer | Todd Kennedy <toddke@google.com> | 2016-10-17 14:50:52 -0700 |
commit | 9caf94e535a1a7573ad61fbc487b74d122ca4d29 (patch) | |
tree | d847e402418c2aaabff19ecf0d9e1c3615c51d0e /cmds/pm | |
parent | 00a981e522d073acd4e77b8150d3cf5da58c0f87 (diff) |
force appropriate size
during install, the user could specify an invalid size [ie. a negative
number].
also error out if we're given a path that's not a file.
Change-Id: I79e9ef82723495782146208eb5469722d1f8ed02
Test: manually ran 'adb install' with invalid arguments
Diffstat (limited to 'cmds/pm')
-rw-r--r-- | cmds/pm/src/com/android/commands/pm/Pm.java | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/cmds/pm/src/com/android/commands/pm/Pm.java b/cmds/pm/src/com/android/commands/pm/Pm.java index aba53dcdca4d..718f1414c93d 100644 --- a/cmds/pm/src/com/android/commands/pm/Pm.java +++ b/cmds/pm/src/com/android/commands/pm/Pm.java @@ -84,6 +84,7 @@ import java.util.concurrent.TimeUnit; public final class Pm { private static final String TAG = "Pm"; + private static final String STDIN_PATH = "-"; IPackageManager mPm; IPackageInstaller mInstaller; @@ -403,7 +404,7 @@ public final class Pm { private int runInstall() throws RemoteException { final InstallParams params = makeInstallParams(); final String inPath = nextArg(); - if (params.sessionParams.sizeBytes < 0 && inPath != null) { + if (params.sessionParams.sizeBytes == -1 && !STDIN_PATH.equals(inPath)) { File file = new File(inPath); if (file.isFile()) { try { @@ -413,9 +414,12 @@ public final class Pm { PackageHelper.calculateInstalledSize(pkgLite, false, params.sessionParams.abiOverride)); } catch (PackageParserException | IOException e) { - System.err.println("Error: Failed to parse APK file : " + e); + System.err.println("Error: Failed to parse APK file: " + e); return 1; } + } else { + System.err.println("Error: Can't open non-file: " + inPath); + return 1; } } @@ -423,7 +427,7 @@ public final class Pm { params.installerPackageName, params.userId); try { - if (inPath == null && params.sessionParams.sizeBytes == 0) { + if (inPath == null && params.sessionParams.sizeBytes == -1) { System.err.println("Error: must either specify a package size or an APK file"); return 1; } @@ -540,7 +544,11 @@ public final class Pm { } break; case "-S": - sessionParams.setSize(Long.parseLong(nextOptionData())); + final long sizeBytes = Long.parseLong(nextOptionData()); + if (sizeBytes <= 0) { + throw new IllegalArgumentException("Size must be positive"); + } + sessionParams.setSize(sizeBytes); break; case "--abi": sessionParams.abiOverride = checkAbiArgument(nextOptionData()); @@ -585,7 +593,7 @@ public final class Pm { private int doWriteSession(int sessionId, String inPath, long sizeBytes, String splitName, boolean logSuccess) throws RemoteException { - if ("-".equals(inPath)) { + if (STDIN_PATH.equals(inPath)) { inPath = null; } else if (inPath != null) { final File file = new File(inPath); |