From a707ed46b0cf913aaf87a1635fc2907914330905 Mon Sep 17 00:00:00 2001 From: Mohd Husaam Mehdi Date: Thu, 20 Nov 2025 17:18:31 +0530 Subject: [PATCH] libbbfdm-api: ignore trailing dots in reference paths --- libbbfdm-api/legacy/dmapi.c | 9 ++++++++- libbbfdm-api/legacy/dmbbf.c | 35 +++++++++++++++++++++++++++++++---- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/libbbfdm-api/legacy/dmapi.c b/libbbfdm-api/legacy/dmapi.c index 3ef10891..466202fa 100644 --- a/libbbfdm-api/legacy/dmapi.c +++ b/libbbfdm-api/legacy/dmapi.c @@ -291,13 +291,20 @@ int bbfdm_get_reference_linker(struct dmctx *ctx, char *reference_path, struct d { char hash_str[9] = {0}; char *uci_val = NULL; + size_t len = 0; if (!reference_path || !reference_args) return -1; + // Remove trailing dot if present + len = DM_STRLEN(reference_path); + if (len > 0 && reference_path[len - 1] == '.') { + reference_path[len - 1] = '\0'; + } + reference_args->path = reference_path; - if (DM_STRLEN(reference_args->path) == 0) + if (len == 0) return 0; calculate_hash(reference_path, hash_str, sizeof(hash_str)); diff --git a/libbbfdm-api/legacy/dmbbf.c b/libbbfdm-api/legacy/dmbbf.c index 2b8d755a..dc6571d7 100644 --- a/libbbfdm-api/legacy/dmbbf.c +++ b/libbbfdm-api/legacy/dmbbf.c @@ -896,16 +896,42 @@ static bool is_same_reference_path(const char *curr_value, const char *in_value) char *pch = NULL, *pchr = NULL; char resolved_path[2048] = {0}; char buf[2048] = {0}; - unsigned pos = 0; + char cleaned_in_value[2048] = {0}; + unsigned pos = 0, clean_pos = 0; if (!curr_value || !in_value) return false; - if (strcmp(curr_value, in_value) == 0) + DM_STRNCPY(buf, in_value, sizeof(buf)); + for (pch = strtok_r(buf, ",", &pchr); + pch != NULL && clean_pos < sizeof(cleaned_in_value) - 1; + pch = strtok_r(NULL, ",", &pchr)) { + + size_t len = strlen(pch); + while (len > 0 && pch[len - 1] == '.') { + pch[len - 1] = '\0'; + len--; + } + + int written = snprintf(&cleaned_in_value[clean_pos], + sizeof(cleaned_in_value) - clean_pos, + "%s,", pch); + + if (written < 0 || written >= (int)(sizeof(cleaned_in_value) - clean_pos)) { + // Buffer full or error, stop appending + break; + } + clean_pos += written; + } + if (clean_pos > 0) { + cleaned_in_value[clean_pos - 1] = '\0'; // Remove trailing comma + } + + // If curr_value matches cleaned_in_value directly + if (strcmp(curr_value, cleaned_in_value) == 0) return true; DM_STRNCPY(buf, curr_value, sizeof(buf)); - char *is_list = strchr(buf, ';'); for (pch = strtok_r(buf, is_list ? ";" : ",", &pchr); @@ -936,7 +962,8 @@ static bool is_same_reference_path(const char *curr_value, const char *in_value) resolved_path[pos - 1] = 0; // Remove trailing comma } - if (strcmp(resolved_path, in_value) == 0) + // Compare resolved_path with cleaned_in_value + if (strcmp(resolved_path, cleaned_in_value) == 0) return true; return false;