bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2007-2018 Dovecot authors, see the included COPYING file */
48acc31adebfdd4e4945ee76e1f5259e4b1b6fffTimo Sirainenstatic bool test_str_find_substring(const char *key, int expected_pos)
48acc31adebfdd4e4945ee76e1f5259e4b1b6fffTimo Sirainen const unsigned char *text = (const unsigned char *)str_find_text;
48acc31adebfdd4e4945ee76e1f5259e4b1b6fffTimo Sirainen const unsigned int text_len = strlen(str_find_text);
48acc31adebfdd4e4945ee76e1f5259e4b1b6fffTimo Sirainen ctx = str_find_init(pool_datastack_create(), key);
48acc31adebfdd4e4945ee76e1f5259e4b1b6fffTimo Sirainen /* divide text into every possible block combination and test that
48acc31adebfdd4e4945ee76e1f5259e4b1b6fffTimo Sirainen it matches */
48acc31adebfdd4e4945ee76e1f5259e4b1b6fffTimo Sirainen for (i = 0; i < max; i++) {
48acc31adebfdd4e4945ee76e1f5259e4b1b6fffTimo Sirainen for (j = 0; j < text_len; j++) {
48acc31adebfdd4e4945ee76e1f5259e4b1b6fffTimo Sirainen if ((i & (1 << j)) != 0) {
48acc31adebfdd4e4945ee76e1f5259e4b1b6fffTimo Sirainen unsigned int i;
48acc31adebfdd4e4945ee76e1f5259e4b1b6fffTimo Sirainen for (idx = 0; idx < strlen(str_find_text); idx++) {
48acc31adebfdd4e4945ee76e1f5259e4b1b6fffTimo Sirainen for (len = strlen(str_find_text)-idx; len > 0; len--) {
48acc31adebfdd4e4945ee76e1f5259e4b1b6fffTimo Sirainen /* we'll get a search key for all substrings of text */
48acc31adebfdd4e4945ee76e1f5259e4b1b6fffTimo Sirainen success = test_str_find_substring(key, p - str_find_text);
48acc31adebfdd4e4945ee76e1f5259e4b1b6fffTimo Sirainen for (i = 0; i < N_ELEMENTS(fail_input) && success; i++)