grosjo / fts-xapian

Dovecot FTS plugin based on Xapian
GNU Lesser General Public License v2.1
97 stars 21 forks source link

Regression: segfault on 1.5.0 #103

Closed symphorien closed 3 years ago

symphorien commented 3 years ago

This segfault does not happen when I downgrade to 1.4.14

#0  fts_user_autoindex_exclude (box=box@entry=0x555c6279c0d8) at fts-user.c:347
        fuser = 0x0
#1  0x00007f444c5c7686 in fts_mailbox_allocated (box=0x555c6279c0d8) at fts-storage.c:806
        flist = <optimized out>
        v = 0x555c6279c748
        fbox = 0x555c6279c8e0
#2  0x00007f444ca55e88 in hook_mailbox_allocated (box=box@entry=0x555c6279c0d8) at mail-storage-hooks.c:256
        _data_stack_cur_id = 0x5
        _foreach_end = 0x555c6278d278
        _foreach_ptr = 0x555c6278d258
        hooks = 0x7f444c62f120 <fts_mail_storage_hooks>
        ctx = 0x555c6279d908
#3  0x00007f444ca51009 in mailbox_alloc (list=<optimized out>, vname=0x555c62747660 "INBOX", flags=flags@entry=MAILBOX_FLAG_DROP_RECENT) at mail-storage.c:885
        _data_stack_cur_id = 0x4
        new_list = 0x555c62795c88
        storage = 0x555c62796498
        box = 0x555c6279c0d8
        open_error = MAIL_ERROR_NONE
        errstr = 0x0
        __func__ = "mailbox_alloc"
#4  0x0000555c61885586 in select_open (readonly=0x0, mailbox=<optimized out>, ctx=0x555c62793478) at cmd-select.c:285
        client = 0x555c62790ab8
        status = {
          messages = 0x20,
          recent = 0x0,
          unseen = 0x21,
          uidvalidity = 0x0,
          uidnext = 0xfffffff8,
          first_unseen_seq = 0x7,
          first_recent_uid = 0x4c943942,
          last_cached_seq = 0x7f44,
          highest_modseq = 0x21,
          highest_pvt_modseq = 0x7f444c919562,
          keywords = 0x20,
          permanent_flags = 1285468640,
          flags = 32580,
          permanent_keywords = 0x0,
          allow_new_keywords = 0x0,
          nonpermanent_modseqs = 0x0,
          no_modseq_tracking = 0x0,
          have_guids = 0x1,
          have_save_guids = 0x0,
          have_only_guid128 = 0x1
        }
        flags = MAILBOX_FLAG_DROP_RECENT
        ret = 0x0
        client = <optimized out>
        status = {
          messages = <optimized out>,
          recent = <optimized out>,
          unseen = <optimized out>,
          uidvalidity = <optimized out>,
          uidnext = <optimized out>,
          first_unseen_seq = <optimized out>,
          first_recent_uid = <optimized out>,
          last_cached_seq = <optimized out>,
          highest_modseq = <optimized out>,
          highest_pvt_modseq = <optimized out>,
          keywords = <optimized out>,
          permanent_flags = <optimized out>,
          flags = <optimized out>,
          permanent_keywords = <optimized out>,
          allow_new_keywords = <optimized out>,
          nonpermanent_modseqs = <optimized out>,
          no_modseq_tracking = <optimized out>,
          have_guids = <optimized out>,
          have_save_guids = <optimized out>,
          have_only_guid128 = <optimized out>
        }
        flags = <optimized out>
        ret = <optimized out>
#5  cmd_select_full (cmd=<optimized out>, readonly=<optimized out>) at cmd-select.c:416
        client = 0x555c62790ab8
        ctx = 0x555c62793478
        args = 0x555c6275e0e0
        list_args = 0x3100000005
        mailbox = 0x555c62747660 "INBOX"
        client_error = 0x0
        ret = <optimized out>
        __func__ = "cmd_select_full"
#6  0x0000555c6188d4e4 in command_exec (cmd=0x555c627932d8) at imap-commands.c:201
        hook = 0x555c627535d0
        finished = <optimized out>
        __func__ = "command_exec"
#7  0x0000555c6188b4df in client_command_input (cmd=<optimized out>) at imap-client.c:1230
        client = 0x555c62790ab8
        command = <optimized out>
        tag = 0x7f444c957c4a <p_strdup+74> "]A\\A]\303E1\300L\211\300\303f\017\037\204"
        name = 0x555c618a1e50 "SELECT"
        ret = <optimized out>
        __func__ = "client_command_input"
