| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/mem_sec.c |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||||||||||||||
| 2 | - | |||||||||||||||||||||||||
| 3 | - | |||||||||||||||||||||||||
| 4 | - | |||||||||||||||||||||||||
| 5 | - | |||||||||||||||||||||||||
| 6 | - | |||||||||||||||||||||||||
| 7 | - | |||||||||||||||||||||||||
| 8 | - | |||||||||||||||||||||||||
| 9 | - | |||||||||||||||||||||||||
| 10 | static size_t secure_mem_used; | - | ||||||||||||||||||||||||
| 11 | - | |||||||||||||||||||||||||
| 12 | static int secure_mem_initialized; | - | ||||||||||||||||||||||||
| 13 | - | |||||||||||||||||||||||||
| 14 | static CRYPTO_RWLOCK *sec_malloc_lock = | - | ||||||||||||||||||||||||
| 15 | ((void *)0) | - | ||||||||||||||||||||||||
| 16 | ; | - | ||||||||||||||||||||||||
| 17 | - | |||||||||||||||||||||||||
| 18 | - | |||||||||||||||||||||||||
| 19 | - | |||||||||||||||||||||||||
| 20 | - | |||||||||||||||||||||||||
| 21 | static int sh_init(size_t size, int minsize); | - | ||||||||||||||||||||||||
| 22 | static void *sh_malloc(size_t size); | - | ||||||||||||||||||||||||
| 23 | static void sh_free(void *ptr); | - | ||||||||||||||||||||||||
| 24 | static void sh_done(void); | - | ||||||||||||||||||||||||
| 25 | static size_t sh_actual_size(char *ptr); | - | ||||||||||||||||||||||||
| 26 | static int sh_allocated(const char *ptr); | - | ||||||||||||||||||||||||
| 27 | - | |||||||||||||||||||||||||
| 28 | - | |||||||||||||||||||||||||
| 29 | int CRYPTO_secure_malloc_init(size_t size, int minsize) | - | ||||||||||||||||||||||||
| 30 | { | - | ||||||||||||||||||||||||
| 31 | - | |||||||||||||||||||||||||
| 32 | int ret = 0; | - | ||||||||||||||||||||||||
| 33 | - | |||||||||||||||||||||||||
| 34 | if (!secure_mem_initialized
| 0-4 | ||||||||||||||||||||||||
| 35 | sec_malloc_lock = CRYPTO_THREAD_lock_new(); | - | ||||||||||||||||||||||||
| 36 | if (sec_malloc_lock ==
| 0-4 | ||||||||||||||||||||||||
| 37 | ((void *)0)
| 0-4 | ||||||||||||||||||||||||
| 38 | ) | - | ||||||||||||||||||||||||
| 39 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||||||||||||||
| 40 | if ((
| 1-3 | ||||||||||||||||||||||||
| 41 | secure_mem_initialized = 1; | - | ||||||||||||||||||||||||
| 42 | } executed 3 times by 1 test: else {end of blockExecuted by:
| 3 | ||||||||||||||||||||||||
| 43 | CRYPTO_THREAD_lock_free(sec_malloc_lock); | - | ||||||||||||||||||||||||
| 44 | sec_malloc_lock = | - | ||||||||||||||||||||||||
| 45 | ((void *)0) | - | ||||||||||||||||||||||||
| 46 | ; | - | ||||||||||||||||||||||||
| 47 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||||||||||||||
| 48 | } | - | ||||||||||||||||||||||||
| 49 | - | |||||||||||||||||||||||||
| 50 | return executed 4 times by 1 test: ret;return ret;Executed by:
executed 4 times by 1 test: return ret;Executed by:
| 4 | ||||||||||||||||||||||||
| 51 | - | |||||||||||||||||||||||||
| 52 | - | |||||||||||||||||||||||||
| 53 | - | |||||||||||||||||||||||||
| 54 | } | - | ||||||||||||||||||||||||
| 55 | - | |||||||||||||||||||||||||
| 56 | int CRYPTO_secure_malloc_done(void) | - | ||||||||||||||||||||||||
| 57 | { | - | ||||||||||||||||||||||||
| 58 | - | |||||||||||||||||||||||||
| 59 | if (secure_mem_used == 0
| 1-2079 | ||||||||||||||||||||||||
| 60 | sh_done(); | - | ||||||||||||||||||||||||
| 61 | secure_mem_initialized = 0; | - | ||||||||||||||||||||||||
| 62 | CRYPTO_THREAD_lock_free(sec_malloc_lock); | - | ||||||||||||||||||||||||
| 63 | sec_malloc_lock = | - | ||||||||||||||||||||||||
| 64 | ((void *)0) | - | ||||||||||||||||||||||||
| 65 | ; | - | ||||||||||||||||||||||||
| 66 | return executed 2079 times by 12 tests: 1;return 1;Executed by:
executed 2079 times by 12 tests: return 1;Executed by:
| 2079 | ||||||||||||||||||||||||
| 67 | } | - | ||||||||||||||||||||||||
| 68 | - | |||||||||||||||||||||||||
| 69 | return executed 1 time by 1 test: 0;return 0;Executed by:
executed 1 time by 1 test: return 0;Executed by:
| 1 | ||||||||||||||||||||||||
| 70 | } | - | ||||||||||||||||||||||||
| 71 | - | |||||||||||||||||||||||||
| 72 | int CRYPTO_secure_malloc_initialized(void) | - | ||||||||||||||||||||||||
| 73 | { | - | ||||||||||||||||||||||||
| 74 | - | |||||||||||||||||||||||||
| 75 | return executed 3 times by 1 test: secure_mem_initialized;return secure_mem_initialized;Executed by:
executed 3 times by 1 test: return secure_mem_initialized;Executed by:
| 3 | ||||||||||||||||||||||||
| 76 | - | |||||||||||||||||||||||||
| 77 | - | |||||||||||||||||||||||||
| 78 | - | |||||||||||||||||||||||||
| 79 | } | - | ||||||||||||||||||||||||
| 80 | - | |||||||||||||||||||||||||
| 81 | void *CRYPTO_secure_malloc(size_t num, const char *file, int line) | - | ||||||||||||||||||||||||
| 82 | { | - | ||||||||||||||||||||||||
| 83 | - | |||||||||||||||||||||||||
| 84 | void *ret; | - | ||||||||||||||||||||||||
| 85 | size_t actual_size; | - | ||||||||||||||||||||||||
| 86 | - | |||||||||||||||||||||||||
| 87 | if (!secure_mem_initialized
| 4-85716 | ||||||||||||||||||||||||
| 88 | return executed 85716 times by 1 test: CRYPTO_malloc(num, file, line);return CRYPTO_malloc(num, file, line);Executed by:
executed 85716 times by 1 test: return CRYPTO_malloc(num, file, line);Executed by:
| 85716 | ||||||||||||||||||||||||
| 89 | } | - | ||||||||||||||||||||||||
| 90 | CRYPTO_THREAD_write_lock(sec_malloc_lock); | - | ||||||||||||||||||||||||
| 91 | ret = sh_malloc(num); | - | ||||||||||||||||||||||||
| 92 | actual_size = ret
| 1-3 | ||||||||||||||||||||||||
| 93 | secure_mem_used += actual_size; | - | ||||||||||||||||||||||||
| 94 | CRYPTO_THREAD_unlock(sec_malloc_lock); | - | ||||||||||||||||||||||||
| 95 | return executed 4 times by 1 test: ret;return ret;Executed by:
executed 4 times by 1 test: return ret;Executed by:
| 4 | ||||||||||||||||||||||||
| 96 | - | |||||||||||||||||||||||||
| 97 | - | |||||||||||||||||||||||||
| 98 | - | |||||||||||||||||||||||||
| 99 | } | - | ||||||||||||||||||||||||
| 100 | - | |||||||||||||||||||||||||
| 101 | void *CRYPTO_secure_zalloc(size_t num, const char *file, int line) | - | ||||||||||||||||||||||||
| 102 | { | - | ||||||||||||||||||||||||
| 103 | - | |||||||||||||||||||||||||
| 104 | if (secure_mem_initialized
| 0-1146154 | ||||||||||||||||||||||||
| 105 | - | |||||||||||||||||||||||||
| 106 | return never executed: CRYPTO_secure_malloc(num, file, line);return CRYPTO_secure_malloc(num, file, line);never executed: return CRYPTO_secure_malloc(num, file, line); | 0 | ||||||||||||||||||||||||
| 107 | - | |||||||||||||||||||||||||
| 108 | return executed 1146206 times by 2 tests: CRYPTO_zalloc(num, file, line);return CRYPTO_zalloc(num, file, line);Executed by:
executed 1146206 times by 2 tests: return CRYPTO_zalloc(num, file, line);Executed by:
| 1146206 | ||||||||||||||||||||||||
| 109 | } | - | ||||||||||||||||||||||||
| 110 | - | |||||||||||||||||||||||||
| 111 | void CRYPTO_secure_free(void *ptr, const char *file, int line) | - | ||||||||||||||||||||||||
| 112 | { | - | ||||||||||||||||||||||||
| 113 | - | |||||||||||||||||||||||||
| 114 | size_t actual_size; | - | ||||||||||||||||||||||||
| 115 | - | |||||||||||||||||||||||||
| 116 | if (ptr ==
| 6-89963 | ||||||||||||||||||||||||
| 117 | ((void *)0)
| 6-89963 | ||||||||||||||||||||||||
| 118 | ) | - | ||||||||||||||||||||||||
| 119 | return; executed 6 times by 1 test: return;Executed by:
| 6 | ||||||||||||||||||||||||
| 120 | if (!CRYPTO_secure_allocated(ptr)
| 2-89961 | ||||||||||||||||||||||||
| 121 | CRYPTO_free(ptr, file, line); | - | ||||||||||||||||||||||||
| 122 | return; executed 89961 times by 2 tests: return;Executed by:
| 89961 | ||||||||||||||||||||||||
| 123 | } | - | ||||||||||||||||||||||||
| 124 | CRYPTO_THREAD_write_lock(sec_malloc_lock); | - | ||||||||||||||||||||||||
| 125 | actual_size = sh_actual_size(ptr); | - | ||||||||||||||||||||||||
| 126 | OPENSSL_cleanse(ptr, actual_size); | - | ||||||||||||||||||||||||
| 127 | secure_mem_used -= actual_size; | - | ||||||||||||||||||||||||
| 128 | sh_free(ptr); | - | ||||||||||||||||||||||||
| 129 | CRYPTO_THREAD_unlock(sec_malloc_lock); | - | ||||||||||||||||||||||||
| 130 | - | |||||||||||||||||||||||||
| 131 | - | |||||||||||||||||||||||||
| 132 | - | |||||||||||||||||||||||||
| 133 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||||||||
| 134 | - | |||||||||||||||||||||||||
| 135 | void CRYPTO_secure_clear_free(void *ptr, size_t num, | - | ||||||||||||||||||||||||
| 136 | const char *file, int line) | - | ||||||||||||||||||||||||
| 137 | { | - | ||||||||||||||||||||||||
| 138 | - | |||||||||||||||||||||||||
| 139 | size_t actual_size; | - | ||||||||||||||||||||||||
| 140 | - | |||||||||||||||||||||||||
| 141 | if (ptr ==
| 1083348-1110433 | ||||||||||||||||||||||||
| 142 | ((void *)0)
| 1083348-1110433 | ||||||||||||||||||||||||
| 143 | ) | - | ||||||||||||||||||||||||
| 144 | return; executed 1082014 times by 2 tests: return;Executed by:
| 1082014 | ||||||||||||||||||||||||
| 145 | if (!CRYPTO_secure_allocated(ptr)
| 1-1123891 | ||||||||||||||||||||||||
| 146 | OPENSSL_cleanse(ptr, num); | - | ||||||||||||||||||||||||
| 147 | CRYPTO_free(ptr, file, line); | - | ||||||||||||||||||||||||
| 148 | return; executed 1140790 times by 2 tests: return;Executed by:
| 1140790 | ||||||||||||||||||||||||
| 149 | } | - | ||||||||||||||||||||||||
| 150 | CRYPTO_THREAD_write_lock(sec_malloc_lock); | - | ||||||||||||||||||||||||
| 151 | actual_size = sh_actual_size(ptr); | - | ||||||||||||||||||||||||
| 152 | OPENSSL_cleanse(ptr, actual_size); | - | ||||||||||||||||||||||||
| 153 | secure_mem_used -= actual_size; | - | ||||||||||||||||||||||||
| 154 | sh_free(ptr); | - | ||||||||||||||||||||||||
| 155 | CRYPTO_THREAD_unlock(sec_malloc_lock); | - | ||||||||||||||||||||||||
| 156 | - | |||||||||||||||||||||||||
| 157 | - | |||||||||||||||||||||||||
| 158 | - | |||||||||||||||||||||||||
| 159 | - | |||||||||||||||||||||||||
| 160 | - | |||||||||||||||||||||||||
| 161 | - | |||||||||||||||||||||||||
| 162 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||||||||||||||
| 163 | - | |||||||||||||||||||||||||
| 164 | int CRYPTO_secure_allocated(const void *ptr) | - | ||||||||||||||||||||||||
| 165 | { | - | ||||||||||||||||||||||||
| 166 | - | |||||||||||||||||||||||||
| 167 | int ret; | - | ||||||||||||||||||||||||
| 168 | - | |||||||||||||||||||||||||
| 169 | if (!secure_mem_initialized
| 8-1194110 | ||||||||||||||||||||||||
| 170 | return executed 1188449 times by 2 tests: 0;return 0;Executed by:
executed 1188449 times by 2 tests: return 0;Executed by:
| 1188449 | ||||||||||||||||||||||||
| 171 | CRYPTO_THREAD_write_lock(sec_malloc_lock); | - | ||||||||||||||||||||||||
| 172 | ret = sh_allocated(ptr); | - | ||||||||||||||||||||||||
| 173 | CRYPTO_THREAD_unlock(sec_malloc_lock); | - | ||||||||||||||||||||||||
| 174 | return executed 8 times by 1 test: ret;return ret;Executed by:
executed 8 times by 1 test: return ret;Executed by:
| 8 | ||||||||||||||||||||||||
| 175 | - | |||||||||||||||||||||||||
| 176 | - | |||||||||||||||||||||||||
| 177 | - | |||||||||||||||||||||||||
| 178 | } | - | ||||||||||||||||||||||||
| 179 | - | |||||||||||||||||||||||||
| 180 | size_t CRYPTO_secure_used(void) | - | ||||||||||||||||||||||||
| 181 | { | - | ||||||||||||||||||||||||
| 182 | - | |||||||||||||||||||||||||
| 183 | return executed 4 times by 1 test: secure_mem_used;return secure_mem_used;Executed by:
executed 4 times by 1 test: return secure_mem_used;Executed by:
| 4 | ||||||||||||||||||||||||
| 184 | - | |||||||||||||||||||||||||
| 185 | - | |||||||||||||||||||||||||
| 186 | - | |||||||||||||||||||||||||
| 187 | } | - | ||||||||||||||||||||||||
| 188 | - | |||||||||||||||||||||||||
| 189 | size_t CRYPTO_secure_actual_size(void *ptr) | - | ||||||||||||||||||||||||
| 190 | { | - | ||||||||||||||||||||||||
| 191 | - | |||||||||||||||||||||||||
| 192 | size_t actual_size; | - | ||||||||||||||||||||||||
| 193 | - | |||||||||||||||||||||||||
| 194 | CRYPTO_THREAD_write_lock(sec_malloc_lock); | - | ||||||||||||||||||||||||
| 195 | actual_size = sh_actual_size(ptr); | - | ||||||||||||||||||||||||
| 196 | CRYPTO_THREAD_unlock(sec_malloc_lock); | - | ||||||||||||||||||||||||
| 197 | return never executed: actual_size;return actual_size;never executed: return actual_size; | 0 | ||||||||||||||||||||||||
| 198 | - | |||||||||||||||||||||||||
| 199 | - | |||||||||||||||||||||||||
| 200 | - | |||||||||||||||||||||||||
| 201 | } | - | ||||||||||||||||||||||||
| 202 | typedef struct sh_list_st | - | ||||||||||||||||||||||||
| 203 | { | - | ||||||||||||||||||||||||
| 204 | struct sh_list_st *next; | - | ||||||||||||||||||||||||
| 205 | struct sh_list_st **p_next; | - | ||||||||||||||||||||||||
| 206 | } SH_LIST; | - | ||||||||||||||||||||||||
| 207 | - | |||||||||||||||||||||||||
| 208 | typedef struct sh_st | - | ||||||||||||||||||||||||
| 209 | { | - | ||||||||||||||||||||||||
| 210 | char* map_result; | - | ||||||||||||||||||||||||
| 211 | size_t map_size; | - | ||||||||||||||||||||||||
| 212 | char *arena; | - | ||||||||||||||||||||||||
| 213 | size_t arena_size; | - | ||||||||||||||||||||||||
| 214 | char **freelist; | - | ||||||||||||||||||||||||
| 215 | ssize_t freelist_size; | - | ||||||||||||||||||||||||
| 216 | size_t minsize; | - | ||||||||||||||||||||||||
| 217 | unsigned char *bittable; | - | ||||||||||||||||||||||||
| 218 | unsigned char *bitmalloc; | - | ||||||||||||||||||||||||
| 219 | size_t bittable_size; | - | ||||||||||||||||||||||||
| 220 | } SH; | - | ||||||||||||||||||||||||
| 221 | - | |||||||||||||||||||||||||
| 222 | static SH sh; | - | ||||||||||||||||||||||||
| 223 | - | |||||||||||||||||||||||||
| 224 | static size_t sh_getlist(char *ptr) | - | ||||||||||||||||||||||||
| 225 | { | - | ||||||||||||||||||||||||
| 226 | ssize_t list = sh.freelist_size - 1; | - | ||||||||||||||||||||||||
| 227 | size_t bit = (sh.arena_size + ptr - sh.arena) / sh.minsize; | - | ||||||||||||||||||||||||
| 228 | - | |||||||||||||||||||||||||
| 229 | for (; bit
| 0-12 | ||||||||||||||||||||||||
| 230 | if ((
| 3-9 | ||||||||||||||||||||||||
| 231 | break; executed 9 times by 1 test: break;Executed by:
| 9 | ||||||||||||||||||||||||
| 232 | (void)(((bit & 1) == 0) ? 0 : (OPENSSL_die("assertion failed: " "(bit & 1) == 0", __FILE__, 302), 1)); | - | ||||||||||||||||||||||||
| 233 | } executed 3 times by 1 test: end of blockExecuted by:
| 3 | ||||||||||||||||||||||||
| 234 | - | |||||||||||||||||||||||||
| 235 | return executed 9 times by 1 test: list;return list;Executed by:
executed 9 times by 1 test: return list;Executed by:
| 9 | ||||||||||||||||||||||||
| 236 | } | - | ||||||||||||||||||||||||
| 237 | - | |||||||||||||||||||||||||
| 238 | - | |||||||||||||||||||||||||
| 239 | static int sh_testbit(char *ptr, int list, unsigned char *table) | - | ||||||||||||||||||||||||
| 240 | { | - | ||||||||||||||||||||||||
| 241 | size_t bit; | - | ||||||||||||||||||||||||
| 242 | - | |||||||||||||||||||||||||
| 243 | (void)((list >= 0 && list < sh.freelist_size) ? 0 : (OPENSSL_die("assertion failed: " "list >= 0 && list < sh.freelist_size", __FILE__, 313), 1)); | - | ||||||||||||||||||||||||
| 244 | (void)((((ptr - sh.arena) & ((sh.arena_size >> list) - 1)) == 0) ? 0 : (OPENSSL_die("assertion failed: " "((ptr - sh.arena) & ((sh.arena_size >> list) - 1)) == 0", __FILE__, 314), 1)); | - | ||||||||||||||||||||||||
| 245 | bit = (((size_t)1) << list) + ((ptr - sh.arena) / (sh.arena_size >> list)); | - | ||||||||||||||||||||||||
| 246 | (void)((bit > 0 && bit < sh.bittable_size) ? 0 : (OPENSSL_die("assertion failed: " "bit > 0 && bit < sh.bittable_size", __FILE__, 316), 1)); | - | ||||||||||||||||||||||||
| 247 | return executed 90 times by 1 test: (table[(bit) >> 3] & (((size_t)1) << ((bit) & 7)));return (table[(bit) >> 3] & (((size_t)1) << ((bit) & 7)));Executed by:
executed 90 times by 1 test: return (table[(bit) >> 3] & (((size_t)1) << ((bit) & 7)));Executed by:
| 90 | ||||||||||||||||||||||||
| 248 | } | - | ||||||||||||||||||||||||
| 249 | - | |||||||||||||||||||||||||
| 250 | static void sh_clearbit(char *ptr, int list, unsigned char *table) | - | ||||||||||||||||||||||||
| 251 | { | - | ||||||||||||||||||||||||
| 252 | size_t bit; | - | ||||||||||||||||||||||||
| 253 | - | |||||||||||||||||||||||||
| 254 | (void)((list >= 0 && list < sh.freelist_size) ? 0 : (OPENSSL_die("assertion failed: " "list >= 0 && list < sh.freelist_size", __FILE__, 324), 1)); | - | ||||||||||||||||||||||||
| 255 | (void)((((ptr - sh.arena) & ((sh.arena_size >> list) - 1)) == 0) ? 0 : (OPENSSL_die("assertion failed: " "((ptr - sh.arena) & ((sh.arena_size >> list) - 1)) == 0", __FILE__, 325), 1)); | - | ||||||||||||||||||||||||
| 256 | bit = (((size_t)1) << list) + ((ptr - sh.arena) / (sh.arena_size >> list)); | - | ||||||||||||||||||||||||
| 257 | (void)((bit > 0 && bit < sh.bittable_size) ? 0 : (OPENSSL_die("assertion failed: " "bit > 0 && bit < sh.bittable_size", __FILE__, 327), 1)); | - | ||||||||||||||||||||||||
| 258 | (void)(((table[(bit) >> 3] & (((size_t)1) << ((bit) & 7)))) ? 0 : (OPENSSL_die("assertion failed: " "TESTBIT(table, bit)", __FILE__, 328), 1)); | - | ||||||||||||||||||||||||
| 259 | (table[(bit) >> 3] &= (0xFF & ~(((size_t)1) << ((bit) & 7)))); | - | ||||||||||||||||||||||||
| 260 | } executed 42 times by 1 test: end of blockExecuted by:
| 42 | ||||||||||||||||||||||||
| 261 | - | |||||||||||||||||||||||||
| 262 | static void sh_setbit(char *ptr, int list, unsigned char *table) | - | ||||||||||||||||||||||||
| 263 | { | - | ||||||||||||||||||||||||
| 264 | size_t bit; | - | ||||||||||||||||||||||||
| 265 | - | |||||||||||||||||||||||||
| 266 | (void)((list >= 0 && list < sh.freelist_size) ? 0 : (OPENSSL_die("assertion failed: " "list >= 0 && list < sh.freelist_size", __FILE__, 336), 1)); | - | ||||||||||||||||||||||||
| 267 | (void)((((ptr - sh.arena) & ((sh.arena_size >> list) - 1)) == 0) ? 0 : (OPENSSL_die("assertion failed: " "((ptr - sh.arena) & ((sh.arena_size >> list) - 1)) == 0", __FILE__, 337), 1)); | - | ||||||||||||||||||||||||
| 268 | bit = (((size_t)1) << list) + ((ptr - sh.arena) / (sh.arena_size >> list)); | - | ||||||||||||||||||||||||
| 269 | (void)((bit > 0 && bit < sh.bittable_size) ? 0 : (OPENSSL_die("assertion failed: " "bit > 0 && bit < sh.bittable_size", __FILE__, 339), 1)); | - | ||||||||||||||||||||||||
| 270 | (void)((!(table[(bit) >> 3] & (((size_t)1) << ((bit) & 7)))) ? 0 : (OPENSSL_die("assertion failed: " "!TESTBIT(table, bit)", __FILE__, 340), 1)); | - | ||||||||||||||||||||||||
| 271 | (table[(bit) >> 3] |= (((size_t)1) << ((bit) & 7))); | - | ||||||||||||||||||||||||
| 272 | } executed 45 times by 1 test: end of blockExecuted by:
| 45 | ||||||||||||||||||||||||
| 273 | - | |||||||||||||||||||||||||
| 274 | static void sh_add_to_list(char **list, char *ptr) | - | ||||||||||||||||||||||||
| 275 | { | - | ||||||||||||||||||||||||
| 276 | SH_LIST *temp; | - | ||||||||||||||||||||||||
| 277 | - | |||||||||||||||||||||||||
| 278 | (void)((((char*)(list) >= (char*)sh.freelist && (char*)(list) < (char*)&sh.freelist[sh.freelist_size])) ? 0 : (OPENSSL_die("assertion failed: " "WITHIN_FREELIST(list)", __FILE__, 348), 1)); | - | ||||||||||||||||||||||||
| 279 | (void)((((char*)(ptr) >= sh.arena && (char*)(ptr) < &sh.arena[sh.arena_size])) ? 0 : (OPENSSL_die("assertion failed: " "WITHIN_ARENA(ptr)", __FILE__, 349), 1)); | - | ||||||||||||||||||||||||
| 280 | - | |||||||||||||||||||||||||
| 281 | temp = (SH_LIST *)ptr; | - | ||||||||||||||||||||||||
| 282 | temp->next = *(SH_LIST **)list; | - | ||||||||||||||||||||||||
| 283 | (void)((temp->next == | - | ||||||||||||||||||||||||
| 284 | ((void *)0) | - | ||||||||||||||||||||||||
| 285 | || ((char*)(temp->next) >= sh.arena && (char*)(temp->next) < &sh.arena[sh.arena_size])) ? 0 : (OPENSSL_die("assertion failed: " "temp->next == NULL || WITHIN_ARENA(temp->next)", __FILE__, 353), 1)); | - | ||||||||||||||||||||||||
| 286 | temp->p_next = (SH_LIST **)list; | - | ||||||||||||||||||||||||
| 287 | - | |||||||||||||||||||||||||
| 288 | if (temp->next !=
| 19-26 | ||||||||||||||||||||||||
| 289 | ((void *)0)
| 19-26 | ||||||||||||||||||||||||
| 290 | ) { | - | ||||||||||||||||||||||||
| 291 | (void)(((char **)temp->next->p_next == list) ? 0 : (OPENSSL_die("assertion failed: " "(char **)temp->next->p_next == list", __FILE__, 357), 1)); | - | ||||||||||||||||||||||||
| 292 | temp->next->p_next = &(temp->next); | - | ||||||||||||||||||||||||
| 293 | } executed 26 times by 1 test: end of blockExecuted by:
| 26 | ||||||||||||||||||||||||
| 294 | - | |||||||||||||||||||||||||
| 295 | *list = ptr; | - | ||||||||||||||||||||||||
| 296 | } executed 45 times by 1 test: end of blockExecuted by:
| 45 | ||||||||||||||||||||||||
| 297 | - | |||||||||||||||||||||||||
| 298 | static void sh_remove_from_list(char *ptr) | - | ||||||||||||||||||||||||
| 299 | { | - | ||||||||||||||||||||||||
| 300 | SH_LIST *temp, *temp2; | - | ||||||||||||||||||||||||
| 301 | - | |||||||||||||||||||||||||
| 302 | temp = (SH_LIST *)ptr; | - | ||||||||||||||||||||||||
| 303 | if (temp->next !=
| 16-26 | ||||||||||||||||||||||||
| 304 | ((void *)0)
| 16-26 | ||||||||||||||||||||||||
| 305 | ) | - | ||||||||||||||||||||||||
| 306 | temp->next->p_next = temp->p_next; executed 26 times by 1 test: temp->next->p_next = temp->p_next;Executed by:
| 26 | ||||||||||||||||||||||||
| 307 | *temp->p_next = temp->next; | - | ||||||||||||||||||||||||
| 308 | if (temp->next ==
| 16-26 | ||||||||||||||||||||||||
| 309 | ((void *)0)
| 16-26 | ||||||||||||||||||||||||
| 310 | ) | - | ||||||||||||||||||||||||
| 311 | return; executed 16 times by 1 test: return;Executed by:
| 16 | ||||||||||||||||||||||||
| 312 | - | |||||||||||||||||||||||||
| 313 | temp2 = temp->next; | - | ||||||||||||||||||||||||
| 314 | (void)((((char*)(temp2->p_next) >= (char*)sh.freelist && (char*)(temp2->p_next) < (char*)&sh.freelist[sh.freelist_size]) || ((char*)(temp2->p_next) >= sh.arena && (char*)(temp2->p_next) < &sh.arena[sh.arena_size])) ? 0 : (OPENSSL_die("assertion failed: " "WITHIN_FREELIST(temp2->p_next) || WITHIN_ARENA(temp2->p_next)", __FILE__, 376), 1)); | - | ||||||||||||||||||||||||
| 315 | } executed 26 times by 1 test: end of blockExecuted by:
| 26 | ||||||||||||||||||||||||
| 316 | - | |||||||||||||||||||||||||
| 317 | - | |||||||||||||||||||||||||
| 318 | static int sh_init(size_t size, int minsize) | - | ||||||||||||||||||||||||
| 319 | { | - | ||||||||||||||||||||||||
| 320 | int ret; | - | ||||||||||||||||||||||||
| 321 | size_t i; | - | ||||||||||||||||||||||||
| 322 | size_t pgsize; | - | ||||||||||||||||||||||||
| 323 | size_t aligned; | - | ||||||||||||||||||||||||
| 324 | - | |||||||||||||||||||||||||
| 325 | memset(&sh, 0, sizeof(sh)); | - | ||||||||||||||||||||||||
| 326 | - | |||||||||||||||||||||||||
| 327 | - | |||||||||||||||||||||||||
| 328 | (void)((size > 0) ? 0 : (OPENSSL_die("assertion failed: " "size > 0", __FILE__, 390), 1)); | - | ||||||||||||||||||||||||
| 329 | (void)(((size & (size - 1)) == 0) ? 0 : (OPENSSL_die("assertion failed: " "(size & (size - 1)) == 0", __FILE__, 391), 1)); | - | ||||||||||||||||||||||||
| 330 | (void)((minsize > 0) ? 0 : (OPENSSL_die("assertion failed: " "minsize > 0", __FILE__, 392), 1)); | - | ||||||||||||||||||||||||
| 331 | (void)(((minsize & (minsize - 1)) == 0) ? 0 : (OPENSSL_die("assertion failed: " "(minsize & (minsize - 1)) == 0", __FILE__, 393), 1)); | - | ||||||||||||||||||||||||
| 332 | if (size <= 0
| 0-4 | ||||||||||||||||||||||||
| 333 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||||||||
| 334 | if (minsize <= 0
| 0-4 | ||||||||||||||||||||||||
| 335 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||||||||
| 336 | - | |||||||||||||||||||||||||
| 337 | while (minsize < (int)sizeof(SH_LIST)
| 0-4 | ||||||||||||||||||||||||
| 338 | minsize *= 2; never executed: minsize *= 2; | 0 | ||||||||||||||||||||||||
| 339 | - | |||||||||||||||||||||||||
| 340 | sh.arena_size = size; | - | ||||||||||||||||||||||||
| 341 | sh.minsize = minsize; | - | ||||||||||||||||||||||||
| 342 | sh.bittable_size = (sh.arena_size / sh.minsize) * 2; | - | ||||||||||||||||||||||||
| 343 | - | |||||||||||||||||||||||||
| 344 | - | |||||||||||||||||||||||||
| 345 | if (sh.bittable_size >> 3 == 0
| 1-3 | ||||||||||||||||||||||||
| 346 | goto executed 1 time by 1 test: err;goto err;Executed by:
executed 1 time by 1 test: goto err;Executed by:
| 1 | ||||||||||||||||||||||||
| 347 | - | |||||||||||||||||||||||||
| 348 | sh.freelist_size = -1; | - | ||||||||||||||||||||||||
| 349 | for (i = sh.bittable_size; i
| 3-31 | ||||||||||||||||||||||||
| 350 | sh.freelist_size++; executed 31 times by 1 test: sh.freelist_size++;Executed by:
| 31 | ||||||||||||||||||||||||
| 351 | - | |||||||||||||||||||||||||
| 352 | sh.freelist = CRYPTO_zalloc(sh.freelist_size * sizeof(char *), __FILE__, 414); | - | ||||||||||||||||||||||||
| 353 | (void)((sh.freelist != | - | ||||||||||||||||||||||||
| 354 | ((void *)0) | - | ||||||||||||||||||||||||
| 355 | ) ? 0 : (OPENSSL_die("assertion failed: " "sh.freelist != NULL", __FILE__, 415), 1)); | - | ||||||||||||||||||||||||
| 356 | if (sh.freelist ==
| 0-3 | ||||||||||||||||||||||||
| 357 | ((void *)0)
| 0-3 | ||||||||||||||||||||||||
| 358 | ) | - | ||||||||||||||||||||||||
| 359 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||||||||
| 360 | - | |||||||||||||||||||||||||
| 361 | sh.bittable = CRYPTO_zalloc(sh.bittable_size >> 3, __FILE__, 419); | - | ||||||||||||||||||||||||
| 362 | (void)((sh.bittable != | - | ||||||||||||||||||||||||
| 363 | ((void *)0) | - | ||||||||||||||||||||||||
| 364 | ) ? 0 : (OPENSSL_die("assertion failed: " "sh.bittable != NULL", __FILE__, 420), 1)); | - | ||||||||||||||||||||||||
| 365 | if (sh.bittable ==
| 0-3 | ||||||||||||||||||||||||
| 366 | ((void *)0)
| 0-3 | ||||||||||||||||||||||||
| 367 | ) | - | ||||||||||||||||||||||||
| 368 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||||||||
| 369 | - | |||||||||||||||||||||||||
| 370 | sh.bitmalloc = CRYPTO_zalloc(sh.bittable_size >> 3, __FILE__, 424); | - | ||||||||||||||||||||||||
| 371 | (void)((sh.bitmalloc != | - | ||||||||||||||||||||||||
| 372 | ((void *)0) | - | ||||||||||||||||||||||||
| 373 | ) ? 0 : (OPENSSL_die("assertion failed: " "sh.bitmalloc != NULL", __FILE__, 425), 1)); | - | ||||||||||||||||||||||||
| 374 | if (sh.bitmalloc ==
| 0-3 | ||||||||||||||||||||||||
| 375 | ((void *)0)
| 0-3 | ||||||||||||||||||||||||
| 376 | ) | - | ||||||||||||||||||||||||
| 377 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||||||||
| 378 | - | |||||||||||||||||||||||||
| 379 | - | |||||||||||||||||||||||||
| 380 | - | |||||||||||||||||||||||||
| 381 | { | - | ||||||||||||||||||||||||
| 382 | - | |||||||||||||||||||||||||
| 383 | long tmppgsize = sysconf( | - | ||||||||||||||||||||||||
| 384 | _SC_PAGESIZE | - | ||||||||||||||||||||||||
| 385 | ); | - | ||||||||||||||||||||||||
| 386 | - | |||||||||||||||||||||||||
| 387 | - | |||||||||||||||||||||||||
| 388 | - | |||||||||||||||||||||||||
| 389 | if (tmppgsize < 1
| 0-3 | ||||||||||||||||||||||||
| 390 | pgsize = 4096; never executed: pgsize = 4096; | 0 | ||||||||||||||||||||||||
| 391 | else | - | ||||||||||||||||||||||||
| 392 | pgsize = (size_t)tmppgsize; executed 3 times by 1 test: pgsize = (size_t)tmppgsize;Executed by:
| 3 | ||||||||||||||||||||||||
| 393 | } | - | ||||||||||||||||||||||||
| 394 | - | |||||||||||||||||||||||||
| 395 | - | |||||||||||||||||||||||||
| 396 | - | |||||||||||||||||||||||||
| 397 | sh.map_size = pgsize + sh.arena_size + pgsize; | - | ||||||||||||||||||||||||
| 398 | if (1) { | - | ||||||||||||||||||||||||
| 399 | - | |||||||||||||||||||||||||
| 400 | sh.map_result = mmap( | - | ||||||||||||||||||||||||
| 401 | ((void *)0) | - | ||||||||||||||||||||||||
| 402 | , sh.map_size, | - | ||||||||||||||||||||||||
| 403 | - | |||||||||||||||||||||||||
| 404 | 0x1 | - | ||||||||||||||||||||||||
| 405 | | | - | ||||||||||||||||||||||||
| 406 | 0x2 | - | ||||||||||||||||||||||||
| 407 | , | - | ||||||||||||||||||||||||
| 408 | 0x20 | - | ||||||||||||||||||||||||
| 409 | | | - | ||||||||||||||||||||||||
| 410 | 0x02 | - | ||||||||||||||||||||||||
| 411 | , -1, 0); | - | ||||||||||||||||||||||||
| 412 | } executed 3 times by 1 test: else {end of blockExecuted by:
dead code: { int fd; sh.map_result = ((void *) -1) ; if ((fd = open("/dev/zero", 02 )) >= 0) { sh.map_result = mmap( ((void *)0) , sh.map_size, 0x1 | 0x2 , 0x02 , fd, 0); close(fd); } } | - | ||||||||||||||||||||||||
| 413 | - | |||||||||||||||||||||||||
| 414 | int fd; dead code: { int fd; sh.map_result = ((void *) -1) ; if ((fd = open("/dev/zero", 02 )) >= 0) { sh.map_result = mmap( ((void *)0) , sh.map_size, 0x1 | 0x2 , 0x02 , fd, 0); close(fd); } } | - | ||||||||||||||||||||||||
| 415 | - | |||||||||||||||||||||||||
| 416 | sh.map_result = dead code: { int fd; sh.map_result = ((void *) -1) ; if ((fd = open("/dev/zero", 02 )) >= 0) { sh.map_result = mmap( ((void *)0) , sh.map_size, 0x1 | 0x2 , 0x02 , fd, 0); close(fd); } } | - | ||||||||||||||||||||||||
| 417 | ((void *) -1) dead code: { int fd; sh.map_result = ((void *) -1) ; if ((fd = open("/dev/zero", 02 )) >= 0) { sh.map_result = mmap( ((void *)0) , sh.map_size, 0x1 | 0x2 , 0x02 , fd, 0); close(fd); } } | - | ||||||||||||||||||||||||
| 418 | ; dead code: { int fd; sh.map_result = ((void *) -1) ; if ((fd = open("/dev/zero", 02 )) >= 0) { sh.map_result = mmap( ((void *)0) , sh.map_size, 0x1 | 0x2 , 0x02 , fd, 0); close(fd); } } | - | ||||||||||||||||||||||||
| 419 | if ((fd = open("/dev/zero", dead code: { int fd; sh.map_result = ((void *) -1) ; if ((fd = open("/dev/zero", 02 )) >= 0) { sh.map_result = mmap( ((void *)0) , sh.map_size, 0x1 | 0x2 , 0x02 , fd, 0); close(fd); } } | - | ||||||||||||||||||||||||
| 420 | 02 dead code: { int fd; sh.map_result = ((void *) -1) ; if ((fd = open("/dev/zero", 02 )) >= 0) { sh.map_result = mmap( ((void *)0) , sh.map_size, 0x1 | 0x2 , 0x02 , fd, 0); close(fd); } } | - | ||||||||||||||||||||||||
| 421 | )) >= 0) { dead code: { int fd; sh.map_result = ((void *) -1) ; if ((fd = open("/dev/zero", 02 )) >= 0) { sh.map_result = mmap( ((void *)0) , sh.map_size, 0x1 | 0x2 , 0x02 , fd, 0); close(fd); } } | - | ||||||||||||||||||||||||
| 422 | sh.map_result = mmap( dead code: { int fd; sh.map_result = ((void *) -1) ; if ((fd = open("/dev/zero", 02 )) >= 0) { sh.map_result = mmap( ((void *)0) , sh.map_size, 0x1 | 0x2 , 0x02 , fd, 0); close(fd); } } | - | ||||||||||||||||||||||||
| 423 | ((void *)0) dead code: { int fd; sh.map_result = ((void *) -1) ; if ((fd = open("/dev/zero", 02 )) >= 0) { sh.map_result = mmap( ((void *)0) , sh.map_size, 0x1 | 0x2 , 0x02 , fd, 0); close(fd); } } | - | ||||||||||||||||||||||||
| 424 | , sh.map_size, dead code: { int fd; sh.map_result = ((void *) -1) ; if ((fd = open("/dev/zero", 02 )) >= 0) { sh.map_result = mmap( ((void *)0) , sh.map_size, 0x1 | 0x2 , 0x02 , fd, 0); close(fd); } } | - | ||||||||||||||||||||||||
| 425 | dead code: { int fd; sh.map_result = ((void *) -1) ; if ((fd = open("/dev/zero", 02 )) >= 0) { sh.map_result = mmap( ((void *)0) , sh.map_size, 0x1 | 0x2 , 0x02 , fd, 0); close(fd); } } | - | ||||||||||||||||||||||||
| 426 | 0x1 dead code: { int fd; sh.map_result = ((void *) -1) ; if ((fd = open("/dev/zero", 02 )) >= 0) { sh.map_result = mmap( ((void *)0) , sh.map_size, 0x1 | 0x2 , 0x02 , fd, 0); close(fd); } } | - | ||||||||||||||||||||||||
| 427 | | dead code: { int fd; sh.map_result = ((void *) -1) ; if ((fd = open("/dev/zero", 02 )) >= 0) { sh.map_result = mmap( ((void *)0) , sh.map_size, 0x1 | 0x2 , 0x02 , fd, 0); close(fd); } } | - | ||||||||||||||||||||||||
| 428 | 0x2 dead code: { int fd; sh.map_result = ((void *) -1) ; if ((fd = open("/dev/zero", 02 )) >= 0) { sh.map_result = mmap( ((void *)0) , sh.map_size, 0x1 | 0x2 , 0x02 , fd, 0); close(fd); } } | - | ||||||||||||||||||||||||
| 429 | , dead code: { int fd; sh.map_result = ((void *) -1) ; if ((fd = open("/dev/zero", 02 )) >= 0) { sh.map_result = mmap( ((void *)0) , sh.map_size, 0x1 | 0x2 , 0x02 , fd, 0); close(fd); } } | - | ||||||||||||||||||||||||
| 430 | 0x02 dead code: { int fd; sh.map_result = ((void *) -1) ; if ((fd = open("/dev/zero", 02 )) >= 0) { sh.map_result = mmap( ((void *)0) , sh.map_size, 0x1 | 0x2 , 0x02 , fd, 0); close(fd); } } | - | ||||||||||||||||||||||||
| 431 | , fd, 0); dead code: { int fd; sh.map_result = ((void *) -1) ; if ((fd = open("/dev/zero", 02 )) >= 0) { sh.map_result = mmap( ((void *)0) , sh.map_size, 0x1 | 0x2 , 0x02 , fd, 0); close(fd); } } | - | ||||||||||||||||||||||||
| 432 | close(fd); dead code: { int fd; sh.map_result = ((void *) -1) ; if ((fd = open("/dev/zero", 02 )) >= 0) { sh.map_result = mmap( ((void *)0) , sh.map_size, 0x1 | 0x2 , 0x02 , fd, 0); close(fd); } } | - | ||||||||||||||||||||||||
| 433 | } dead code: { int fd; sh.map_result = ((void *) -1) ; if ((fd = open("/dev/zero", 02 )) >= 0) { sh.map_result = mmap( ((void *)0) , sh.map_size, 0x1 | 0x2 , 0x02 , fd, 0); close(fd); } } | - | ||||||||||||||||||||||||
| 434 | } dead code: { int fd; sh.map_result = ((void *) -1) ; if ((fd = open("/dev/zero", 02 )) >= 0) { sh.map_result = mmap( ((void *)0) , sh.map_size, 0x1 | 0x2 , 0x02 , fd, 0); close(fd); } } | - | ||||||||||||||||||||||||
| 435 | if (sh.map_result ==
| 0-3 | ||||||||||||||||||||||||
| 436 | ((void *) -1)
| 0-3 | ||||||||||||||||||||||||
| 437 | ) | - | ||||||||||||||||||||||||
| 438 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||||||||
| 439 | sh.arena = (char *)(sh.map_result + pgsize); | - | ||||||||||||||||||||||||
| 440 | sh_setbit(sh.arena, 0, sh.bittable); | - | ||||||||||||||||||||||||
| 441 | sh_add_to_list(&sh.freelist[0], sh.arena); | - | ||||||||||||||||||||||||
| 442 | - | |||||||||||||||||||||||||
| 443 | - | |||||||||||||||||||||||||
| 444 | ret = 1; | - | ||||||||||||||||||||||||
| 445 | - | |||||||||||||||||||||||||
| 446 | - | |||||||||||||||||||||||||
| 447 | if (mprotect(sh.map_result, pgsize,
| 0-3 | ||||||||||||||||||||||||
| 448 | 0x0
| 0-3 | ||||||||||||||||||||||||
| 449 | ) < 0
| 0-3 | ||||||||||||||||||||||||
| 450 | ret = 2; never executed: ret = 2; | 0 | ||||||||||||||||||||||||
| 451 | - | |||||||||||||||||||||||||
| 452 | - | |||||||||||||||||||||||||
| 453 | aligned = (pgsize + sh.arena_size + (pgsize - 1)) & ~(pgsize - 1); | - | ||||||||||||||||||||||||
| 454 | if (mprotect(sh.map_result + aligned, pgsize,
| 0-3 | ||||||||||||||||||||||||
| 455 | 0x0
| 0-3 | ||||||||||||||||||||||||
| 456 | ) < 0
| 0-3 | ||||||||||||||||||||||||
| 457 | ret = 2; never executed: ret = 2; | 0 | ||||||||||||||||||||||||
| 458 | - | |||||||||||||||||||||||||
| 459 | - | |||||||||||||||||||||||||
| 460 | if (syscall(
| 0-3 | ||||||||||||||||||||||||
| 461 | 325
| 0-3 | ||||||||||||||||||||||||
| 462 | , sh.arena, sh.arena_size,
| 0-3 | ||||||||||||||||||||||||
| 463 | 0x01
| 0-3 | ||||||||||||||||||||||||
| 464 | ) < 0
| 0-3 | ||||||||||||||||||||||||
| 465 | if ( | - | ||||||||||||||||||||||||
| 466 | (*
| 0 | ||||||||||||||||||||||||
| 467 | ==
| 0 | ||||||||||||||||||||||||
| 468 | 38
| 0 | ||||||||||||||||||||||||
| 469 | ) { | - | ||||||||||||||||||||||||
| 470 | if (mlock(sh.arena, sh.arena_size) < 0
| 0 | ||||||||||||||||||||||||
| 471 | ret = 2; never executed: ret = 2; | 0 | ||||||||||||||||||||||||
| 472 | } never executed: else {end of block | 0 | ||||||||||||||||||||||||
| 473 | ret = 2; | - | ||||||||||||||||||||||||
| 474 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 475 | } | - | ||||||||||||||||||||||||
| 476 | - | |||||||||||||||||||||||||
| 477 | - | |||||||||||||||||||||||||
| 478 | - | |||||||||||||||||||||||||
| 479 | - | |||||||||||||||||||||||||
| 480 | - | |||||||||||||||||||||||||
| 481 | if (madvise(sh.arena, sh.arena_size,
| 0-3 | ||||||||||||||||||||||||
| 482 | 16
| 0-3 | ||||||||||||||||||||||||
| 483 | ) < 0
| 0-3 | ||||||||||||||||||||||||
| 484 | ret = 2; never executed: ret = 2; | 0 | ||||||||||||||||||||||||
| 485 | - | |||||||||||||||||||||||||
| 486 | - | |||||||||||||||||||||||||
| 487 | return executed 3 times by 1 test: ret;return ret;Executed by:
executed 3 times by 1 test: return ret;Executed by:
| 3 | ||||||||||||||||||||||||
| 488 | - | |||||||||||||||||||||||||
| 489 | err: | - | ||||||||||||||||||||||||
| 490 | sh_done(); | - | ||||||||||||||||||||||||
| 491 | return executed 1 time by 1 test: 0;return 0;Executed by:
executed 1 time by 1 test: return 0;Executed by:
| 1 | ||||||||||||||||||||||||
| 492 | } | - | ||||||||||||||||||||||||
| 493 | - | |||||||||||||||||||||||||
| 494 | static void sh_done(void) | - | ||||||||||||||||||||||||
| 495 | { | - | ||||||||||||||||||||||||
| 496 | CRYPTO_free(sh.freelist, __FILE__, 506); | - | ||||||||||||||||||||||||
| 497 | CRYPTO_free(sh.bittable, __FILE__, 507); | - | ||||||||||||||||||||||||
| 498 | CRYPTO_free(sh.bitmalloc, __FILE__, 508); | - | ||||||||||||||||||||||||
| 499 | if (sh.map_result !=
| 3-2077 | ||||||||||||||||||||||||
| 500 | ((void *)0)
| 3-2077 | ||||||||||||||||||||||||
| 501 | && sh.map_size
| 0-3 | ||||||||||||||||||||||||
| 502 | munmap(sh.map_result, sh.map_size); executed 3 times by 1 test: munmap(sh.map_result, sh.map_size);Executed by:
| 3 | ||||||||||||||||||||||||
| 503 | memset(&sh, 0, sizeof(sh)); | - | ||||||||||||||||||||||||
| 504 | } executed 2080 times by 12 tests: end of blockExecuted by:
| 2080 | ||||||||||||||||||||||||
| 505 | - | |||||||||||||||||||||||||
| 506 | static int sh_allocated(const char *ptr) | - | ||||||||||||||||||||||||
| 507 | { | - | ||||||||||||||||||||||||
| 508 | return executed 8 times by 1 test: ((return ((char*)(ptr) >= sh.arena && (char*)(ptr) < &sh.arena[sh.arena_size]) ? 1 : 0;Executed by:
executed 8 times by 1 test: return ((char*)(ptr) >= sh.arena && (char*)(ptr) < &sh.arena[sh.arena_size]) ? 1 : 0;Executed by:
| 0-8 | ||||||||||||||||||||||||
| 509 | } | - | ||||||||||||||||||||||||
| 510 | - | |||||||||||||||||||||||||
| 511 | static char *sh_find_my_buddy(char *ptr, int list) | - | ||||||||||||||||||||||||
| 512 | { | - | ||||||||||||||||||||||||
| 513 | size_t bit; | - | ||||||||||||||||||||||||
| 514 | char *chunk = | - | ||||||||||||||||||||||||
| 515 | ((void *)0) | - | ||||||||||||||||||||||||
| 516 | ; | - | ||||||||||||||||||||||||
| 517 | - | |||||||||||||||||||||||||
| 518 | bit = (((size_t)1) << list) + (ptr - sh.arena) / (sh.arena_size >> list); | - | ||||||||||||||||||||||||
| 519 | bit ^= 1; | - | ||||||||||||||||||||||||
| 520 | - | |||||||||||||||||||||||||
| 521 | if ((
| 1-40 | ||||||||||||||||||||||||
| 522 | chunk = sh.arena + ((bit & ((((size_t)1) << list) - 1)) * (sh.arena_size >> list)); executed 39 times by 1 test: chunk = sh.arena + ((bit & ((((size_t)1) << list) - 1)) * (sh.arena_size >> list));Executed by:
| 39 | ||||||||||||||||||||||||
| 523 | - | |||||||||||||||||||||||||
| 524 | return executed 42 times by 1 test: chunk;return chunk;Executed by:
executed 42 times by 1 test: return chunk;Executed by:
| 42 | ||||||||||||||||||||||||
| 525 | } | - | ||||||||||||||||||||||||
| 526 | - | |||||||||||||||||||||||||
| 527 | static void *sh_malloc(size_t size) | - | ||||||||||||||||||||||||
| 528 | { | - | ||||||||||||||||||||||||
| 529 | ssize_t list, slist; | - | ||||||||||||||||||||||||
| 530 | size_t i; | - | ||||||||||||||||||||||||
| 531 | char *chunk; | - | ||||||||||||||||||||||||
| 532 | - | |||||||||||||||||||||||||
| 533 | if (size > sh.arena_size
| 1-3 | ||||||||||||||||||||||||
| 534 | return executed 1 time by 1 test: return ((void *)0) ;Executed by:
executed 1 time by 1 test: return ((void *)0) ;Executed by:
| 1 | ||||||||||||||||||||||||
| 535 | ((void *)0) executed 1 time by 1 test: return ((void *)0) ;Executed by:
| 1 | ||||||||||||||||||||||||
| 536 | ; executed 1 time by 1 test: return ((void *)0) ;Executed by:
| 1 | ||||||||||||||||||||||||
| 537 | - | |||||||||||||||||||||||||
| 538 | list = sh.freelist_size - 1; | - | ||||||||||||||||||||||||
| 539 | for (i = sh.minsize; i < size
| 1-3 | ||||||||||||||||||||||||
| 540 | list--; executed 1 time by 1 test: list--;Executed by:
| 1 | ||||||||||||||||||||||||
| 541 | if (list < 0
| 0-3 | ||||||||||||||||||||||||
| 542 | return never executed: return ((void *)0) ;never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
| 543 | ((void *)0) never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
| 544 | ; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
| 545 | - | |||||||||||||||||||||||||
| 546 | - | |||||||||||||||||||||||||
| 547 | for (slist = list; slist >= 0
| 0-16 | ||||||||||||||||||||||||
| 548 | if (sh.freelist[slist] !=
| 3-13 | ||||||||||||||||||||||||
| 549 | ((void *)0)
| 3-13 | ||||||||||||||||||||||||
| 550 | ) | - | ||||||||||||||||||||||||
| 551 | break; executed 3 times by 1 test: break;Executed by:
| 3 | ||||||||||||||||||||||||
| 552 | if (slist < 0
| 0-3 | ||||||||||||||||||||||||
| 553 | return never executed: return ((void *)0) ;never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
| 554 | ((void *)0) never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
| 555 | ; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
| 556 | - | |||||||||||||||||||||||||
| 557 | - | |||||||||||||||||||||||||
| 558 | while (slist != list
| 3-13 | ||||||||||||||||||||||||
| 559 | char *temp = sh.freelist[slist]; | - | ||||||||||||||||||||||||
| 560 | - | |||||||||||||||||||||||||
| 561 | - | |||||||||||||||||||||||||
| 562 | (void)((!sh_testbit(temp, slist, sh.bitmalloc)) ? 0 : (OPENSSL_die("assertion failed: " "!sh_testbit(temp, slist, sh.bitmalloc)", __FILE__, 560), 1)); | - | ||||||||||||||||||||||||
| 563 | sh_clearbit(temp, slist, sh.bittable); | - | ||||||||||||||||||||||||
| 564 | sh_remove_from_list(temp); | - | ||||||||||||||||||||||||
| 565 | (void)((temp != sh.freelist[slist]) ? 0 : (OPENSSL_die("assertion failed: " "temp != sh.freelist[slist]", __FILE__, 563), 1)); | - | ||||||||||||||||||||||||
| 566 | - | |||||||||||||||||||||||||
| 567 | - | |||||||||||||||||||||||||
| 568 | slist++; | - | ||||||||||||||||||||||||
| 569 | - | |||||||||||||||||||||||||
| 570 | - | |||||||||||||||||||||||||
| 571 | (void)((!sh_testbit(temp, slist, sh.bitmalloc)) ? 0 : (OPENSSL_die("assertion failed: " "!sh_testbit(temp, slist, sh.bitmalloc)", __FILE__, 569), 1)); | - | ||||||||||||||||||||||||
| 572 | sh_setbit(temp, slist, sh.bittable); | - | ||||||||||||||||||||||||
| 573 | sh_add_to_list(&sh.freelist[slist], temp); | - | ||||||||||||||||||||||||
| 574 | (void)((sh.freelist[slist] == temp) ? 0 : (OPENSSL_die("assertion failed: " "sh.freelist[slist] == temp", __FILE__, 572), 1)); | - | ||||||||||||||||||||||||
| 575 | - | |||||||||||||||||||||||||
| 576 | - | |||||||||||||||||||||||||
| 577 | temp += sh.arena_size >> slist; | - | ||||||||||||||||||||||||
| 578 | (void)((!sh_testbit(temp, slist, sh.bitmalloc)) ? 0 : (OPENSSL_die("assertion failed: " "!sh_testbit(temp, slist, sh.bitmalloc)", __FILE__, 576), 1)); | - | ||||||||||||||||||||||||
| 579 | sh_setbit(temp, slist, sh.bittable); | - | ||||||||||||||||||||||||
| 580 | sh_add_to_list(&sh.freelist[slist], temp); | - | ||||||||||||||||||||||||
| 581 | (void)((sh.freelist[slist] == temp) ? 0 : (OPENSSL_die("assertion failed: " "sh.freelist[slist] == temp", __FILE__, 579), 1)); | - | ||||||||||||||||||||||||
| 582 | - | |||||||||||||||||||||||||
| 583 | (void)((temp-(sh.arena_size >> slist) == sh_find_my_buddy(temp, slist)) ? 0 : (OPENSSL_die("assertion failed: " "temp-(sh.arena_size >> slist) == sh_find_my_buddy(temp, slist)", __FILE__, 581), 1)); | - | ||||||||||||||||||||||||
| 584 | } executed 13 times by 1 test: end of blockExecuted by:
| 13 | ||||||||||||||||||||||||
| 585 | - | |||||||||||||||||||||||||
| 586 | - | |||||||||||||||||||||||||
| 587 | chunk = sh.freelist[list]; | - | ||||||||||||||||||||||||
| 588 | (void)((sh_testbit(chunk, list, sh.bittable)) ? 0 : (OPENSSL_die("assertion failed: " "sh_testbit(chunk, list, sh.bittable)", __FILE__, 586), 1)); | - | ||||||||||||||||||||||||
| 589 | sh_setbit(chunk, list, sh.bitmalloc); | - | ||||||||||||||||||||||||
| 590 | sh_remove_from_list(chunk); | - | ||||||||||||||||||||||||
| 591 | - | |||||||||||||||||||||||||
| 592 | (void)((((char*)(chunk) >= sh.arena && (char*)(chunk) < &sh.arena[sh.arena_size])) ? 0 : (OPENSSL_die("assertion failed: " "WITHIN_ARENA(chunk)", __FILE__, 590), 1)); | - | ||||||||||||||||||||||||
| 593 | - | |||||||||||||||||||||||||
| 594 | - | |||||||||||||||||||||||||
| 595 | memset(chunk, 0, sizeof(SH_LIST)); | - | ||||||||||||||||||||||||
| 596 | - | |||||||||||||||||||||||||
| 597 | return executed 3 times by 1 test: chunk;return chunk;Executed by:
executed 3 times by 1 test: return chunk;Executed by:
| 3 | ||||||||||||||||||||||||
| 598 | } | - | ||||||||||||||||||||||||
| 599 | - | |||||||||||||||||||||||||
| 600 | static void sh_free(void *ptr) | - | ||||||||||||||||||||||||
| 601 | { | - | ||||||||||||||||||||||||
| 602 | size_t list; | - | ||||||||||||||||||||||||
| 603 | void *buddy; | - | ||||||||||||||||||||||||
| 604 | - | |||||||||||||||||||||||||
| 605 | if (ptr ==
| 0-3 | ||||||||||||||||||||||||
| 606 | ((void *)0)
| 0-3 | ||||||||||||||||||||||||
| 607 | ) | - | ||||||||||||||||||||||||
| 608 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 609 | (void)((((char*)(ptr) >= sh.arena && (char*)(ptr) < &sh.arena[sh.arena_size])) ? 0 : (OPENSSL_die("assertion failed: " "WITHIN_ARENA(ptr)", __FILE__, 605), 1)); | - | ||||||||||||||||||||||||
| 610 | if (!((
| 0-3 | ||||||||||||||||||||||||
| 611 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 612 | - | |||||||||||||||||||||||||
| 613 | list = sh_getlist(ptr); | - | ||||||||||||||||||||||||
| 614 | (void)((sh_testbit(ptr, list, sh.bittable)) ? 0 : (OPENSSL_die("assertion failed: " "sh_testbit(ptr, list, sh.bittable)", __FILE__, 610), 1)); | - | ||||||||||||||||||||||||
| 615 | sh_clearbit(ptr, list, sh.bitmalloc); | - | ||||||||||||||||||||||||
| 616 | sh_add_to_list(&sh.freelist[list], ptr); | - | ||||||||||||||||||||||||
| 617 | - | |||||||||||||||||||||||||
| 618 | - | |||||||||||||||||||||||||
| 619 | while ((
| 3-13 | ||||||||||||||||||||||||
| 620 | ((void *)0)
| 3-13 | ||||||||||||||||||||||||
| 621 | ) { | - | ||||||||||||||||||||||||
| 622 | (void)((ptr == sh_find_my_buddy(buddy, list)) ? 0 : (OPENSSL_die("assertion failed: " "ptr == sh_find_my_buddy(buddy, list)", __FILE__, 616), 1)); | - | ||||||||||||||||||||||||
| 623 | (void)((ptr != | - | ||||||||||||||||||||||||
| 624 | ((void *)0) | - | ||||||||||||||||||||||||
| 625 | ) ? 0 : (OPENSSL_die("assertion failed: " "ptr != NULL", __FILE__, 617), 1)); | - | ||||||||||||||||||||||||
| 626 | (void)((!sh_testbit(ptr, list, sh.bitmalloc)) ? 0 : (OPENSSL_die("assertion failed: " "!sh_testbit(ptr, list, sh.bitmalloc)", __FILE__, 618), 1)); | - | ||||||||||||||||||||||||
| 627 | sh_clearbit(ptr, list, sh.bittable); | - | ||||||||||||||||||||||||
| 628 | sh_remove_from_list(ptr); | - | ||||||||||||||||||||||||
| 629 | (void)((!sh_testbit(ptr, list, sh.bitmalloc)) ? 0 : (OPENSSL_die("assertion failed: " "!sh_testbit(ptr, list, sh.bitmalloc)", __FILE__, 621), 1)); | - | ||||||||||||||||||||||||
| 630 | sh_clearbit(buddy, list, sh.bittable); | - | ||||||||||||||||||||||||
| 631 | sh_remove_from_list(buddy); | - | ||||||||||||||||||||||||
| 632 | - | |||||||||||||||||||||||||
| 633 | list--; | - | ||||||||||||||||||||||||
| 634 | - | |||||||||||||||||||||||||
| 635 | - | |||||||||||||||||||||||||
| 636 | memset(ptr > buddy ? ptr : buddy, 0, sizeof(SH_LIST)); | - | ||||||||||||||||||||||||
| 637 | if (ptr > buddy
| 1-12 | ||||||||||||||||||||||||
| 638 | ptr = buddy; executed 12 times by 1 test: ptr = buddy;Executed by:
| 12 | ||||||||||||||||||||||||
| 639 | - | |||||||||||||||||||||||||
| 640 | (void)((!sh_testbit(ptr, list, sh.bitmalloc)) ? 0 : (OPENSSL_die("assertion failed: " "!sh_testbit(ptr, list, sh.bitmalloc)", __FILE__, 632), 1)); | - | ||||||||||||||||||||||||
| 641 | sh_setbit(ptr, list, sh.bittable); | - | ||||||||||||||||||||||||
| 642 | sh_add_to_list(&sh.freelist[list], ptr); | - | ||||||||||||||||||||||||
| 643 | (void)((sh.freelist[list] == ptr) ? 0 : (OPENSSL_die("assertion failed: " "sh.freelist[list] == ptr", __FILE__, 635), 1)); | - | ||||||||||||||||||||||||
| 644 | } executed 13 times by 1 test: end of blockExecuted by:
| 13 | ||||||||||||||||||||||||
| 645 | } executed 3 times by 1 test: end of blockExecuted by:
| 3 | ||||||||||||||||||||||||
| 646 | - | |||||||||||||||||||||||||
| 647 | static size_t sh_actual_size(char *ptr) | - | ||||||||||||||||||||||||
| 648 | { | - | ||||||||||||||||||||||||
| 649 | int list; | - | ||||||||||||||||||||||||
| 650 | - | |||||||||||||||||||||||||
| 651 | (void)((((char*)(ptr) >= sh.arena && (char*)(ptr) < &sh.arena[sh.arena_size])) ? 0 : (OPENSSL_die("assertion failed: " "WITHIN_ARENA(ptr)", __FILE__, 643), 1)); | - | ||||||||||||||||||||||||
| 652 | if (!((
| 0-6 | ||||||||||||||||||||||||
| 653 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||||||||||||||
| 654 | list = sh_getlist(ptr); | - | ||||||||||||||||||||||||
| 655 | (void)((sh_testbit(ptr, list, sh.bittable)) ? 0 : (OPENSSL_die("assertion failed: " "sh_testbit(ptr, list, sh.bittable)", __FILE__, 647), 1)); | - | ||||||||||||||||||||||||
| 656 | return executed 6 times by 1 test: sh.arena_size / (((size_t)1) << list);return sh.arena_size / (((size_t)1) << list);Executed by:
executed 6 times by 1 test: return sh.arena_size / (((size_t)1) << list);Executed by:
| 6 | ||||||||||||||||||||||||
| 657 | } | - | ||||||||||||||||||||||||
| Switch to Source code | Preprocessed file |