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 {