From 8f55cfbc16c84628f7122d4e74619b0df44ca165 Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Fri, 21 Oct 2016 12:36:38 +0300 Subject: [PATCH] Fix cache_dir path handling in MySQLAuth The path that was given as the option for the cache directory wasn't properly checked for terminating forward slashes. Due to this, the cache file was created with the wrong name. --- include/maxscale/utils.h | 2 +- server/core/utils.c | 7 +++++-- server/modules/authenticator/MySQLAuth/mysql_auth.c | 5 +++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/include/maxscale/utils.h b/include/maxscale/utils.h index 55ce9a34e..67f699af2 100644 --- a/include/maxscale/utils.h +++ b/include/maxscale/utils.h @@ -72,7 +72,7 @@ char* replace_literal(char* haystack, const char* replacement); char* replace_quoted(const char** src, const size_t* srcsize, char** dest, size_t* destsize); -void clean_up_pathname(char *path); +bool clean_up_pathname(char *path); bool mxs_mkdir_all(const char *path, int mask); diff --git a/server/core/utils.c b/server/core/utils.c index 0688da6c8..9a930def9 100644 --- a/server/core/utils.c +++ b/server/core/utils.c @@ -315,14 +315,15 @@ char *create_hex_sha1_sha1_passwd(char *passwd) * Remove duplicate and trailing forward slashes from a path. * @param path Path to clean up */ -void clean_up_pathname(char *path) +bool clean_up_pathname(char *path) { char *data = path; size_t len = strlen(path); if (len > PATH_MAX) { - MXS_WARNING("Pathname too long: %s", path); + MXS_ERROR("Pathname too long: %s", path); + return false; } while (*data != '\0') @@ -350,6 +351,8 @@ void clean_up_pathname(char *path) len--; } } + + return true; } /** diff --git a/server/modules/authenticator/MySQLAuth/mysql_auth.c b/server/modules/authenticator/MySQLAuth/mysql_auth.c index a7942783d..a2fe41894 100644 --- a/server/modules/authenticator/MySQLAuth/mysql_auth.c +++ b/server/modules/authenticator/MySQLAuth/mysql_auth.c @@ -155,7 +155,8 @@ static void* mysql_auth_init(char **options) if (strcmp(options[i], "cache_dir") == 0) { - if ((instance->cache_dir = MXS_STRDUP(value)) == NULL) + if ((instance->cache_dir = MXS_STRDUP(value)) == NULL || + !clean_up_pathname(instance->cache_dir)) { error = true; } @@ -903,7 +904,7 @@ static int mysql_auth_load_users(SERV_LISTENER *port) if (instance->cache_dir) { - strcpy(path, instance->cache_dir); + snprintf(path, sizeof(path) - sizeof(DBUSERS_FILE) - 1, "%s/", instance->cache_dir); } else {