#8  0x0000555c6188b58a in client_command_input (cmd=<optimized out>) at imap-client.c:1297
        client = 0x555c62790ab8
        command = <optimized out>
        tag = 0x555c6275e238 "A0004"
        name = 0x555c6275e240 "SELECT"
        ret = <optimized out>
        __func__ = "client_command_input"
#9  0x0000555c6188ba05 in client_handle_next_command (remove_io_r=<synthetic pointer>, client=0x555c62790ab8) at imap-client.c:1339
No locals.
#10 client_handle_input (client=0x555c62790ab8) at imap-client.c:1353
        _data_stack_cur_id = 0x3
        ret = <optimized out>
        remove_io = 0x0
        handled_commands = 0x0
        __func__ = "client_handle_input"
#11 0x0000555c6188bf70 in client_input (client=0x555c62790ab8) at imap-client.c:1397
        cmd = 0x555c6275b6e8
        output = 0x555c62793130
        bytes = 0x16
        __func__ = "client_input"
#12 0x00007f444c939c89 in io_loop_call_io (io=0x555c62793aa0) at ioloop.c:737
        ioloop = 0x555c6274fee0
        t_id = 0x2
        __func__ = "io_loop_call_io"
#13 0x00007f444c93b322 in io_loop_handler_run_internal (ioloop=ioloop@entry=0x555c6274fee0) at ioloop-epoll.c:222
        ctx = 0x555c62752610
        events = <optimized out>
        event = 0x555c62752690
        list = 0x555c6275b6d0
        io = <optimized out>
        tv = {
          tv_sec = 0x707,
          tv_usec = 0xf3f3b
        }
        events_count = <optimized out>
        msecs = <optimized out>
        ret = 0x1
        i = 0x0
        j = 0x0
        call = <optimized out>
        __func__ = "io_loop_handler_run_internal"
#14 0x00007f444c939d30 in io_loop_handler_run (ioloop=0x555c6274fee0) at ioloop.c:789
        __func__ = "io_loop_handler_run"
#15 0x00007f444c939ef0 in io_loop_run (ioloop=0x555c6274fee0) at ioloop.c:762
        __func__ = "io_loop_run"
#16 0x00007f444c8ad9f3 in master_service_run (service=0x555c6274fd40, callback=callback@entry=0x555c61899ee0 <client_connected>) at master-service.c:863
No locals.
#17 0x0000555c6187cf8a in main (argc=<optimized out>, argv=<optimized out>) at main.c:564
        set_roots = {0x555c618ae8e0 <smtp_submit_setting_parser_info>, 0x555c618ae600 <imap_setting_parser_info>, 0x0}
        login_set = {
          auth_socket_path = 0x555c627477f0 "8xtb\\U",
          postlogin_socket_path = 0x0,
          postlogin_timeout_secs = 0x3c,
          callback = 0x555c6189a880 <login_client_connected>,
          failure_callback = 0x555c61899fb0 <login_client_failed>,
          request_auth_token = 0x1
        }
        service_flags = <optimized out>
        storage_service_flags = <optimized out>
        username = 0x0
        auth_socket_path = <optimized out>
        c = <optimized out>
        error = 0x40 <error: Cannot access memory at address 0x40>

dovecot 2.3.17

grosjo commented 3 years ago

This has no link with the plugin, right ? (according to the debug data)

symphorien commented 3 years ago

Yes it does, as it disappears if I downgrade. Surely fts_xapian is corrupting some memory that segfaults later in dovecot.

symphorien commented 3 years ago

Log under valgrind suggest the segfault happens just after fts_xapian returns:

