From: Timo Sirainen Date: Wed, 23 Sep 2015 19:57:55 +0000 (+0300) Subject: dict-client: Catch more invalid protocol replies. X-Git-Tag: 2.2.19.rc2~53 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7e74fadc6668d85c2bfd630f215770808d73d1a3;p=thirdparty%2Fdovecot%2Fcore.git dict-client: Catch more invalid protocol replies. --- diff --git a/src/lib-dict/dict-client.c b/src/lib-dict/dict-client.c index 5d72a796cc..d8110a20ce 100644 --- a/src/lib-dict/dict-client.c +++ b/src/lib-dict/dict-client.c @@ -542,18 +542,22 @@ static int client_dict_wait(struct dict *_dict) { struct client_dict *dict = (struct client_dict *)_dict; char *line; - int ret = 0; + int ret; if (!dict->handshaked) return -1; while (dict->async_commits > 0) { - if (client_dict_read_one_line(dict, &line) < 0) { - ret = -1; - break; + if ((ret = client_dict_read_one_line(dict, &line)) < 0) + return -1; + + if (ret > 0) { + i_error("dict-client: Unexpected reply waiting waiting for async commits: %s", line); + client_dict_disconnect(dict); + return -1; } } - return ret; + return 0; } static int client_dict_lookup(struct dict *_dict, pool_t pool, @@ -578,12 +582,19 @@ static int client_dict_lookup(struct dict *_dict, pool_t pool, if (line == NULL) return -1; - if (*line == DICT_PROTOCOL_REPLY_OK) { + switch (*line) { + case DICT_PROTOCOL_REPLY_OK: *value_r = p_strdup(pool, dict_client_unescape(line + 1)); return 1; - } else { + case DICT_PROTOCOL_REPLY_NOTFOUND: *value_r = NULL; - return *line == DICT_PROTOCOL_REPLY_NOTFOUND ? 0 : -1; + return 0; + case DICT_PROTOCOL_REPLY_FAIL: + return -1; + default: + i_error("dict-client: Invalid lookup '%s' reply: %s", key, line); + client_dict_disconnect(dict); + return -1; } } @@ -710,6 +721,10 @@ static void dict_async_input(struct client_dict *dict) if (ret < 0) io_remove(&dict->io); + else if (ret > 0) { + i_error("dict-client: Unexpected reply waiting waiting for async commits: %s", line); + client_dict_disconnect(dict); + } } static int @@ -746,12 +761,22 @@ client_dict_transaction_commit(struct dict_transaction_context *_ctx, line = client_dict_read_line(dict); if (line == NULL) ret = -1; - else if (*line == DICT_PROTOCOL_REPLY_OK) + else switch (*line) { + case DICT_PROTOCOL_REPLY_OK: ret = 1; - else if (*line == DICT_PROTOCOL_REPLY_NOTFOUND) + break; + case DICT_PROTOCOL_REPLY_NOTFOUND: ret = 0; - else + break; + case DICT_PROTOCOL_REPLY_FAIL: + ret = -1; + break; + default: + i_error("dict-client: Invalid commit reply: %s", line); + client_dict_disconnect(dict); ret = -1; + break; + } } } T_END;