From b1b2e76ed6803232e9e3c7197a4af9ebadd8b4d2 Mon Sep 17 00:00:00 2001 From: Xiaofeng Meng Date: Wed, 9 Jul 2025 11:20:06 +0200 Subject: [PATCH] Fix reference DB hash collision MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: `convert_path_with_star()` replaced all index in the path with `*` so different higher-level instances that shared the same linker value ( e.g. `Bridge.1.Port.2` vs `Bridge.2.Port.2` ) produced the *same* linker string → identical hash → last one overwrote the others. Fix: Remove `convert_path_with_star()` entirely. In `set_references()` compose the linker string directly from `parent_path`, leaving all existing instance numbers intact: `Device.Bridging.Bridge.2.Port.[Name==eth0.1].` Each object therefore hashes to a unique key. --- libbbfdm-api/legacy/dmbbf.c | 24 +----------------------- 1 file changed, 1 insertion(+), 23 deletions(-) diff --git a/libbbfdm-api/legacy/dmbbf.c b/libbbfdm-api/legacy/dmbbf.c index 2b8d755a..110a1214 100644 --- a/libbbfdm-api/legacy/dmbbf.c +++ b/libbbfdm-api/legacy/dmbbf.c @@ -1952,35 +1952,13 @@ static void create_required_sections(struct dmctx *ctx) ctx->addobj_instance = (void *)ref_s; } -static int convert_path_with_star(const char *full_obj, char *out_str, size_t out_len) -{ - char str[1024] = {0}; - char *pch, *pchr; - size_t pos = 0; - - DM_STRNCPY(str, full_obj, sizeof(str)); - - for (pch = strtok_r(str, ".", &pchr); pch != NULL; pch = strtok_r(NULL, ".", &pchr)) { - const char *part = isdigit_str(pch) ? "*" : pch; - int written = snprintf(out_str + pos, out_len - pos, "%s.", part); - if (written < 0 || written >= (int)(out_len - pos)) { - return -1; // overflow - } - pos += written; - } - - return 0; -} - static void set_references(struct uci_section *service_sec, const char *parent_path, const char *current_path, const char *key_name, const char *key_value, char *out_str, size_t out_len) { struct uci_list *uci_list = NULL; char linker[MAX_DM_PATH * 2] = {0}; char hash_str[9] = {0}; - convert_path_with_star(parent_path, out_str, out_len); - - snprintf(linker, sizeof(linker), "%s[%s==%s].", out_str, key_name, DM_STRLEN(key_value) ? key_value : ""); + snprintf(linker, sizeof(linker), "%s[%s==%s].", parent_path, key_name, DM_STRLEN(key_value) ? key_value : ""); calculate_hash(linker, hash_str, sizeof(hash_str)); DM_STRNCPY(out_str, current_path, strlen(current_path)); dmuci_set_value_varstate("bbfdm_reference_db", "reference_path", hash_str, out_str);