summaryrefslogtreecommitdiffstats
path: root/benchmarks
diff options
context:
space:
mode:
authorChristopher Ferris <cferris@google.com>2014-07-15 19:09:07 -0700
committerChristopher Ferris <cferris@google.com>2014-07-15 19:26:28 -0700
commit53531ccebbaf103d80516ff74874482ca3ee31fc (patch)
tree4ffa7a74ff337a765c891979bba73c7da0e60e76 /benchmarks
parent64035c4a4b52ce87398e3a5945ad6b755c8f35b1 (diff)
downloadbionic-53531ccebbaf103d80516ff74874482ca3ee31fc.zip
bionic-53531ccebbaf103d80516ff74874482ca3ee31fc.tar.gz
bionic-53531ccebbaf103d80516ff74874482ca3ee31fc.tar.bz2
Make sure not to construct illegal property names.
Change-Id: I37624e69aec51efd4291f076fb87af3f35d33025
Diffstat (limited to 'benchmarks')
-rw-r--r--benchmarks/property_benchmark.cpp34
1 files changed, 28 insertions, 6 deletions
diff --git a/benchmarks/property_benchmark.cpp b/benchmarks/property_benchmark.cpp
index f330d7e..0802b4c 100644
--- a/benchmarks/property_benchmark.cpp
+++ b/benchmarks/property_benchmark.cpp
@@ -28,12 +28,14 @@
extern void *__system_property_area__;
+// Do not exceed 512, that is about the largest number of properties
+// that can be created with the current property area size.
#define TEST_NUM_PROPS \
- Arg(1)->Arg(4)->Arg(16)->Arg(64)->Arg(128)->Arg(256)->Arg(512)->Arg(1024)
+ Arg(1)->Arg(4)->Arg(16)->Arg(64)->Arg(128)->Arg(256)->Arg(512)
struct LocalPropertyTestState {
LocalPropertyTestState(int nprops) : nprops(nprops), valid(false) {
- static const char prop_name_chars[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-_";
+ static const char prop_name_chars[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_.";
const char* android_data = getenv("ANDROID_DATA");
if (android_data == NULL) {
@@ -66,18 +68,38 @@ struct LocalPropertyTestState {
srandom(nprops);
for (int i = 0; i < nprops; i++) {
- name_lens[i] = random() % PROP_NAME_MAX;
+ // Make sure the name has at least 10 characters to make
+ // it very unlikely to generate the same random name.
+ name_lens[i] = (random() % (PROP_NAME_MAX - 10)) + 10;
names[i] = new char[PROP_NAME_MAX + 1];
+ size_t prop_name_len = sizeof(prop_name_chars) - 1;
for (int j = 0; j < name_lens[i]; j++) {
- names[i][j] = prop_name_chars[random() % (sizeof(prop_name_chars) - 1)];
+ if (j == 0 || names[i][j-1] == '.' || j == name_lens[i] - 1) {
+ // Certain values are not allowed:
+ // - Don't start name with '.'
+ // - Don't allow '.' to appear twice in a row
+ // - Don't allow the name to end with '.'
+ // This assumes that '.' is the last character in the
+ // array so that decrementing the length by one removes
+ // the value from the possible values.
+ prop_name_len--;
+ }
+ names[i][j] = prop_name_chars[random() % prop_name_len];
}
names[i][name_lens[i]] = 0;
- value_lens[i] = random() % PROP_VALUE_MAX;
+
+ // Make sure the value contains at least 1 character.
+ value_lens[i] = (random() % (PROP_VALUE_MAX - 1)) + 1;
values[i] = new char[PROP_VALUE_MAX];
for (int j = 0; j < value_lens[i]; j++) {
values[i][j] = prop_name_chars[random() % (sizeof(prop_name_chars) - 1)];
}
- __system_property_add(names[i], name_lens[i], values[i], value_lens[i]);
+
+ if (__system_property_add(names[i], name_lens[i], values[i], value_lens[i]) < 0) {
+ printf("Failed to add a property, terminating...\n");
+ printf("%s = %.*s\n", names[i], value_lens[i], values[i]);
+ exit(1);
+ }
}
valid = true;