server # 2021-11-11T09:52:21.702939+00:00 server dovecot: imap(user1@example.com)<1461><xChKTIDQSp/AqAEB>: FTS Xapian: Index path = /var/vmail/example.com/user1/xapian-indexes
server # [   55.850037] dovecot[1009]: imap(user1@example.com)<1461><xChKTIDQSp/AqAEB>: Debug: Namespace : /var/vmail/example.com/user1 doesn't exist yet, using default permissions
server # [   55.851668] dovecot[1009]: imap(user1@example.com)<1461><xChKTIDQSp/AqAEB>: Debug: Namespace : Using permissions from /var/vmail/example.com/user1: mode=0700 gid=default
server # 2021-11-11T09:52:21.710702+00:00 server dovecot: imap(user1@example.com)<1461><xChKTIDQSp/AqAEB>: Debug: Namespace : /var/vmail/example.com/user1 doesn't exist yet, using default p>
server # 2021-11-11T09:52:21.712333+00:00 server dovecot: imap(user1@example.com)<1461><xChKTIDQSp/AqAEB>: Debug: Namespace : Using permissions from /var/vmail/example.com/user1: mode=0700 >
server # [   55.858304] dovecot[1009]: imap(user1@example.com)<1461><xChKTIDQSp/AqAEB>: FTS Xapian: Starting with partial=2 full=20 verbose=1 lowmemory=200
server # 2021-11-11T09:52:21.718969+00:00 server dovecot: imap(user1@example.com)<1461><xChKTIDQSp/AqAEB>: FTS Xapian: Starting with partial=2 full=20 verbose=1 lowmemory=200
server # [   55.873913] dovecot[1009]: imap(user1@example.com)<1461><xChKTIDQSp/AqAEB>: Debug: quota: quota_over_flag check: quota_over_script unset - skipping
server # 2021-11-11T09:52:21.734576+00:00 server dovecot: imap(user1@example.com)<1461><xChKTIDQSp/AqAEB>: Debug: quota: quota_over_flag check: quota_over_script unset - skipping
server # [   55.882177] rspamd[1451]: <bmwaxo>; upstream; rspamd_upstream_fail: upstream 127.0.0.1 failed; reason: timeout waiting reply
server # [   55.883363] rspamd[1451]: <>; rdns; rdns_process_timer: reschedule request with id: 14567
server # 2021-11-11T09:52:21.742841+00:00 server rspamd[1451]: <bmwaxo>; upstream; rspamd_upstream_fail: upstream 127.0.0.1 failed; reason: timeout waiting reply
server # 2021-11-11T09:52:21.744030+00:00 server rspamd[1451]: <>; rdns; rdns_process_timer: reschedule request with id: 14567
server # [   55.886819] rspamd[1451]: <>; ; rspamd_dns_select_upstream_retransmit: select forced 127.0.0.1
server # [   55.888295] rspamd[1451]: <bmwaxo>; upstream; rspamd_upstream_fail: upstream 127.0.0.1 failed; reason: timeout waiting reply
server # 2021-11-11T09:52:21.747483+00:00 server rspamd[1451]: <>; ; rspamd_dns_select_upstream_retransmit: select forced 127.0.0.1
server # 2021-11-11T09:52:21.748960+00:00 server rspamd[1451]: <bmwaxo>; upstream; rspamd_upstream_fail: upstream 127.0.0.1 failed; reason: timeout waiting reply
server # [   55.893712] rspamd[1451]: <>; rdns; rdns_process_timer: reschedule request with id: 9337
server # [   55.895303] rspamd[1451]: <>; ; rspamd_dns_select_upstream_retransmit: select forced 127.0.0.1
server # 2021-11-11T09:52:21.754376+00:00 server rspamd[1451]: <>; rdns; rdns_process_timer: reschedule request with id: 9337
server # 2021-11-11T09:52:21.755968+00:00 server rspamd[1451]: <>; ; rspamd_dns_select_upstream_retransmit: select forced 127.0.0.1
server # [   55.930083] dovecot[1009]: imap: Error: ==1461== Invalid read of size 8
server # 2021-11-11T09:52:21.790747+00:00 server dovecot: imap: Error: ==1461== Invalid read of size 8
server # [   55.931885] dovecot[1009]: imap: Error: ==1461==    at 0x51A74D2: fts_user_autoindex_exclude.cold (fts-user.c:347)
server # 2021-11-11T09:52:21.792549+00:00 server dovecot: imap: Error: ==1461==    at 0x51A74D2: fts_user_autoindex_exclude.cold (fts-user.c:347)
server # [   55.934571] dovecot[1009]: imap: Error: ==1461==    by 0x51B0685: fts_mailbox_allocated (fts-storage.c:806)
server # 2021-11-11T09:52:21.795236+00:00 server dovecot: imap: Error: ==1461==    by 0x51B0685: fts_mailbox_allocated (fts-storage.c:806)
server # 2021-11-11T09:52:21.797845+00:00 server dovecot: imap: Error: ==1461==    by 0x48B7E87: hook_mailbox_allocated (mail-storage-hooks.c:256)
server # [   55.937180] dovecot[1009]: imap: Error: ==1461==    by 0x48B7E87: hook_mailbox_allocated (mail-storage-hooks.c:256)
server # [   55.941311] dovecot[1009]: imap: Error: ==1461==    by 0x48B3008: mailbox_alloc (mail-storage.c:885)
server # [   55.943485] dovecot[1009]: imap: Error: ==1461==    by 0x123585: select_open (cmd-select.c:285)
server # 2021-11-11T09:52:21.801976+00:00 server dovecot: imap: Error: ==1461==    by 0x48B3008: mailbox_alloc (mail-storage.c:885)
server # 2021-11-11T09:52:21.804150+00:00 server dovecot: imap: Error: ==1461==    by 0x123585: select_open (cmd-select.c:285)
server # [   55.947278] dovecot[1009]: imap: Error: ==1461==    by 0x123585: cmd_select_full (cmd-select.c:416)
server # 2021-11-11T09:52:21.807943+00:00 server dovecot: imap: Error: ==1461==    by 0x123585: cmd_select_full (cmd-select.c:416)
server # [   55.950415] dovecot[1009]: imap: Error: ==1461==    by 0x12B4E3: command_exec (imap-commands.c:201)
server # [   55.953618] dovecot[1009]: imap: Error: ==1461==    by 0x1294DE: client_command_input (imap-client.c:1230)
server # 2021-11-11T09:52:21.811079+00:00 server dovecot: imap: Error: ==1461==    by 0x12B4E3: command_exec (imap-commands.c:201)
server # 2021-11-11T09:52:21.814284+00:00 server dovecot: imap: Error: ==1461==    by 0x1294DE: client_command_input (imap-client.c:1230)
server # 2021-11-11T09:52:21.821083+00:00 server dovecot: imap: Error: ==1461==    by 0x129589: client_command_input (imap-client.c:1297)
server # [   55.960418] dovecot[1009]: imap: Error: ==1461==    by 0x129589: client_command_input (imap-client.c:1297)
server # [   55.962951] dovecot[1009]: imap: Error: ==1461==    by 0x129A04: client_handle_next_command (imap-client.c:1339)
server # 2021-11-11T09:52:21.823616+00:00 server dovecot: imap: Error: ==1461==    by 0x129A04: client_handle_next_command (imap-client.c:1339)
server # [   55.966629] dovecot[1009]: imap: Error: ==1461==    by 0x129A04: client_handle_input (imap-client.c:1353)
server # 2021-11-11T09:52:21.827294+00:00 server dovecot: imap: Error: ==1461==    by 0x129A04: client_handle_input (imap-client.c:1353)
server # [   55.975239] dovecot[1009]: imap: Error: ==1461==    by 0x129F6F: client_input (imap-client.c:1397)
server # [   55.976252] dovecot[1009]: imap: Error: ==1461==    by 0x4ADCC88: io_loop_call_io (ioloop.c:737)
server # 2021-11-11T09:52:21.835902+00:00 server dovecot: imap: Error: ==1461==    by 0x129F6F: client_input (imap-client.c:1397)
server # [   55.976252] dovecot[1009]: imap: Error: ==1461==    by 0x4ADCC88: io_loop_call_io (ioloop.c:737)
server # 2021-11-11T09:52:21.835902+00:00 server dovecot: imap: Error: ==1461==    by 0x129F6F: client_input (imap-client.c:1397)
server # 2021-11-11T09:52:21.836919+00:00 server dovecot: imap: Error: ==1461==    by 0x4ADCC88: io_loop_call_io (ioloop.c:737)
server # [   55.980347] dovecot[1009]: imap: Error: ==1461==    by 0x4ADE321: io_loop_handler_run_internal (ioloop-epoll.c:222)
server # 2021-11-11T09:52:21.841012+00:00 server dovecot: imap: Error: ==1461==    by 0x4ADE321: io_loop_handler_run_internal (ioloop-epoll.c:222)
server # [   56.012588] dovecot[1009]: imap: Error: ==1461==    by 0x4ADCD2F: io_loop_handler_run (ioloop.c:789)
server # 2021-11-11T09:52:21.873252+00:00 server dovecot: imap: Error: ==1461==    by 0x4ADCD2F: io_loop_handler_run (ioloop.c:789)
server # [   56.014879] dovecot[1009]: imap: Error: ==1461==    by 0x4ADCEEF: io_loop_run (ioloop.c:762)
server # 2021-11-11T09:52:21.875530+00:00 server dovecot: imap: Error: ==1461==    by 0x4ADCEEF: io_loop_run (ioloop.c:762)
server # [   56.016842] dovecot[1009]: imap: Error: ==1461==    by 0x4A509F2: master_service_run (master-service.c:863)
server # 2021-11-11T09:52:21.877507+00:00 server dovecot: imap: Error: ==1461==    by 0x4A509F2: master_service_run (master-service.c:863)
server # [   56.019133] dovecot[1009]: imap: Error: ==1461==    by 0x11AF89: main (main.c:564)
server # [   56.019962] dovecot[1009]: imap: Error: ==1461==  Address 0x50 is not stack'd, malloc'd or (recently) free'd
server # 2021-11-11T09:52:21.879799+00:00 server dovecot: imap: Error: ==1461==    by 0x11AF89: main (main.c:564)
server # 2021-11-11T09:52:21.880629+00:00 server dovecot: imap: Error: ==1461==  Address 0x50 is not stack'd, malloc'd or (recently) free'd
server # [   56.023130] dovecot[1009]: imap: Error: ==1461==
server # [   56.023725] dovecot[1009]: imap: Error: ==1461==
server # 2021-11-11T09:52:21.883796+00:00 server dovecot: imap: Error: ==1461==
server # 2021-11-11T09:52:21.884392+00:00 server dovecot: imap: Error: ==1461==
server # [   56.025640] dovecot[1009]: imap: Error: ==1461== Process terminating with default action of signal 11 (SIGSEGV): dumping core

