Skip to content

Commit

Permalink
afpd: character encoding in Spotlight queries
Browse files Browse the repository at this point in the history
Fix path escaping in Spotlight so paths with spaces or special
characters can be properly matched to tracker paths.

Signed-off-by: Ralph Boehme <slow@samba.org>
(similar to commit 4473897)
  • Loading branch information
dbuckley authored and slowfranklin committed May 5, 2016
1 parent faaaf46 commit 90aa43d
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions etc/afpd/spotlight.c
Expand Up @@ -831,6 +831,7 @@ static int sl_rpc_openQuery(AFPObj *obj,
GError *error = NULL;
bool ok;
sl_array_t *scope_array;
char *scope = NULL;

array = talloc_zero(reply, sl_array_t);

Expand Down Expand Up @@ -858,6 +859,9 @@ static int sl_rpc_openQuery(AFPObj *obj,
if (sl_query == NULL) {
EC_FAIL;
}

LOG(log_debug, logtype_sl, "Spotlight query pre-conversion: \"%s\"", sl_query);

ret = convert_charset(CH_UTF8_MAC, v->v_volcharset, v->v_maccharset,
sl_query, strlen(sl_query), slq_host, MAXPATHLEN,
&convflags);
Expand Down Expand Up @@ -891,15 +895,26 @@ static int sl_rpc_openQuery(AFPObj *obj,
scope_array = dalloc_value_for_key(query, "DALLOC_CTX", 0, "DALLOC_CTX", 1,
"kMDScopeArray");
if (scope_array == NULL) {
slq->slq_scope = talloc_strdup(slq, v->v_path);
scope = g_uri_escape_string(v->v_path,
G_URI_RESERVED_CHARS_ALLOWED_IN_PATH, TRUE);
} else {
slq->slq_scope = talloc_strdup(slq, scope_array->dd_talloc_array[0]);
scope = g_uri_escape_string(scope_array->dd_talloc_array[0],
G_URI_RESERVED_CHARS_ALLOWED_IN_PATH, TRUE);
}
if (slq->slq_scope == NULL) {

if (scope == NULL) {
LOG(log_error, logtype_sl, "failed to setup search scope");
EC_FAIL;
}

slq->slq_scope = talloc_strdup(slq, scope);
if (slq->slq_scope == NULL) {
LOG(log_error, logtype_sl, "talloc_strdup failed");
EC_FAIL;
}

g_free(scope);

LOG(log_debug, logtype_sl, "Search scope: \"%s\"", slq->slq_scope);

cnids = dalloc_value_for_key(query, "DALLOC_CTX", 0, "DALLOC_CTX", 1,
Expand Down

2 comments on commit 90aa43d

@andy-js
Copy link
Contributor

@andy-js andy-js commented on 90aa43d May 5, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you've got a potential memory leak there. You need to move the g_free(scope) call up above the if (slq->slq_scope == NULL) check.

@slowfranklin
Copy link
Member

@slowfranklin slowfranklin commented on 90aa43d May 5, 2016 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.