From 17d89ad513d5dab5371de5565721916ebb0f8dff Mon Sep 17 00:00:00 2001 From: Amin Ben Romdhane Date: Wed, 11 Sep 2024 19:47:20 +0200 Subject: [PATCH] Ensure the validity of reference path when trying to set a reference path with an empty reference value --- libbbfdm-api/dmapi.c | 6 ++++++ libbbfdm-api/dmapi.h | 1 + libbbfdm-api/dmbbf.c | 2 +- libbbfdm-api/dmentry.c | 12 +++++------- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/libbbfdm-api/dmapi.c b/libbbfdm-api/dmapi.c index 3097b11f..9b81f8ee 100644 --- a/libbbfdm-api/dmapi.c +++ b/libbbfdm-api/dmapi.c @@ -308,6 +308,12 @@ int bbfdm_get_reference_linker(struct dmctx *ctx, char *reference_path, struct d reference_args->value = separator + 2; + char *valid_path = strstr(separator + 2, "##"); + if (valid_path) { + reference_args->is_valid_path = true; + *valid_path = 0; + } + return 0; } diff --git a/libbbfdm-api/dmapi.h b/libbbfdm-api/dmapi.h index 4fe5343b..4c61fd3d 100644 --- a/libbbfdm-api/dmapi.h +++ b/libbbfdm-api/dmapi.h @@ -159,6 +159,7 @@ typedef struct dm_map_obj { struct dm_reference { char *path; char *value; + bool is_valid_path; }; struct dmctx { diff --git a/libbbfdm-api/dmbbf.c b/libbbfdm-api/dmbbf.c index aeebac8b..fa3ed83d 100644 --- a/libbbfdm-api/dmbbf.c +++ b/libbbfdm-api/dmbbf.c @@ -995,7 +995,7 @@ static void get_reference_paramater_value(struct dmctx *dmctx, char *in_value, c adm_entry_get_reference_value(dmctx, pch, &linker); - pos += snprintf((char *)str + pos, size - pos, "%s=>%s,", pch, linker ? linker : ""); + pos += snprintf((char *)str + pos, size - pos, "%s=>%s%s,", pch, linker ? linker : "", linker ? "##" : ""); } if (pos) diff --git a/libbbfdm-api/dmentry.c b/libbbfdm-api/dmentry.c index b429148d..c67cecec 100644 --- a/libbbfdm-api/dmentry.c +++ b/libbbfdm-api/dmentry.c @@ -257,14 +257,12 @@ int dm_validate_allowed_objects(struct dmctx *ctx, struct dm_reference *referenc for (; *objects; objects++) { if (match(reference->path, *objects, 0, NULL)) { + if (DM_STRLEN(reference->value)) + return 0; - if (dm_is_micro_service()) { - if (DM_STRLEN(reference->value)) - return 0; - } else { - if (adm_entry_object_exists(ctx, reference->path)) - return 0; - } + // In some cases, the reference value might be empty, but this doesn't mean the reference path is invalid. + if (reference->is_valid_path) + return 0; } }