From: Sebastian Harl Date: Thu, 20 Feb 2014 21:41:26 +0000 (+0100) Subject: date_test: Added some simple overflow tests. X-Git-Tag: sysdb-0.1.0~201 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=91f2b91816a7c84393237baef85f4838e65686d7;p=sysdb.git date_test: Added some simple overflow tests. --- diff --git a/t/core/data_test.c b/t/core/data_test.c index 420ee85..8af042a 100644 --- a/t/core/data_test.c +++ b/t/core/data_test.c @@ -154,16 +154,25 @@ START_TEST(test_format) for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_data); ++i) { sdb_data_t *datum = &golden_data[i].datum; - char buf[sdb_data_strlen(datum) + 1]; + char buf[sdb_data_strlen(datum) + 2]; int check; - check = sdb_data_format(datum, buf, sizeof(buf)); + memset(buf, (int)'A', sizeof(buf)); + + check = sdb_data_format(datum, buf, sizeof(buf) - 1); fail_unless(! check, "sdb_data_format(type=%s) = %d; expected: 0", SDB_TYPE_TO_STRING(datum->type), check); fail_unless(! strcmp(buf, golden_data[i].expected), "sdb_data_format(type=%s) used wrong format: %s; expected: %s", SDB_TYPE_TO_STRING(datum->type), buf, golden_data[i].expected); + + fail_unless(buf[sizeof(buf) - 2] == '\0', + "sdb_data_format(type=%s) did not nul-terminate the buffer", + SDB_TYPE_TO_STRING(datum->type)); + fail_unless(buf[sizeof(buf) - 1] == 'A', + "sdb_data_format(type=%s) wrote past the end of the buffer", + SDB_TYPE_TO_STRING(datum->type)); } } END_TEST