Since address is 0x50, maybe fts_xapian is returning a null pointer when it shouldn't ?

symphorien commented 3 years ago

I bisected the bug down to 8b97b97ded078540e21458412ccba29998045574

It looks like you forgot to add the new AC_DEFINED variable to fts-xapian-config.h.in: here is the content of fts-xapian-config.h after ./configure:

/* fts-xapian-config.h.  Generated from fts-xapian-config.h.in by configure.  */
#define FTS_XAPIAN_NAME "Dovecot FTS Xapian"
#define FTS_XAPIAN_VERSION "1.5.0"

then DOVECOT_VERSION_MINOR_MINOR is undefined and CHECK_VERSION is false when it should be true.

you can compile with -Wundef to see that:

In file included from fts-xapian-plugin.c:4:
fts-xapian-plugin.c: In function 'fts_xapian_mail_user_created':
fts-xapian-plugin.h:50:83: warning: "DOVECOT_VERSION_MINOR_MINOR" is not defined, evaluates to 0 [8;;https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wundef-Wundef8;;]
   50 | #define CHECK_VERSION() (DOVECOT_VERSION_MAJOR > 2 || DOVECOT_VERSION_MINOR >3 || DOVECOT_VERSION_MINOR_MINOR > 16)
      |                                                                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~
