]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
imap: Fixed segfault in URLFETCH command.
authorStephan Bosch <stephan@rename-it.nl>
Thu, 30 May 2013 15:04:52 +0000 (18:04 +0300)
committerStephan Bosch <stephan@rename-it.nl>
Thu, 30 May 2013 15:04:52 +0000 (18:04 +0300)
Command would be cleaned up while requests were still pending, causing a
segfault once a request finished. Added API determining whether the URLAUTH
fetch interface still has pending requests.

src/imap/cmd-urlfetch.c
src/lib-imap-urlauth/imap-urlauth-fetch.c
src/lib-imap-urlauth/imap-urlauth-fetch.h

index c3fac615b805929b25024f5d6f03b56a89aa1c6f..0fdfb7b6e6aa6eaae297225970dcd1d59af42d15 100644 (file)
@@ -357,7 +357,6 @@ bool cmd_urlfetch(struct client_command_context *cmd)
        const struct cmd_urlfetch_url *url;
        const struct imap_arg *args;
        struct cmd_urlfetch_url *ufurl;
-       int ret;
 
        if (client->urlauth_ctx == NULL) {
                client_send_command_error(cmd, "URLAUTH disabled.");
@@ -387,17 +386,16 @@ bool cmd_urlfetch(struct client_command_context *cmd)
        ctx->ufetch = imap_urlauth_fetch_init(client->urlauth_ctx,
                                              cmd_urlfetch_url_callback, cmd);
 
-       ret = 1;
        array_foreach(&urls, url) {
-               ret = imap_urlauth_fetch_url(ctx->ufetch, url->url, url->flags);
-               if (ret < 0) {
+               if (imap_urlauth_fetch_url(ctx->ufetch, url->url, url->flags) < 0) {
                        /* fatal error */
                        ctx->failed = TRUE;
                        break;
                }
        }
 
-       if (ret != 0 && cmd->client->output_cmd_lock != cmd) {
+       if ((ctx->failed || !imap_urlauth_fetch_is_pending(ctx->ufetch))
+               && cmd->client->output_cmd_lock != cmd) {
                /* finished */
                cmd_urlfetch_finish(cmd);
                return TRUE;
index 2393811aa835250e0717bd96be79e5ecfb357856..b0836bd4689b57ee9e80e6982e2091763ec9f2ed 100644 (file)
@@ -516,3 +516,7 @@ bool imap_urlauth_fetch_continue(struct imap_urlauth_fetch *ufetch)
        return pending;
 }
 
+bool imap_urlauth_fetch_is_pending(struct imap_urlauth_fetch *ufetch)
+{
+       return ufetch->pending_requests > 0;
+}
index 55398af7bc8a1633d4fb9b00a27aaef747c532ea..8d39381639fb3b1d8e43629c0ba7122524c404b1 100644 (file)
@@ -45,6 +45,8 @@ void imap_urlauth_fetch_deinit(struct imap_urlauth_fetch **ufetch);
 
 int imap_urlauth_fetch_url(struct imap_urlauth_fetch *ufetch, const char *url,
                           enum imap_urlauth_fetch_flags url_flags);
+
 bool imap_urlauth_fetch_continue(struct imap_urlauth_fetch *ufetch);
+bool imap_urlauth_fetch_is_pending(struct imap_urlauth_fetch *ufetch);
 
 #endif