]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-fts: Avoid NULL pointer arithmetic
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Mon, 9 Nov 2020 23:30:06 +0000 (01:30 +0200)
committerTimo Sirainen <timo.sirainen@open-xchange.com>
Mon, 9 Nov 2020 23:30:06 +0000 (01:30 +0200)
Even though it was only doing +0. Fixes:
runtime error: applying zero offset to null pointer

src/lib-fts/fts-tokenizer-generic.c
src/lib-fts/fts-tokenizer.c

index 4284f37abaeb22290da2ec93910bfe241c9917eb..844503c37758b0f47b714e993c27f73da4275fce 100644 (file)
@@ -297,7 +297,8 @@ fts_tokenizer_generic_simple_next(struct fts_tokenizer *_tok,
                }
        }
        /* word boundary not found yet */
-       tok_append_truncated(tok, data + start, i - start);
+       if (i > start)
+               tok_append_truncated(tok, data + start, i - start);
        *skip_r = i;
 
        /* return the last token */
@@ -757,7 +758,8 @@ fts_tokenizer_generic_tr29_next(struct fts_tokenizer *_tok,
                }
        }
        i_assert(i >= start_pos && size >= start_pos);
-       tok_append_truncated(tok, data + start_pos, i - start_pos);
+       if (i > start_pos)
+               tok_append_truncated(tok, data + start_pos, i - start_pos);
        *skip_r = i;
 
        if (size == 0 && tok->token->used > 0) {
index 8e9baa9f2c57f2264cf1e79c6da00566bfc2bbf0..989b52133986babe72cd761245f6c0505d30674c 100644 (file)
@@ -144,7 +144,15 @@ fts_tokenizer_next_self(struct fts_tokenizer *tok,
        } else {
                /* continuing previous data */
                i_assert(tok->prev_skip <= size);
-               ret = tok->v->next(tok, data + tok->prev_skip,
+
+               const unsigned char *data_next;
+               if (data != NULL)
+                       data_next = data + tok->prev_skip;
+               else {
+                       i_assert(tok->prev_skip == 0 && size == 0);
+                       data_next = NULL;
+               }
+               ret = tok->v->next(tok, data_next,
                                   size - tok->prev_skip, &skip,
                                   token_r, error_r);
        }