Ensure the validity of reference path when trying to set a reference path with an empty reference value

This commit is contained in:
Amin Ben Romdhane 2024-09-11 19:47:20 +02:00
parent 402e8b77ff
commit 17d89ad513
4 changed files with 13 additions and 8 deletions

View file

@ -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;
}

View file

@ -159,6 +159,7 @@ typedef struct dm_map_obj {
struct dm_reference {
char *path;
char *value;
bool is_valid_path;
};
struct dmctx {

View file

@ -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)

View file

@ -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;
}
}