From 7e2f47f9ca63cde59d32073cade46c39a1d67635 Mon Sep 17 00:00:00 2001 From: ejurgensen Date: Tue, 1 Apr 2014 21:51:07 +0200 Subject: [PATCH] Minor adjustment so Valgrind is happy with string handling in user_agent_filter --- src/httpd_daap.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/httpd_daap.c b/src/httpd_daap.c index 97b2a9d4..0016041d 100644 --- a/src/httpd_daap.c +++ b/src/httpd_daap.c @@ -489,6 +489,9 @@ user_agent_filter(const char *user_agent, struct query_params *qp) if (!user_agent) return; + // Valgrind doesn't like strlen(filter) below, so instead we allocate 128 bytes + // to hold the string and the leading " AND ". Remember to adjust the 128 if + // you define strings here that will be too large for the buffer. if (strcasestr(user_agent, "itunes")) filter = strdup("(f.data_kind = 0)"); // Only real files else if (strcasestr(user_agent, "daap")) @@ -502,9 +505,9 @@ user_agent_filter(const char *user_agent, struct query_params *qp) if (qp->filter) { - len = strlen(qp->filter) + strlen(" AND ") + strlen(filter); - buffer = (char *)malloc(len + 1); - snprintf(buffer, len + 1, "%s AND %s", qp->filter, filter); + len = strlen(qp->filter) + 128; + buffer = (char *)malloc(len); + snprintf(buffer, len, "%s AND %s", qp->filter, filter); free(qp->filter); qp->filter = strdup(buffer); free(buffer);