fts-xapian-plugin.c:104:5: note: in expansion of macro 'CHECK_VERSION'
  104 | #if CHECK_VERSION()
      |     ^~~~~~~~~~~~~
grosjo commented 3 years ago

Please try with latest git

symphorien commented 3 years ago

Running dovecot during configure is incompatible with cross-compilation. Using ac_package version was better. Maybe you could do the version comparison inside ./configure with https://www.gnu.org/software/autoconf-archive/ax_compare_version.html instead of in the c preprocessor ?

grosjo commented 3 years ago

@symphorien how to get the current dovecot version from the configure.ac file ?

grosjo commented 3 years ago

@cmouse any idea on this topic of having "DOVECOT_VERSION" from configure.ac ?

symphorien commented 3 years ago

Maybe an approach like this could work:

AC_MSG_CHECKING([Whether fts_mail_user_init has 3 args])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
                   [[
                    #include "dovecot/lib.h"
                    #include "dovecot/fts-user.h"
                    void f(struct mail_user *s, const char **error) {
                      fts_mail_user_init(s, 0, error);
                    }
                  ]])], [
                         AC_MSG_RESULT([yes])
                         AC_DEFINE([FTS_MAIL_USER_INIT_3_ARGS], [1], ["yay"])
                         ], [
                         AC_MSG_RESULT([no])
                         AC_DEFINE([FTS_MAIL_USER_INIT_3_ARGS], [0], ["yay"])
                         ])

but I get weird errors including dovecot headers:

configure:18147: checking Whether fts_mail_user_init has 3 args
configure:18166: gcc -c -std=gnu99 -fstack-protector-strong -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2   conftest.c >&5
In file included from /nix/store/v15ahq9q9yps4k88mniyj3fwl12r38r1-dovecot-2.3.16/include/dovecot/lib.h:26,
                 from conftest.c:24:
/nix/store/v15ahq9q9yps4k88mniyj3fwl12r38r1-dovecot-2.3.16/include/dovecot/compat.h:68:4: error: #error uoff_t size not set
   68 | #  error uoff_t size not set
      |    ^~~~~
