aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher Ferris2014-07-15 21:09:07 -0500
committerChristopher Ferris2014-07-15 21:26:28 -0500
commit53531ccebbaf103d80516ff74874482ca3ee31fc (patch)
tree4ffa7a74ff337a765c891979bba73c7da0e60e76 /benchmarks
parent64035c4a4b52ce87398e3a5945ad6b755c8f35b1 (diff)
downloadplatform-bionic-53531ccebbaf103d80516ff74874482ca3ee31fc.tar.gz
platform-bionic-53531ccebbaf103d80516ff74874482ca3ee31fc.tar.xz
platform-bionic-53531ccebbaf103d80516ff74874482ca3ee31fc.zip
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 f330d7e9..0802b4c3 100644
--- a/benchmarks/property_benchmark.cpp
+++ b/benchmarks/property_benchmark.cpp
@@ -28,12 +28,14 @@
28 28
29extern void *__system_property_area__; 29extern void *__system_property_area__;
30 30
31// Do not exceed 512, that is about the largest number of properties
32// that can be created with the current property area size.
31#define TEST_NUM_PROPS \ 33#define TEST_NUM_PROPS \
32 Arg(1)->Arg(4)->Arg(16)->Arg(64)->Arg(128)->Arg(256)->Arg(512)->Arg(1024) 34 Arg(1)->Arg(4)->Arg(16)->Arg(64)->Arg(128)->Arg(256)->Arg(512)
33 35
34struct LocalPropertyTestState { 36struct LocalPropertyTestState {
35 LocalPropertyTestState(int nprops) : nprops(nprops), valid(false) { 37 LocalPropertyTestState(int nprops) : nprops(nprops), valid(false) {
36 static const char prop_name_chars[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-_"; 38 static const char prop_name_chars[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_.";
37 39
38 const char* android_data = getenv("ANDROID_DATA"); 40 const char* android_data = getenv("ANDROID_DATA");
39 if (android_data == NULL) { 41 if (android_data == NULL) {
@@ -66,18 +68,38 @@ struct LocalPropertyTestState {
66 srandom(nprops); 68 srandom(nprops);
67 69
68 for (int i = 0; i < nprops; i++) { 70 for (int i = 0; i < nprops; i++) {
69 name_lens[i] = random() % PROP_NAME_MAX; 71 // Make sure the name has at least 10 characters to make
72 // it very unlikely to generate the same random name.
73 name_lens[i] = (random() % (PROP_NAME_MAX - 10)) + 10;
70 names[i] = new char[PROP_NAME_MAX + 1]; 74 names[i] = new char[PROP_NAME_MAX + 1];
75 size_t prop_name_len = sizeof(prop_name_chars) - 1;
71 for (int j = 0; j < name_lens[i]; j++) { 76 for (int j = 0; j < name_lens[i]; j++) {
72 names[i][j] = prop_name_chars[random() % (sizeof(prop_name_chars) - 1)]; 77 if (j == 0 || names[i][j-1] == '.' || j == name_lens[i] - 1) {
78 // Certain values are not allowed:
79 // - Don't start name with '.'
80 // - Don't allow '.' to appear twice in a row
81 // - Don't allow the name to end with '.'
82 // This assumes that '.' is the last character in the
83 // array so that decrementing the length by one removes
84 // the value from the possible values.
85 prop_name_len--;
86 }
87 names[i][j] = prop_name_chars[random() % prop_name_len];
73 } 88 }
74 names[i][name_lens[i]] = 0; 89 names[i][name_lens[i]] = 0;
75 value_lens[i] = random() % PROP_VALUE_MAX; 90
91 // Make sure the value contains at least 1 character.
92 value_lens[i] = (random() % (PROP_VALUE_MAX - 1)) + 1;
76 values[i] = new char[PROP_VALUE_MAX]; 93 values[i] = new char[PROP_VALUE_MAX];
77 for (int j = 0; j < value_lens[i]; j++) { 94 for (int j = 0; j < value_lens[i]; j++) {
78 values[i][j] = prop_name_chars[random() % (sizeof(prop_name_chars) - 1)]; 95 values[i][j] = prop_name_chars[random() % (sizeof(prop_name_chars) - 1)];
79 } 96 }
80 __system_property_add(names[i], name_lens[i], values[i], value_lens[i]); 97
98 if (__system_property_add(names[i], name_lens[i], values[i], value_lens[i]) < 0) {
99 printf("Failed to add a property, terminating...\n");
100 printf("%s = %.*s\n", names[i], value_lens[i], values[i]);
101 exit(1);
102 }
81 } 103 }
82 104
83 valid = true; 105 valid = true;