Skip to content

Commit

Permalink
fts-solr: Append '/' to URL path when missing in configuration
Browse files Browse the repository at this point in the history
This fixes a crash when url parameter has empty path like
http://localhost:8080 instead of http://localhost:8080/ and makes using
url like http://localhost:8080/solr behave the same as
http://localhost:8080/solr/
  • Loading branch information
mrannanj authored and cmouse committed Aug 7, 2018
1 parent f886108 commit ec4592e
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/plugins/fts-solr/solr-connection.c
Expand Up @@ -101,6 +101,20 @@ static int solr_xml_parse(struct solr_connection *conn,
return 0;
}

/* Regardless of the specified URL, make sure path ends in '/' */
static char *solr_connection_create_http_base_url(struct http_url *http_url)
{
if (http_url->path == NULL)
return i_strconcat("/", http_url->enc_query, NULL);
size_t len = strlen(http_url->path);
if (len > 0 && http_url->path[len-1] != '/')
return i_strconcat(http_url->path, "/",
http_url->enc_query, NULL);
/* http_url->path is NULL on empty path, so this is impossible. */
i_assert(len != 0);
return i_strconcat(http_url->path, http_url->enc_query, NULL);
}

int solr_connection_init(const char *url,
const struct ssl_iostream_settings *ssl_client_set,
bool debug, struct solr_connection **conn_r,
Expand All @@ -121,7 +135,7 @@ int solr_connection_init(const char *url,
conn = i_new(struct solr_connection, 1);
conn->http_host = i_strdup(http_url->host.name);
conn->http_port = http_url->port;
conn->http_base_url = i_strconcat(http_url->path, http_url->enc_query, NULL);
conn->http_base_url = solr_connection_create_http_base_url(http_url);
conn->http_ssl = http_url->have_ssl;
if (http_url->user != NULL) {
conn->http_user = i_strdup(http_url->user);
Expand Down

0 comments on commit ec4592e

Please sign in to comment.