In file included from /nix/store/q141hd8jl7in5223jmf7kmx9h517km4p-glibc-2.32-54-dev/include/sys/socket.h:33,
                 from /nix/store/v15ahq9q9yps4k88mniyj3fwl12r38r1-dovecot-2.3.16/include/dovecot/compat.h:154,
                 from /nix/store/v15ahq9q9yps4k88mniyj3fwl12r38r1-dovecot-2.3.16/include/dovecot/lib.h:26,
                 from conftest.c:24:
/nix/store/q141hd8jl7in5223jmf7kmx9h517km4p-glibc-2.32-54-dev/include/bits/socket.h:33:21: error: conflicting types for 'socklen_t'
   33 | typedef __socklen_t socklen_t;
      |                     ^~~~~~~~~
In file included from /nix/store/v15ahq9q9yps4k88mniyj3fwl12r38r1-dovecot-2.3.16/include/dovecot/lib.h:26,
                 from conftest.c:24:
/nix/store/v15ahq9q9yps4k88mniyj3fwl12r38r1-dovecot-2.3.16/include/dovecot/compat.h:88:13: note: previous declaration of 'socklen_t' was here
   88 | typedef int socklen_t;
      |             ^~~~~~~~~
In file included from /nix/store/v15ahq9q9yps4k88mniyj3fwl12r38r1-dovecot-2.3.16/include/dovecot/lib.h:26,
                 from conftest.c:24:
