diff options
author | Scott Mertz <scott@cyngn.com> | 2016-03-14 09:06:45 -0700 |
---|---|---|
committer | Scott Mertz <scott@cyngn.com> | 2016-03-14 11:33:39 -0700 |
commit | 1b88763d09d547fc817354360656d18249906771 (patch) | |
tree | 9e73ca94effd641b45cbd8ed0296c4be676b2a63 | |
parent | 5fc6b2eb050331cfa40a4f7116d89d1b09745582 (diff) | |
download | android_frameworks_base-1b88763d09d547fc817354360656d18249906771.tar.gz android_frameworks_base-1b88763d09d547fc817354360656d18249906771.tar.bz2 android_frameworks_base-1b88763d09d547fc817354360656d18249906771.zip |
cmhw: add invalid input checking for persistent storage APIs
Some of this exists in the PersistentStorage implementation, but it
was never formally documented in the APIs. Inherit the cmhw implementation
error checking & move it into the service.
CYNGNOS-2237
Change-Id: I3ecda29fdd28bbc4e6d8ccce7511c4644065ea46
-rw-r--r-- | core/java/android/hardware/CmHardwareManager.java | 16 | ||||
-rw-r--r-- | services/core/java/com/android/server/CmHardwareService.java | 14 |
2 files changed, 22 insertions, 8 deletions
diff --git a/core/java/android/hardware/CmHardwareManager.java b/core/java/android/hardware/CmHardwareManager.java index ad840b2aa18..0d47ea41acd 100644 --- a/core/java/android/hardware/CmHardwareManager.java +++ b/core/java/android/hardware/CmHardwareManager.java @@ -619,8 +619,8 @@ public final class CmHardwareManager { /** * Write a string to persistent storage, which persists thru factory reset * - * @param key String identifier for this item - * @param value The UTF-8 encoded string to store + * @param key String identifier for this item. Must not exceed 64 characters. + * @param value The UTF-8 encoded string to store of at least 1 character. null deletes the key/value pair. * @return true on success * * @hide @@ -641,7 +641,7 @@ public final class CmHardwareManager { /** * Write an integer to persistent storage, which persists thru factory reset * - * @param key String identifier for this item + * @param key String identifier for this item. Must not exceed 64 characters. * @param value The integer to store * @return true on success * @@ -661,8 +661,8 @@ public final class CmHardwareManager { /** * Write a byte array to persistent storage, which persists thru factory reset * - * @param key String identifier for this item - * @param value The byte array to store, up to 4096 bytes + * @param key String identifier for this item. Must not exceed 64 characters. + * @param value The byte array to store, must be 1-4096 bytes. null deletes the key/value pair. * @return true on success * * @hide @@ -680,7 +680,7 @@ public final class CmHardwareManager { /** * Read a string from persistent storage * - * @param key String identifier for this item + * @param key String identifier for this item. Must not exceed 64 characters. * @return the stored UTF-8 encoded string, null if not found * * @hide @@ -703,7 +703,7 @@ public final class CmHardwareManager { /** * Read an integer from persistent storage * - * @param key String identifier for this item + * @param key String identifier for this item. Must not exceed 64 characters. * @return the stored integer, zero if not found * * @hide @@ -724,7 +724,7 @@ public final class CmHardwareManager { /** * Read a byte array from persistent storage * - * @param key String identifier for this item + * @param key String identifier for this item. Must not exceed 64 characters. * @return the stored byte array, null if not found * * @hide diff --git a/services/core/java/com/android/server/CmHardwareService.java b/services/core/java/com/android/server/CmHardwareService.java index cfd088e36a7..2b4f11267a8 100644 --- a/services/core/java/com/android/server/CmHardwareService.java +++ b/services/core/java/com/android/server/CmHardwareService.java @@ -25,6 +25,7 @@ import android.os.RemoteException; import android.util.Log; import java.io.File; +import java.util.Arrays; import org.cyanogenmod.hardware.AdaptiveBacklight; import org.cyanogenmod.hardware.ColorEnhancement; @@ -522,6 +523,15 @@ public class CmHardwareService extends ICmHardwareService.Stub implements Therma public boolean writePersistentBytes(String key, byte[] value) { mContext.enforceCallingOrSelfPermission( Manifest.permission.MANAGE_PERSISTENT_STORAGE, null); + if (key == null || key.length() == 0 || key.length() > 64) { + Log.e(TAG, "Invalid key: " + key); + return false; + } + // A null value is delete + if (value != null && (value.length > 4096 || value.length == 0)) { + Log.e(TAG, "Invalid value: " + (value != null ? Arrays.toString(value) : null)); + return false; + } if (!isSupported(CmHardwareManager.FEATURE_PERSISTENT_STORAGE)) { Log.e(TAG, "Persistent storage is not supported"); return false; @@ -533,6 +543,10 @@ public class CmHardwareService extends ICmHardwareService.Stub implements Therma public byte[] readPersistentBytes(String key) { mContext.enforceCallingOrSelfPermission( Manifest.permission.MANAGE_PERSISTENT_STORAGE, null); + if (key == null || key.length() == 0 || key.length() > 64) { + Log.e(TAG, "Invalid key: " + key); + return null; + } if (!isSupported(CmHardwareManager.FEATURE_PERSISTENT_STORAGE)) { Log.e(TAG, "Persistent storage is not supported"); return null; |