diff --git a/env/posix/ocf_env.h b/env/posix/ocf_env.h index 7e81924..82b145e 100644 --- a/env/posix/ocf_env.h +++ b/env/posix/ocf_env.h @@ -621,7 +621,7 @@ static inline void env_sort(void *base, size_t num, size_t size, }) #define env_strdup strndup #define env_strnlen(s, smax) strnlen(s, smax) -#define env_strncmp strncmp +#define env_strncmp(s1, slen1, s2, slen2) strncmp(s1, s2, min(slen1, slen2)) #define env_strncpy(dest, dmax, src, slen) ({ \ strncpy(dest, src, min(dmax - 1, slen)); \ dest[dmax - 1] = '\0'; \ diff --git a/inc/ocf_core.h b/inc/ocf_core.h index 435dd74..1973be5 100644 --- a/inc/ocf_core.h +++ b/inc/ocf_core.h @@ -47,12 +47,13 @@ struct ocf_core_info { * * @param[in] cache OCF cache * @param[in] name Core name + * @param[in] name_len Core name length * @param[out] core OCF core handle * * @retval 0 Get cache successfully * @retval -OCF_ERR_CORE_NOT_EXIST Core with given name doesn't exist */ -int ocf_core_get_by_name(ocf_cache_t cache, const char *name, +int ocf_core_get_by_name(ocf_cache_t cache, const char *name, size_t name_len, ocf_core_t *core); /** diff --git a/inc/ocf_mngt.h b/inc/ocf_mngt.h index 810b85e..7f4ebaf 100644 --- a/inc/ocf_mngt.h +++ b/inc/ocf_mngt.h @@ -85,12 +85,13 @@ uint32_t ocf_mngt_cache_get_count(ocf_ctx_t ctx); * * @param[in] ctx OCF context * @param[in] name OCF cache name + * @param[in] name_len Cache name length * @param[out] cache OCF cache handle * * @retval 0 Get cache successfully * @retval -OCF_ERR_CACHE_NOT_EXIST Cache with given name doesn't exist */ -int ocf_mngt_cache_get_by_name(ocf_ctx_t ctx, const char* name, +int ocf_mngt_cache_get_by_name(ocf_ctx_t ctx, const char* name, size_t name_len, ocf_cache_t *cache); /** diff --git a/src/mngt/ocf_mngt_cache.c b/src/mngt/ocf_mngt_cache.c index 06965f4..09c372a 100644 --- a/src/mngt/ocf_mngt_cache.c +++ b/src/mngt/ocf_mngt_cache.c @@ -662,7 +662,8 @@ static int _ocf_mngt_init_prepare_cache(struct ocf_cache_mngt_init_params *param int ret = 0; /* Check if cache with specified name exists */ - ret = ocf_mngt_cache_get_by_name(param->ctx, cfg->name, &cache); + ret = ocf_mngt_cache_get_by_name(param->ctx, cfg->name, + OCF_CACHE_NAME_SIZE, &cache); if (!ret) { ocf_mngt_cache_put(cache); /* Cache already exist */ @@ -924,8 +925,8 @@ static void _ocf_mngt_attach_load_properties_end(void *priv, int error, /* * Check if name loaded from disk is the same as present one. */ - if (env_strncmp(cache->conf_meta->name, properties->cache_name, - OCF_CACHE_NAME_SIZE)) { + if (env_strncmp(cache->conf_meta->name, OCF_CACHE_NAME_SIZE, + properties->cache_name, OCF_CACHE_NAME_SIZE)) { OCF_PL_FINISH_RET(context->pipeline, -OCF_ERR_CACHE_NAME_MISMATCH); } diff --git a/src/mngt/ocf_mngt_common.c b/src/mngt/ocf_mngt_common.c index 052600f..7e0022c 100644 --- a/src/mngt/ocf_mngt_common.c +++ b/src/mngt/ocf_mngt_common.c @@ -140,7 +140,7 @@ void ocf_mngt_cache_put(ocf_cache_t cache) } } -int ocf_mngt_cache_get_by_name(ocf_ctx_t ctx, const char *name, +int ocf_mngt_cache_get_by_name(ocf_ctx_t ctx, const char *name, size_t name_len, ocf_cache_t *cache) { struct ocf_cache *instance = NULL; @@ -153,8 +153,8 @@ int ocf_mngt_cache_get_by_name(ocf_ctx_t ctx, const char *name, env_rmutex_lock(&ctx->lock); list_for_each_entry(iter, &ctx->caches, list) { - if (!env_strncmp(ocf_cache_get_name(iter), name, - OCF_CACHE_NAME_SIZE)) { + if (!env_strncmp(ocf_cache_get_name(iter), OCF_CACHE_NAME_SIZE, + name, name_len)) { instance = iter; break; } diff --git a/src/mngt/ocf_mngt_core.c b/src/mngt/ocf_mngt_core.c index 60ab3b3..594c343 100644 --- a/src/mngt/ocf_mngt_core.c +++ b/src/mngt/ocf_mngt_core.c @@ -228,7 +228,8 @@ static void ocf_mngt_cache_try_add_core_prepare(ocf_pipeline_t pipeline, ocf_ctx_t ctx = cache->owner; int result; - result = ocf_core_get_by_name(cache, cfg->name, &core); + result = ocf_core_get_by_name(cache, cfg->name, + OCF_CORE_NAME_SIZE, &core); if (result) goto err; @@ -245,8 +246,8 @@ static void ocf_mngt_cache_try_add_core_prepare(ocf_pipeline_t pipeline, goto err; } - if (env_strncmp(volume->uuid.data, cfg->uuid.data, - OCF_MIN(volume->uuid.size, cfg->uuid.size))) { + if (env_strncmp(volume->uuid.data, volume->uuid.size, cfg->uuid.data, + cfg->uuid.size)) { result = -OCF_ERR_INVAL; goto err; } @@ -304,7 +305,8 @@ static void ocf_mngt_cache_add_core_prepare(ocf_pipeline_t pipeline, ocf_core_t core; int result; - result = ocf_core_get_by_name(cache, cfg->name, &core); + result = ocf_core_get_by_name(cache, cfg->name, + OCF_CACHE_NAME_SIZE, &core); if (!result) OCF_PL_FINISH_RET(context->pipeline, -OCF_ERR_CORE_EXIST); diff --git a/src/mngt/ocf_mngt_core_pool.c b/src/mngt/ocf_mngt_core_pool.c index 8e28463..ae7e9ea 100644 --- a/src/mngt/ocf_mngt_core_pool.c +++ b/src/mngt/ocf_mngt_core_pool.c @@ -82,7 +82,7 @@ ocf_volume_t ocf_mngt_core_pool_lookup(ocf_ctx_t ctx, ocf_uuid_t uuid, list_for_each_entry(svolume, &ctx->core_pool.core_pool_head, core_pool_item) { if (svolume->type == type && !env_strncmp(svolume->uuid.data, - uuid->data, OCF_MIN(svolume->uuid.size, uuid->size))) { + svolume->uuid.size, uuid->data, uuid->size)) { return svolume; } } diff --git a/src/ocf_core.c b/src/ocf_core.c index 5c8dcfe..c87602b 100644 --- a/src/ocf_core.c +++ b/src/ocf_core.c @@ -49,15 +49,15 @@ ocf_core_id_t ocf_core_get_id(ocf_core_t core) return core_id; } -int ocf_core_get_by_name(ocf_cache_t cache, const char *name, +int ocf_core_get_by_name(ocf_cache_t cache, const char *name, size_t name_len, ocf_core_t *core) { ocf_core_t i_core; ocf_core_id_t i_core_id; for_each_core(cache, i_core, i_core_id) { - if (!env_strncmp(ocf_core_get_name(i_core), name, - OCF_CORE_NAME_SIZE)) { + if (!env_strncmp(ocf_core_get_name(i_core), OCF_CORE_NAME_SIZE, + name, name_len)) { *core = i_core; return 0; }