/nix/store/v15ahq9q9yps4k88mniyj3fwl12r38r1-dovecot-2.3.16/include/dovecot/compat.h:181:8: error: redefinition of 'struct iovec'
  181 | struct iovec {
      |        ^~~~~
In file included from /nix/store/q141hd8jl7in5223jmf7kmx9h517km4p-glibc-2.32-54-dev/include/sys/socket.h:26,
                 from /nix/store/v15ahq9q9yps4k88mniyj3fwl12r38r1-dovecot-2.3.16/include/dovecot/compat.h:154,
                 from /nix/store/v15ahq9q9yps4k88mniyj3fwl12r38r1-dovecot-2.3.16/include/dovecot/lib.h:26,
                 from conftest.c:24:
/nix/store/q141hd8jl7in5223jmf7kmx9h517km4p-glibc-2.32-54-dev/include/bits/types/struct_iovec.h:26:8: note: originally defined here
   26 | struct iovec
      |        ^~~~~
In file included from /nix/store/v15ahq9q9yps4k88mniyj3fwl12r38r1-dovecot-2.3.16/include/dovecot/lib.h:27,
                 from conftest.c:24:
/nix/store/v15ahq9q9yps4k88mniyj3fwl12r38r1-dovecot-2.3.16/include/dovecot/mempool.h: In function 'p_malloc':
/nix/store/v15ahq9q9yps4k88mniyj3fwl12r38r1-dovecot-2.3.16/include/dovecot/mempool.h:104:35: error: 'SSIZE_T_MAX' undeclared (first use in this function); did you mean 'SSIZE_MAX'?
  104 |  if (unlikely(size == 0 || size > POOL_MAX_ALLOC_SIZE))
      |                                   ^~~~~~~~~~~~~~~~~~~
/nix/store/v15ahq9q9yps4k88mniyj3fwl12r38r1-dovecot-2.3.16/include/dovecot/mempool.h:104:35: note: each undeclared identifier is reported only once for each function it appears in
/nix/store/v15ahq9q9yps4k88mniyj3fwl12r38r1-dovecot-2.3.16/include/dovecot/mempool.h: In function 'p_realloc':
/nix/store/v15ahq9q9yps4k88mniyj3fwl12r38r1-dovecot-2.3.16/include/dovecot/mempool.h:113:43: error: 'SSIZE_T_MAX' undeclared (first use in this function); did you mean 'SSIZE_MAX'?
  113 |  if (unlikely(new_size == 0 || new_size > POOL_MAX_ALLOC_SIZE))
      |                                           ^~~~~~~~~~~~~~~~~~~
In file included from /nix/store/v15ahq9q9yps4k88mniyj3fwl12r38r1-dovecot-2.3.16/include/dovecot/lib.h:49,
                 from conftest.c:24:
/nix/store/v15ahq9q9yps4k88mniyj3fwl12r38r1-dovecot-2.3.16/include/dovecot/strnum.h: At top level:
/nix/store/v15ahq9q9yps4k88mniyj3fwl12r38r1-dovecot-2.3.16/include/dovecot/strnum.h:167:34: error: unknown type name 'uoff_t'; did you mean 'off_t'?
  167 | int str_to_uoff(const char *str, uoff_t *num_r)
      |                                  ^~~~~~
      |                                  off_t
/nix/store/v15ahq9q9yps4k88mniyj3fwl12r38r1-dovecot-2.3.16/include/dovecot/strnum.h:169:37: error: unknown type name 'uoff_t'; did you mean 'off_t'?
  169 | int str_parse_uoff(const char *str, uoff_t *num_r,
      |                                     ^~~~~~
      |                                     off_t
conftest.c:26:35: warning: 'struct mail_user' declared inside parameter list will not be visible outside of this definition or declaration
grosjo commented 3 years ago

@symphorien Please kindly try latest git

symphorien commented 3 years ago

You need this for it to work correctly:

diff --git a/configure.ac b/configure.ac
index 5e428a2..106e813 100644
--- a/configure.ac
+++ b/configure.ac
@@ -47,6 +47,7 @@ AC_COMPILE_IFELSE(
                 #include "dovecot/config.h"
        #include "dovecot/lib.h"
                 #include "dovecot/mail-user.h"
+                #include "dovecot/fts-user.h"
                 void f(struct mail_user *s, const char **error) {
                       fts_mail_user_init(s, 0, error);
                     }

otherwise the compilation succeeds even for dovecot 2.3.16: in config.log:

configure:18061: checking Whether fts_mail_user_init has 3 args
configure:18082: gcc -c -std=gnu99 -fstack-protector-strong -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2   conftest.c >&5
conftest.c: In function 'f':
conftest.c:26:23: warning: implicit declaration of function 'fts_mail_user_init'; did you mean 'mail_user_init'? [-Wimplicit-function-declaration]
   26 |                       fts_mail_user_init(s, 0, error);
      |                       ^~~~~~~~~~~~~~~~~~
      |                       mail_user_init
configure:18082: $? = 0
configure:18085: result: yes
fezie commented 3 years ago

Now it doestn't compile anymore with dovecot 2.3.13 I ran autoreconf -fsi and reran ./configure:

/bin/bash ../libtool  --tag=CC   --mode=compile gcc -DHAVE_CONFIG_H -I. -I..  -O2 -I/usr/include/dovecot      -DFTS_MAIL_USER_INIT_THREE_ARGS=1    -g -O2 -std=gnu99 -fstack-protector-strong -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2  -MT fts-xapian-plugin.lo -MD -MP -MF .deps/fts-xapian-plugin.Tpo -c -o fts-xapian-plugin.lo fts-xapian-plugin.c
libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I.. -O2 -I/usr/include/dovecot -DFTS_MAIL_USER_INIT_THREE_ARGS=1 -g -O2 -std=gnu99 -fstack-protector-strong -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -MT fts-xapian-plugin.lo -MD -MP -MF .deps/fts-xapian-plugin.Tpo -c fts-xapian-plugin.c  -fPIC -DPIC -o .libs/fts-xapian-plugin.o
fts-xapian-plugin.c: In function ‘fts_xapian_mail_user_created’:
fts-xapian-plugin.c:105:6: error: too many arguments to function ‘fts_mail_user_init’
  105 |  if (fts_mail_user_init(user, FALSE, &error) < 0)
      |      ^~~~~~~~~~~~~~~~~~
In file included from fts-xapian-plugin.h:10,
                 from fts-xapian-plugin.c:4:
/usr/include/dovecot/fts-user.h:21:5: note: declared here
   21 | int fts_mail_user_init(struct mail_user *user, const char **error_r);
      |     ^~~~~~~~~~~~~~~~~~
symphorien commented 3 years ago

can you try https://github.com/grosjo/fts-xapian/issues/103#issuecomment-969327581 ?

fezie commented 3 years ago

can you try #103 (comment) ?

doestn't help. And the problem is not the missing declaration of fts_mail_user_init. The problem is that the function gained an argument in 2.3.17 which didn't exist in older versions So the old version isn't correctly detected with the git changes for #103

fezie commented 3 years ago

config.log says this about the check:

configure:16964: checking Whether fts_mail_user_init has 3 args
configure:16985: gcc -c -g -O2 -std=gnu99 -fstack-protector-strong -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2   conftest.c >&5
conftest.c: In function 'f':
conftest.c:26:23: warning: implicit declaration of function 'fts_mail_user_init'; did you mean 'mail_user_init'? [-Wimplicit-function-declaration]
   26 |                       fts_mail_user_init(s, 0, error);
      |                       ^~~~~~~~~~~~~~~~~~
      |                       mail_user_init
configure:16985: $? = 0
configure:16987: result: yes
symphorien commented 3 years ago

Humm we are probably calling the compiler without the correct -I flags. It's not needed on my distro, but probably on yours. Can you try this ?

diff --git a/configure.ac b/configure.ac
index 5e428a2..1596be1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -21,7 +21,7 @@ PKG_PROG_PKG_CONFIG
 DC_DOVECOT
 DC_DOVECOT_MODULEDIR
 LIBDOVECOT_INCLUDE="$LIBDOVECOT_INCLUDE"
-CFLAGS="$CFLAGS $EXTRA_CFLAGS"
+CFLAGS="$CFLAGS $EXTRA_CFLAGS $DOVECOT_CFLAGS"
 LIBS="$DOVECOT_LIBS"
 BINARY_LDFLAGS="$PIE_LDFLAGS $RELRO_LDFLAGS"
 BINARY_CFLAGS="$PIE_CFLAGS"
@@ -47,6 +47,7 @@ AC_COMPILE_IFELSE(
                 #include "dovecot/config.h"
        #include "dovecot/lib.h"
                 #include "dovecot/mail-user.h"
+                #include "dovecot/fts-user.h"
                 void f(struct mail_user *s, const char **error) {
                       fts_mail_user_init(s, 0, error);
                     }
fezie commented 3 years ago

Now it works.

symphorien commented 3 years ago

Mmh probably this prevents false positives because of implicit function declaration:

diff --git a/configure.ac b/configure.ac
index 5e428a2..74ec31d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -21,7 +21,7 @@ PKG_PROG_PKG_CONFIG
 DC_DOVECOT
 DC_DOVECOT_MODULEDIR
 LIBDOVECOT_INCLUDE="$LIBDOVECOT_INCLUDE"
-CFLAGS="$CFLAGS $EXTRA_CFLAGS"
+CFLAGS="$CFLAGS $EXTRA_CFLAGS $DOVECOT_CFLAGS"
 LIBS="$DOVECOT_LIBS"
 BINARY_LDFLAGS="$PIE_LDFLAGS $RELRO_LDFLAGS"
 BINARY_CFLAGS="$PIE_CFLAGS"
@@ -40,13 +40,39 @@ ICU_LIBS=$($PKG_CONFIG --libs icu-uc icu-io icu-i18n)
 ICU_CFLAGS=$($PKG_CONFIG --cflags-only-I icu-uc icu-io icu-i18n)
 ICU_INCLUDE=$($PKG_CONFIG --variable=includedir icu-uc)

-AC_MSG_CHECKING([Whether fts_mail_user_init has 3 args])
+AC_MSG_CHECKING([for fts_mail_user_init])

 AC_COMPILE_IFELSE(
    [AC_LANG_PROGRAM([[
                 #include "dovecot/config.h"
        #include "dovecot/lib.h"
                 #include "dovecot/mail-user.h"
+                #include "dovecot/fts-user.h"
+       void f() {
+                      void *ptr = &fts_mail_user_init;
+             (void)ptr;
+             return 0;
+       }
+                ]])], 
+   [
+       AC_MSG_RESULT([yes])
+   ],[
+       AC_MSG_RESULT([no])
+       AC_MSG_ERROR([fts_mail_user_init not found in
+                 dovecot/fts-user.h, dovecot is not installed
+                 correctly])
+   ])
+
+AC_MSG_CHECKING([whether fts_mail_user_init has 3 args])
+dnl this check incorrectly concludes yes if the headers
+dnl don't contain fts_mail_user_init because of implicit function declaration,
+dnl hence the previous check
+AC_COMPILE_IFELSE(
+   [AC_LANG_PROGRAM([[
+                #include "dovecot/config.h"
+       #include "dovecot/lib.h"
+                #include "dovecot/mail-user.h"
+                #include "dovecot/fts-user.h"
                 void f(struct mail_user *s, const char **error) {
                       fts_mail_user_init(s, 0, error);
                     }
grosjo commented 3 years ago

Please check latest git

fezie commented 3 years ago

Please check latest git

compiles fine with old dovecot 2.3.13

grosjo commented 3 years ago

@symphorien issue solved ?

symphorien commented 3 years ago

Yes thanks

Philippe23 commented 1 year ago

@grosjo, did this issue intentionally force -O2?

CFLAGS="$CFLAGS $EXTRA_CFLAGS $DOVECOT_FLAGS -O2"

I believe this means that user-supplied CFLAGS / EXTRA_CFLAGS can't override the -O level.

I asked/noticed because Gentoo's CI noticed and flagged it: https://bugs.gentoo.org/887887