From: Timo Sirainen Date: Tue, 25 May 2004 23:21:56 +0000 (+0300) Subject: mail_index_lookup_uid_range(): don't crash if we look only UIDs larger than X-Git-Tag: 1.1.alpha1~4041 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b0a446671b8f09a1d2ed1d8c86a47298309e989d;p=thirdparty%2Fdovecot%2Fcore.git mail_index_lookup_uid_range(): don't crash if we look only UIDs larger than our next_uid --HG-- branch : HEAD --- diff --git a/src/lib-index/mail-index-view.c b/src/lib-index/mail-index-view.c index 9b7576c723..da5118df2d 100644 --- a/src/lib-index/mail-index-view.c +++ b/src/lib-index/mail-index-view.c @@ -267,6 +267,15 @@ int mail_index_lookup_uid_range(struct mail_index_view *view, if (mail_index_view_lock(view) < 0) return -1; + if (last_uid >= view->map->hdr->next_uid) { + last_uid = view->map->hdr->next_uid-1; + if (first_uid > last_uid) { + *first_seq_r = 0; + *last_seq_r = 0; + return 0; + } + } + left_idx = 0; *first_seq_r = mail_index_bsearch_uid(view, first_uid, &left_idx, 1); if (*first_seq_r == 0 || @@ -280,9 +289,6 @@ int mail_index_lookup_uid_range(struct mail_index_view *view, return 0; } - if (last_uid >= view->map->hdr->next_uid) - last_uid = view->map->hdr->next_uid-1; - /* optimization - binary lookup only from right side: */ *last_seq_r = mail_index_bsearch_uid(view, last_uid, &left_idx, -1); i_assert(*last_seq_r >= *first_seq_r);