test_begin("fatal_array");
t_array_init(&ad, 3);
/* allocation big enough, but memory not initialised */
+ test_expect_fatal_string("(array_idx_i): assertion failed: (idx * array->element_size < array->buffer->used)");
useless_ptr = array_idx(&ad, 0);
return FATAL_TEST_FAILURE;
}
t_array_init(&ad, 2);
array_append(&ad, tmpd, 2);
/* actual out of range address requested */
+ test_expect_fatal_string("(array_idx_i): assertion failed: (idx * array->element_size < array->buffer->used)");
useless_ptr = array_idx(&ad, 2);
return FATAL_TEST_FAILURE;
}
t_array_init(&ad, 2);
t_array_init(&as, 8);
array_append(&as, tmps, 2);
+ /* can't copy different array sizes */
+ test_expect_fatal_string("(array_copy): assertion failed: (dest->element_size == src->element_size)");
array_copy(&ad.arr, 1, &as.arr, 0, 4);
return FATAL_TEST_FAILURE;
}
undo_data = *undo_ptr;
*undo_ptr = '*';
/* t_malloc_no0 will panic block header corruption */
+ test_expect_fatal_string("Corrupted data stack canary");
(void)t_malloc_no0(10);
return FATAL_TEST_FAILURE;
}
undo_data = *undo_ptr;
*undo_ptr = '*';
/* t_pop will now fail */
+ test_expect_fatal_string("buffer overflow");
(void)t_pop(&t_id);
t_id = NONEXISTENT_STACK_FRAME_ID; /* We're FUBAR, mustn't pop next entry */
return FATAL_TEST_FAILURE;
undo_data = *undo_ptr;
*undo_ptr = '*';
/* t_pop will now fail */
+ test_expect_fatal_string("buffer overflow");
(void)t_pop(&t_id);
t_id = NONEXISTENT_STACK_FRAME_ID; /* We're FUBAR, mustn't pop next entry */
return FATAL_TEST_FAILURE;
};
unsigned int i;
+ test_expect_fatal_string("memory allocation overflow");
switch (*stage) {
case 0:
test_begin("MALLOC_MULTIPLY() overflows");
*stage -= N_ELEMENTS(mul_tests)*2;
if (*stage == 0)
test_end();
+ test_expect_fatal_string(NULL);
return FATAL_TEST_FINISHED;
}
i = *stage / 2;
};
unsigned int i;
+ test_expect_fatal_string("memory allocation overflow");
switch (*stage) {
case 0:
test_begin("MALLOC_ADD() overflows");
*stage -= N_ELEMENTS(add_tests)*2;
if (*stage == 0)
test_end();
+ test_expect_fatal_string(NULL);
return FATAL_TEST_FINISHED;
}
i = *stage / 2;
case 0: /* forbidden size */
test_begin("fatal_mempool_allocfree");
pool = pool_allocfree_create("fatal");
+ test_expect_fatal_string("Trying to allocate 0 bytes");
(void)p_malloc(pool, 0);
return FATAL_TEST_FAILURE;
case 1: /* logically impossible size */
+ test_expect_fatal_string("Trying to allocate");
(void)p_malloc(pool, SSIZE_T_MAX + 1ULL);
return FATAL_TEST_FAILURE;
case 2: /* physically impossible size */
+ test_expect_fatal_string("Out of memory");
(void)p_malloc(pool, SSIZE_T_MAX - 1024);
return FATAL_TEST_FAILURE;
case 0: /* forbidden size */
test_begin("fatal_mempool_alloconly");
pool = pool_alloconly_create(MEMPOOL_GROWING"fatal", 1);
+ test_expect_fatal_string("Trying to allocate 0 bytes");
(void)p_malloc(pool, 0);
return FATAL_TEST_FAILURE;
case 1: /* logically impossible size */
+ test_expect_fatal_string("Trying to allocate");
(void)p_malloc(pool, SSIZE_T_MAX + 1ULL);
return FATAL_TEST_FAILURE;
case 2: /* physically impossible size */
+ test_expect_fatal_string("Out of memory");
(void)p_malloc(pool, SSIZE_T_MAX - 1024);
return FATAL_TEST_FAILURE;
static uint32max_array_t *m1;
static uint32_t *m2;
+ test_expect_fatal_string("memory allocation overflow");
#if SIZEOF_VOID_P == 8
switch(stage) {
case 0:
#else
# error unsupported pointer size
#endif
+ test_expect_fatal_string(NULL);
test_end();
return FATAL_TEST_FINISHED;
}
/* Want to test the panics too? go for it! */
enum fatal_test_state fatal_printf_format_fix(unsigned int stage)
{
- static const char *fatals[] = {
- "no no no %n's",
- "no no no %-1234567890123n's with extra stuff",
- "%m allowed once, but not twice: %m",
- "%m must not obscure a later %n",
- "definitely can't have a tailing %",
- "Evil %**%n",
- "Evil %*#%99999$s",
- "No weird %% with %0%",
- "No duplicate modifiers %00s",
- "Minimum length can't be too long %10000s",
- "Minimum length doesn't support %*1$s",
- "Precision can't be too long %.10000s",
- "Precision can't be too long %1.10000s",
- "Precision doesn't support %1.-1s",
+ static const struct {
+ const char *format;
+ const char *expected_fatal;
+ } fatals[] = {
+ { "no no no %n's", "%n modifier used" },
+ { "no no no %-1234567890123n's with extra stuff", "Too large minimum field width" },
+ { "%m allowed once, but not twice: %m", "%m used twice" },
+ { "%m must not obscure a later %n", "%n modifier used" },
+ { "definitely can't have a tailing %", "Missing % specifier" },
+ { "Evil %**%n", "Unsupported 0x2a specifier" },
+ { "Evil %*#%99999$s", "Unsupported 0x23 specifier" },
+ { "No weird %% with %0%", "Unsupported 0x25 specifier" },
+ { "No duplicate modifiers %00s", "Duplicate % flag '0'" },
+ { "Minimum length can't be too long %10000s", "Too large minimum field width" },
+ { "Minimum length doesn't support %*1$s", "Unsupported 0x31 specifier" },
+ { "Precision can't be too long %.10000s", "Too large precision" },
+ { "Precision can't be too long %1.10000s", "Too large precision" },
+ { "Precision doesn't support %1.-1s", "Unsupported 0x2d specifier" },
};
if(stage >= N_ELEMENTS(fatals)) {
test_begin("fatal_printf_format_fix");
/* let's crash! */
- (void)printf_format_fix(fatals[stage]);
+ test_expect_fatal_string(fatals[stage].expected_fatal);
+ (void)printf_format_fix(fatals[stage].format);
return FATAL_TEST_FAILURE;
}