Skip to content

Commit

Permalink
tests: internal: sds: add test for #7143 off by 1 bug
Browse files Browse the repository at this point in the history
Signed-off-by: Wesley Pettit <[email protected]>
  • Loading branch information
PettitWesley authored and edsiper committed Apr 11, 2023
1 parent 61ed59c commit 30f5a3e
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/internal/sds.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,36 @@ static void test_sds_printf()
flb_sds_destroy(s);
}

/* https://github.com/fluent/fluent-bit/issues/7143 */
static void test_sds_printf_7143_off_by_1()
{
flb_sds_t tmp;
flb_sds_t test;
flb_sds_t test2;
int len;

/* 66 char final string, not impacted by bug */
test = flb_sds_create_size(64);
TEST_CHECK(test != NULL);
tmp = flb_sds_printf(&test, "A0123456789 %s", "this-is-54-chars-1234567890-abcdefghijklmnopqrstuvwxyz");
TEST_CHECK(tmp != NULL);
len = flb_sds_len(test);
TEST_CHECK(len == 66);
TEST_CHECK(test[len -1] == 'z');
flb_sds_destroy(test);

/* 65 char final string, impacted by bug */
test2 = flb_sds_create_size(64);
TEST_CHECK(test2 != NULL);
tmp = flb_sds_printf(&test2, "0123456789 %s", "this-is-54-chars-1234567890-abcdefghijklmnopqrstuvwxyz");
TEST_CHECK(tmp != NULL);
len = flb_sds_len(test2);
TEST_CHECK(len == 65);
TEST_CHECK(test2[len -1] == 'z');
flb_sds_destroy(test2);

}

static void test_sds_cat_utf8()
{
flb_sds_t s;
Expand All @@ -53,5 +83,6 @@ TEST_LIST = {
{ "sds_usage" , test_sds_usage},
{ "sds_printf", test_sds_printf},
{ "sds_cat_utf8", test_sds_cat_utf8},
{ "test_sds_printf_7143_off_by_1", test_sds_printf_7143_off_by_1},
{ 0 }
};

0 comments on commit 30f5a3e

Please sign in to comment.