From 4945e4ca86aea0f8ce95344c005d4078a3d23acf Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Sun, 3 May 2026 19:13:41 +0530 Subject: [PATCH 01/79] Update rrdEventProcess.c --- src/rrdEventProcess.c | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/src/rrdEventProcess.c b/src/rrdEventProcess.c index 5164e7832..b22e2e13b 100644 --- a/src/rrdEventProcess.c +++ b/src/rrdEventProcess.c @@ -79,7 +79,10 @@ void processIssueTypeEvent(data_buf *rbuf) cmdBuff = (data_buf *)malloc(sizeof(data_buf)); if (cmdBuff) { - dataMsgLen = strlen(cmdMap[index]) + 1; + char base[128] = {0}; + char local_suffix[128] = {0}; + split_issue_type(cmdMap[index], base, sizeof(base), local_suffix, sizeof(local_suffix)); + dataMsgLen = strlen(base) + 1; RRD_data_buff_init(cmdBuff, EVENT_MSG, RRD_DEEPSLEEP_INVALID_DEFAULT); /* Setting Deafult Values*/ cmdBuff->inDynamic = rbuf->inDynamic; if(cmdBuff->inDynamic) @@ -88,9 +91,19 @@ void processIssueTypeEvent(data_buf *rbuf) } cmdBuff->appendMode = rbuf->appendMode; cmdBuff->mdata = (char *)calloc(1, dataMsgLen); + + /* Store suffix for this issue type */ + cmdBuff->suffix = NULL; + if (local_suffix[0] != '\0') { + cmdBuff->suffix = strdup(local_suffix); + if (cmdBuff->suffix == NULL) + { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: Failed to allocate memory for suffix... \n", __FUNCTION__, __LINE__); + } + } if (cmdBuff->mdata) { - strncpy((char *)cmdBuff->mdata, cmdMap[index], dataMsgLen); + strncpy((char *)cmdBuff->mdata, base, dataMsgLen); processIssueType(cmdBuff); } else @@ -99,12 +112,14 @@ void processIssueTypeEvent(data_buf *rbuf) } if(cmdBuff) { - free(cmdBuff); - cmdBuff = NULL; - } - } - else - { + if (cmdBuff->suffix) + { + /* Persist suffix for this issue type */ + if (local_suffix[0] != '\0') { + persist_suffix_to_file(local_suffix); + } else { + persist_suffix_to_file(""); + } RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Memory Allocation Failed... \n", __FUNCTION__, __LINE__); } if( cmdMap[index]) @@ -639,7 +654,7 @@ static void removeSpecialCharacterfromIssueTypeList(char *str) while (str[source] != '\0') { - if (isalnum(str[source]) || str[source] == ',' || str[source] == '.') + if (isalnum(str[source]) || str[source] == ',' || str[source] == '.' || str[source] == '_'|| str[source] == '-') { str[destination] = str[source]; ++destination; @@ -648,7 +663,6 @@ static void removeSpecialCharacterfromIssueTypeList(char *str) } str[destination] = '\0'; } - /* * @function issueTypeSplitter * @brief Splits a given string into tokens based on a specified delimiter, and removes any @@ -698,4 +712,3 @@ static int issueTypeSplitter(char *input_str, const char delimeter, char ***args return cnt; } - From 8c0f9ee6c45e1625a464220855fe053e1a99e495 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Sun, 3 May 2026 19:16:08 +0530 Subject: [PATCH 02/79] Update rrdJsonParser.c --- src/rrdJsonParser.c | 96 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 95 insertions(+), 1 deletion(-) diff --git a/src/rrdJsonParser.c b/src/rrdJsonParser.c index e06d93ac2..d470bb899 100644 --- a/src/rrdJsonParser.c +++ b/src/rrdJsonParser.c @@ -1,3 +1,4 @@ +#include "rrdCommon.h" /* * If not stated otherwise in this file or this component's LICENSE file the * following copyright and licenses apply: @@ -46,6 +47,83 @@ void removeSpecialChar(char *str) } } + +void persist_suffix_to_file(const char *suffix) { + FILE *fp = fopen("/tmp/rrd_suffix.txt", "w"); + if (fp) { + if (suffix) { + fputs(suffix, fp); + } + fclose(fp); + } +} + +char *read_suffix_from_file() { + FILE *fp = fopen("/tmp/rrd_suffix.txt", "r"); + if (!fp) return NULL; + char buf[128] = {0}; + if (fgets(buf, sizeof(buf), fp) == NULL) { + fclose(fp); + return NULL; + } + fclose(fp); + size_t len = strlen(buf); + if (len > 0 && buf[len-1] == '\n') buf[len-1] = '\0'; + return strdup(buf); +} + +void read_suffix_from_file_to_buf(char *buf, size_t buflen) { + if (!buf || buflen == 0) return; + FILE *fp = fopen("/tmp/rrd_suffix.txt", "r"); + if (!fp) { + buf[0] = '\0'; + return; + } + if (fgets(buf, buflen, fp) == NULL) { + buf[0] = '\0'; + fclose(fp); + return; + } + fclose(fp); + size_t len = strlen(buf); + if (len > 0 && buf[len-1] == '\n') buf[len-1] = '\0'; +} + +// Utility to split base and suffix from issue type string +// Input: Device.DeviceTime_Search-b6877385-9463-45fc-b19d-a24d77fd0790 +// Output: base = Device.DeviceTime, suffix = _Search-b6877385-9463-45fc-b19d-a24d77fd0790 +/* + * @function split_issue_type + * @brief Utility to split base and suffix from issue type string. + * Example: Input: Device.DeviceTime_Search-b6877385-9463-45fc-b19d-a24d77fd0790 + * Output: base = Device.DeviceTime, suffix = _Search-b6877385-9463-45fc-b19d-a24d77fd0790 + * @param const char *input - The input string to split. + * @param char *base - Buffer to store the base part (before the first underscore). + * @param size_t base_len - Size of the base buffer. + * @param char *suffix - Buffer to store the suffix part (from the first underscore onwards). + * @param size_t suffix_len - Size of the suffix buffer. + * @return void + */ +void split_issue_type(const char *input, char *base, size_t base_len, char *suffix, size_t suffix_len) { + if (!input || !base || !suffix) return; + RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: [INFO] split_issue_type called with input='%s'\n", __FUNCTION__, __LINE__, input); + const char *underscore = strchr(input, '_'); + if (underscore) { + size_t b_len = underscore - input; + if (b_len >= base_len) b_len = base_len - 1; + strncpy(base, input, b_len); + base[b_len] = '\0'; + strncpy(suffix, underscore, suffix_len - 1); + suffix[suffix_len - 1] = '\0'; + } else { + strncpy(base, input, base_len - 1); + base[base_len - 1] = '\0'; + suffix[0] = '\0'; + } + RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: [INFO] split_issue_type result: base='%s', suffix='%s'\n", __FUNCTION__, __LINE__, base, suffix); +} + + /* * @function getParamcount * @brief Calculates the total number of nodes (elements) in the input string, excluding delimiters. @@ -206,6 +284,7 @@ void getIssueInfo(char *issuestr, issueNodeData *issue) RDK_LOG(RDK_LOG_INFO,LOG_REMDEBUG,"[%s:%d]: Received Main Node= %s, SubNode= %s\n",__FUNCTION__,__LINE__,issue->Node,issue->subNode); } + /* * @function findIssueInParsedJSON * @brief Finds if an issue category and issue type is present in the parsed JSON. @@ -576,7 +655,22 @@ void checkIssueNodeInfo(issueNodeData *issuestructNode, cJSON *jsoncfg, data_buf else { RDK_LOG(RDK_LOG_DEBUG,LOG_REMDEBUG,"[%s:%d]: Continue uploading Debug Report for %s from %s... \n",__FUNCTION__,__LINE__,buff->mdata,outdir); - status = uploadDebugoutput(outdir,buff->mdata); + // Use the persisted suffix from file for upload + char suffix[128] = {0}; + read_suffix_from_file_to_buf(suffix, sizeof(suffix)); + char tarName[512] = {0}; + if (suffix[0] != '\0') { + snprintf(tarName, sizeof(tarName), "%s%s", buff->mdata, suffix); + } else { + snprintf(tarName, sizeof(tarName), "%s", buff->mdata); + } + RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Tar file name for upload: '%s'\n", __FUNCTION__, __LINE__, tarName); + RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: [INFO] Tar file name for upload: '%s'\n", __FUNCTION__, __LINE__, tarName); + RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: [INFO] Directory for upload: '%s'\n", __FUNCTION__, __LINE__, outdir); + RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: [INFO] Original issue string: '%s'\n", __FUNCTION__, __LINE__, buff->mdata); + RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: [INFO] Suffix used for upload: '%s'\n", __FUNCTION__, __LINE__, suffix); + RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: [INFO] Tar file name for upload: '%s'\n", __FUNCTION__, __LINE__, tarName); + status = uploadDebugoutput(outdir, tarName, suffix); if(status != 0) { RDK_LOG(RDK_LOG_ERROR,LOG_REMDEBUG,"[%s:%d]: RRD Upload Script Execution Failed!!! status:%d\n",__FUNCTION__,__LINE__,status); From c0717983d402b4d6cd0e66b62f5b95a75e587a34 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Sun, 3 May 2026 19:17:26 +0530 Subject: [PATCH 03/79] Update rrdJsonParser.c --- src/rrdJsonParser.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/rrdJsonParser.c b/src/rrdJsonParser.c index d470bb899..c72c2a8ce 100644 --- a/src/rrdJsonParser.c +++ b/src/rrdJsonParser.c @@ -1,4 +1,3 @@ -#include "rrdCommon.h" /* * If not stated otherwise in this file or this component's LICENSE file the * following copyright and licenses apply: From c3b302b1a598a570f3cd18f96b16840170765ca2 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Sun, 3 May 2026 19:19:05 +0530 Subject: [PATCH 04/79] Update rrdJsonParser.h --- src/rrdJsonParser.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/rrdJsonParser.h b/src/rrdJsonParser.h index 299436101..ba6879cd7 100644 --- a/src/rrdJsonParser.h +++ b/src/rrdJsonParser.h @@ -47,6 +47,12 @@ issueData* getIssueCommandInfo(issueNodeData *issuestructNode, cJSON *jsoncfg,ch bool processAllDebugCommand(cJSON *jsoncfg, issueNodeData *issuestructNode, char *rfcbuf); bool processAllDeepSleepAwkMetricsCommands(cJSON *jsoncfg, issueNodeData *issuestructNode, char *rfcbuf); + +void persist_suffix_to_file(const char *suffix); +char *read_suffix_from_file(); +void read_suffix_from_file_to_buf(char *buf, size_t buflen); +void split_issue_type(const char *input, char *base, size_t base_len, char *suffix, size_t suffix_len); + #ifdef __cplusplus } #endif From dbe0d2ce4fed69c6a808f51a93f95c2fd16ae556 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Sun, 3 May 2026 19:22:08 +0530 Subject: [PATCH 05/79] Update rrdEventProcess.c --- src/rrdEventProcess.c | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/src/rrdEventProcess.c b/src/rrdEventProcess.c index b22e2e13b..8a0529827 100644 --- a/src/rrdEventProcess.c +++ b/src/rrdEventProcess.c @@ -92,15 +92,7 @@ void processIssueTypeEvent(data_buf *rbuf) cmdBuff->appendMode = rbuf->appendMode; cmdBuff->mdata = (char *)calloc(1, dataMsgLen); - /* Store suffix for this issue type */ - cmdBuff->suffix = NULL; - if (local_suffix[0] != '\0') { - cmdBuff->suffix = strdup(local_suffix); - if (cmdBuff->suffix == NULL) - { - RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: Failed to allocate memory for suffix... \n", __FUNCTION__, __LINE__); - } - } + /* Suffix is now persisted via file, no struct field needed */ if (cmdBuff->mdata) { strncpy((char *)cmdBuff->mdata, base, dataMsgLen); @@ -112,16 +104,12 @@ void processIssueTypeEvent(data_buf *rbuf) } if(cmdBuff) { - if (cmdBuff->suffix) - { - /* Persist suffix for this issue type */ - if (local_suffix[0] != '\0') { - persist_suffix_to_file(local_suffix); - } else { - persist_suffix_to_file(""); - } - RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Memory Allocation Failed... \n", __FUNCTION__, __LINE__); - } + /* Persist suffix for this issue type */ + if (local_suffix[0] != '\0') { + persist_suffix_to_file(local_suffix); + } else { + persist_suffix_to_file(""); + } if( cmdMap[index]) { free(cmdMap[index]); From b60dc491a6521b10e1caede73a2ea95376f40648 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Sun, 3 May 2026 19:27:43 +0530 Subject: [PATCH 06/79] Update rrdExecuteScript.h --- src/rrdExecuteScript.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/rrdExecuteScript.h b/src/rrdExecuteScript.h index 02705448d..cb2cb8ec8 100644 --- a/src/rrdExecuteScript.h +++ b/src/rrdExecuteScript.h @@ -28,7 +28,8 @@ extern "C" #include "rrdCommon.h" #include "rrd_upload.h" -int uploadDebugoutput(char *outdir, char *issuename); + +int uploadDebugoutput(char *outdir, char *issuename, const char *suffix); #ifdef __cplusplus } From 942ea5f72fb8c3e396c90fd3ef76470f8fece37f Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Sun, 3 May 2026 19:30:56 +0530 Subject: [PATCH 07/79] Update rrdExecuteScript.h --- src/rrdExecuteScript.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rrdExecuteScript.h b/src/rrdExecuteScript.h index cb2cb8ec8..467bbcee5 100644 --- a/src/rrdExecuteScript.h +++ b/src/rrdExecuteScript.h @@ -29,7 +29,7 @@ extern "C" #include "rrd_upload.h" -int uploadDebugoutput(char *outdir, char *issuename, const char *suffix); +int uploadDebugoutput(char *outdir, char *issuename); #ifdef __cplusplus } From c2a4b508933342c3e41bb6c4af4f998ae4c9840a Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Sun, 3 May 2026 19:32:03 +0530 Subject: [PATCH 08/79] Update rrdJsonParser.c --- src/rrdJsonParser.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rrdJsonParser.c b/src/rrdJsonParser.c index c72c2a8ce..a45e98577 100644 --- a/src/rrdJsonParser.c +++ b/src/rrdJsonParser.c @@ -669,7 +669,7 @@ void checkIssueNodeInfo(issueNodeData *issuestructNode, cJSON *jsoncfg, data_buf RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: [INFO] Original issue string: '%s'\n", __FUNCTION__, __LINE__, buff->mdata); RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: [INFO] Suffix used for upload: '%s'\n", __FUNCTION__, __LINE__, suffix); RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: [INFO] Tar file name for upload: '%s'\n", __FUNCTION__, __LINE__, tarName); - status = uploadDebugoutput(outdir, tarName, suffix); + status = uploadDebugoutput(outdir, tarName); if(status != 0) { RDK_LOG(RDK_LOG_ERROR,LOG_REMDEBUG,"[%s:%d]: RRD Upload Script Execution Failed!!! status:%d\n",__FUNCTION__,__LINE__,status); From 0b5b202aaa6a79b3986e1921c7787dbbccc2e584 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Sun, 3 May 2026 19:35:23 +0530 Subject: [PATCH 09/79] Update rrdJsonParser.c --- src/rrdJsonParser.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/rrdJsonParser.c b/src/rrdJsonParser.c index a45e98577..602e7acce 100644 --- a/src/rrdJsonParser.c +++ b/src/rrdJsonParser.c @@ -88,9 +88,6 @@ void read_suffix_from_file_to_buf(char *buf, size_t buflen) { if (len > 0 && buf[len-1] == '\n') buf[len-1] = '\0'; } -// Utility to split base and suffix from issue type string -// Input: Device.DeviceTime_Search-b6877385-9463-45fc-b19d-a24d77fd0790 -// Output: base = Device.DeviceTime, suffix = _Search-b6877385-9463-45fc-b19d-a24d77fd0790 /* * @function split_issue_type * @brief Utility to split base and suffix from issue type string. From 53ddee2a2705fe8b68186e729ccd610a53c7b2ef Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Sun, 3 May 2026 19:47:30 +0530 Subject: [PATCH 10/79] Update rrdEventProcess.c --- src/rrdEventProcess.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/rrdEventProcess.c b/src/rrdEventProcess.c index 8a0529827..ba148cab3 100644 --- a/src/rrdEventProcess.c +++ b/src/rrdEventProcess.c @@ -104,12 +104,24 @@ void processIssueTypeEvent(data_buf *rbuf) } if(cmdBuff) { - /* Persist suffix for this issue type */ - if (local_suffix[0] != '\0') { + /* Persist suffix for this issue type */ + if (local_suffix[0] != '\0') + { persist_suffix_to_file(local_suffix); - } else { + } + else + { persist_suffix_to_file(""); - } + } + free(cmdBuff); + cmdBuff = NULL; + } + } + else + { + RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Memory Allocation Failed... \n", __FUNCTION__, __LINE__); + } + if( cmdMap[index]) { free(cmdMap[index]); From cf41c44da0a7ea2eedc743f553bb5138f443eb6b Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Sun, 3 May 2026 20:00:12 +0530 Subject: [PATCH 11/79] Update rrdJsonParser.c --- src/rrdJsonParser.c | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/src/rrdJsonParser.c b/src/rrdJsonParser.c index 602e7acce..855540753 100644 --- a/src/rrdJsonParser.c +++ b/src/rrdJsonParser.c @@ -57,19 +57,7 @@ void persist_suffix_to_file(const char *suffix) { } } -char *read_suffix_from_file() { - FILE *fp = fopen("/tmp/rrd_suffix.txt", "r"); - if (!fp) return NULL; - char buf[128] = {0}; - if (fgets(buf, sizeof(buf), fp) == NULL) { - fclose(fp); - return NULL; - } - fclose(fp); - size_t len = strlen(buf); - if (len > 0 && buf[len-1] == '\n') buf[len-1] = '\0'; - return strdup(buf); -} + void read_suffix_from_file_to_buf(char *buf, size_t buflen) { if (!buf || buflen == 0) return; @@ -667,6 +655,7 @@ void checkIssueNodeInfo(issueNodeData *issuestructNode, cJSON *jsoncfg, data_buf RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: [INFO] Suffix used for upload: '%s'\n", __FUNCTION__, __LINE__, suffix); RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: [INFO] Tar file name for upload: '%s'\n", __FUNCTION__, __LINE__, tarName); status = uploadDebugoutput(outdir, tarName); + persist_suffix_to_file(""); // Clear the suffix file after upload if(status != 0) { RDK_LOG(RDK_LOG_ERROR,LOG_REMDEBUG,"[%s:%d]: RRD Upload Script Execution Failed!!! status:%d\n",__FUNCTION__,__LINE__,status); From 538d0b596260ae8679199f74e9324dd93ed2f579 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Sun, 3 May 2026 21:03:50 +0530 Subject: [PATCH 12/79] Update rrdEventProcess.c --- src/rrdEventProcess.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/rrdEventProcess.c b/src/rrdEventProcess.c index ba148cab3..8ac018932 100644 --- a/src/rrdEventProcess.c +++ b/src/rrdEventProcess.c @@ -91,6 +91,15 @@ void processIssueTypeEvent(data_buf *rbuf) } cmdBuff->appendMode = rbuf->appendMode; cmdBuff->mdata = (char *)calloc(1, dataMsgLen); + /* Persist suffix for this issue type */ + if (local_suffix[0] != '\0') + { + persist_suffix_to_file(local_suffix); + } + else + { + persist_suffix_to_file(""); + } /* Suffix is now persisted via file, no struct field needed */ if (cmdBuff->mdata) @@ -104,15 +113,6 @@ void processIssueTypeEvent(data_buf *rbuf) } if(cmdBuff) { - /* Persist suffix for this issue type */ - if (local_suffix[0] != '\0') - { - persist_suffix_to_file(local_suffix); - } - else - { - persist_suffix_to_file(""); - } free(cmdBuff); cmdBuff = NULL; } From 0ee897af653c47b050ee32f6c874b3004d0abf1d Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Sun, 3 May 2026 21:14:50 +0530 Subject: [PATCH 13/79] Update rrdJsonParser.c --- src/rrdJsonParser.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/rrdJsonParser.c b/src/rrdJsonParser.c index 855540753..21e4e5f8f 100644 --- a/src/rrdJsonParser.c +++ b/src/rrdJsonParser.c @@ -268,7 +268,6 @@ void getIssueInfo(char *issuestr, issueNodeData *issue) RDK_LOG(RDK_LOG_INFO,LOG_REMDEBUG,"[%s:%d]: Received Main Node= %s, SubNode= %s\n",__FUNCTION__,__LINE__,issue->Node,issue->subNode); } - /* * @function findIssueInParsedJSON * @brief Finds if an issue category and issue type is present in the parsed JSON. @@ -648,11 +647,6 @@ void checkIssueNodeInfo(issueNodeData *issuestructNode, cJSON *jsoncfg, data_buf } else { snprintf(tarName, sizeof(tarName), "%s", buff->mdata); } - RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Tar file name for upload: '%s'\n", __FUNCTION__, __LINE__, tarName); - RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: [INFO] Tar file name for upload: '%s'\n", __FUNCTION__, __LINE__, tarName); - RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: [INFO] Directory for upload: '%s'\n", __FUNCTION__, __LINE__, outdir); - RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: [INFO] Original issue string: '%s'\n", __FUNCTION__, __LINE__, buff->mdata); - RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: [INFO] Suffix used for upload: '%s'\n", __FUNCTION__, __LINE__, suffix); RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: [INFO] Tar file name for upload: '%s'\n", __FUNCTION__, __LINE__, tarName); status = uploadDebugoutput(outdir, tarName); persist_suffix_to_file(""); // Clear the suffix file after upload From d4266263fa0bb0c6f398d41f0eb81d95093f1e82 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Sun, 3 May 2026 21:16:03 +0530 Subject: [PATCH 14/79] Update rrdEventProcess.c --- src/rrdEventProcess.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/rrdEventProcess.c b/src/rrdEventProcess.c index 8ac018932..4efd71b14 100644 --- a/src/rrdEventProcess.c +++ b/src/rrdEventProcess.c @@ -121,7 +121,6 @@ void processIssueTypeEvent(data_buf *rbuf) { RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Memory Allocation Failed... \n", __FUNCTION__, __LINE__); } - if( cmdMap[index]) { free(cmdMap[index]); From 35e0fae196b7bae2f1b6c9a55ea3f973ca412419 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Sun, 3 May 2026 21:19:19 +0530 Subject: [PATCH 15/79] Update rrdEventProcess.c --- src/rrdEventProcess.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/rrdEventProcess.c b/src/rrdEventProcess.c index 4efd71b14..9b0aee108 100644 --- a/src/rrdEventProcess.c +++ b/src/rrdEventProcess.c @@ -662,6 +662,7 @@ static void removeSpecialCharacterfromIssueTypeList(char *str) } str[destination] = '\0'; } + /* * @function issueTypeSplitter * @brief Splits a given string into tokens based on a specified delimiter, and removes any @@ -711,3 +712,4 @@ static int issueTypeSplitter(char *input_str, const char delimeter, char ***args return cnt; } + From 5b48bf615e1619ad0369a87d60aecb379f156db2 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Sun, 3 May 2026 21:20:05 +0530 Subject: [PATCH 16/79] Update rrdExecuteScript.h --- src/rrdExecuteScript.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/rrdExecuteScript.h b/src/rrdExecuteScript.h index 467bbcee5..02705448d 100644 --- a/src/rrdExecuteScript.h +++ b/src/rrdExecuteScript.h @@ -28,7 +28,6 @@ extern "C" #include "rrdCommon.h" #include "rrd_upload.h" - int uploadDebugoutput(char *outdir, char *issuename); #ifdef __cplusplus From 63df92c8111e16da4864f1681d176936ebed7258 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Sun, 3 May 2026 21:22:50 +0530 Subject: [PATCH 17/79] Update rrdJsonParser.h --- src/rrdJsonParser.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/rrdJsonParser.h b/src/rrdJsonParser.h index ba6879cd7..7b63f5375 100644 --- a/src/rrdJsonParser.h +++ b/src/rrdJsonParser.h @@ -49,7 +49,6 @@ bool processAllDeepSleepAwkMetricsCommands(cJSON *jsoncfg, issueNodeData *issues void persist_suffix_to_file(const char *suffix); -char *read_suffix_from_file(); void read_suffix_from_file_to_buf(char *buf, size_t buflen); void split_issue_type(const char *input, char *base, size_t base_len, char *suffix, size_t suffix_len); From 5edb6dd1f2ccd5d0c503c16efb18208f5da7b1fd Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Sun, 3 May 2026 22:36:39 +0530 Subject: [PATCH 18/79] Update rrdEventProcess.c --- src/rrdEventProcess.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/rrdEventProcess.c b/src/rrdEventProcess.c index 9b0aee108..93f1d5bb1 100644 --- a/src/rrdEventProcess.c +++ b/src/rrdEventProcess.c @@ -91,7 +91,16 @@ void processIssueTypeEvent(data_buf *rbuf) } cmdBuff->appendMode = rbuf->appendMode; cmdBuff->mdata = (char *)calloc(1, dataMsgLen); - /* Persist suffix for this issue type */ + /* Only persist suffix if input contains an underscore (i.e., is not just the base name) */ + if (strchr(cmdMap[index], '_') && local_suffix[0] != '\0') { + RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: [DEBUG] Persisting suffix: '%s' from input: '%s' (index=%d)\n", __FUNCTION__, __LINE__, local_suffix, cmdMap[index], index); + persist_suffix_to_file(local_suffix); + } + else + { + RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: [DEBUG] Not persisting suffix for input: '%s' (index=%d)\n", __FUNCTION__, __LINE__, cmdMap[index], index); + } + /* if (local_suffix[0] != '\0') { persist_suffix_to_file(local_suffix); @@ -100,7 +109,7 @@ void processIssueTypeEvent(data_buf *rbuf) { persist_suffix_to_file(""); } - + */ /* Suffix is now persisted via file, no struct field needed */ if (cmdBuff->mdata) { From 9ed06ddf8fc23a674089856474229463ab4ef640 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Sun, 3 May 2026 22:54:23 +0530 Subject: [PATCH 19/79] Update rrdEventProcess.c --- src/rrdEventProcess.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/rrdEventProcess.c b/src/rrdEventProcess.c index 93f1d5bb1..cde6b4505 100644 --- a/src/rrdEventProcess.c +++ b/src/rrdEventProcess.c @@ -91,15 +91,6 @@ void processIssueTypeEvent(data_buf *rbuf) } cmdBuff->appendMode = rbuf->appendMode; cmdBuff->mdata = (char *)calloc(1, dataMsgLen); - /* Only persist suffix if input contains an underscore (i.e., is not just the base name) */ - if (strchr(cmdMap[index], '_') && local_suffix[0] != '\0') { - RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: [DEBUG] Persisting suffix: '%s' from input: '%s' (index=%d)\n", __FUNCTION__, __LINE__, local_suffix, cmdMap[index], index); - persist_suffix_to_file(local_suffix); - } - else - { - RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: [DEBUG] Not persisting suffix for input: '%s' (index=%d)\n", __FUNCTION__, __LINE__, cmdMap[index], index); - } /* if (local_suffix[0] != '\0') { @@ -113,7 +104,17 @@ void processIssueTypeEvent(data_buf *rbuf) /* Suffix is now persisted via file, no struct field needed */ if (cmdBuff->mdata) { - strncpy((char *)cmdBuff->mdata, base, dataMsgLen); + strncpy((char *)cmdBuff->mdata, base, dataMsgLen); + /* Only persist suffix if input contains an underscore (i.e., is not just the base name) */ + if (strchr(cmdMap[index], '_') && local_suffix[0] != '\0') + { + RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: [DEBUG] Persisting suffix: '%s' from input: '%s' (index=%d)\n", __FUNCTION__, __LINE__, local_suffix, cmdMap[index], index); + persist_suffix_to_file(local_suffix); + } + else + { + RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: [DEBUG] Not persisting suffix for input: '%s' (index=%d)\n", __FUNCTION__, __LINE__, cmdMap[index], index); + } processIssueType(cmdBuff); } else From 1c0cf8284103d4398974b9f83a7a91d7b5314dbb Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 3 May 2026 17:34:02 +0000 Subject: [PATCH 20/79] Add GTest test cases for split_issue_type, persist_suffix_to_file, and read_suffix_from_file_to_buf Agent-Logs-Url: https://github.com/rdkcentral/remote_debugger/sessions/60c9ea5b-f5bf-4445-9dee-3bfde1cc11f2 Co-authored-by: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> --- .gitignore | 42 ++++++ src/unittest/rrdUnitTestRunner.cpp | 202 +++++++++++++++++++++++++++++ 2 files changed, 244 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..62c993b75 --- /dev/null +++ b/.gitignore @@ -0,0 +1,42 @@ +# Build artifacts +*.o +*.gcda +*.gcno +*.Po +*.a +*.so +*.la +*.lo + +# Autotools generated files +Makefile +Makefile.in +aclocal.m4 +autom4te.cache/ +config.guess +config.log +config.status +config.sub +configure +compile +depcomp +install-sh +missing +COPYING +INSTALL +libtool +ltmain.sh +stamp-h1 +.deps/ +.libs/ + +# Test binaries and outputs +src/unittest/remotedebugger_gtest +src/unittest/dummy_*/ + +# Coverage files +*.gcda +*.gcno + +# Temporary files +/tmp/ diff --git a/src/unittest/rrdUnitTestRunner.cpp b/src/unittest/rrdUnitTestRunner.cpp index 7b8c6c837..bbbe8a773 100644 --- a/src/unittest/rrdUnitTestRunner.cpp +++ b/src/unittest/rrdUnitTestRunner.cpp @@ -5817,6 +5817,208 @@ TEST_F(RRDProfileHandlerTest, SetHandler_MaxLengthString) EXPECT_STREQ(RRDProfileCategory, maxString.c_str()); } +/* ====================== split_issue_type / persist_suffix / read_suffix ================*/ + +class SuffixUtilsTest : public ::testing::Test { +protected: + void TearDown() override { + // Remove suffix temp file to avoid state leakage between tests + remove("/tmp/rrd_suffix.txt"); + } +}; + +/* --------------- Test split_issue_type() from rrdJsonParser --------------- */ + +TEST_F(SuffixUtilsTest, SplitIssueType_WithUnderscore) +{ + char base[64] = {0}; + char suffix[64] = {0}; + split_issue_type("Device.DeviceTime_Search123", base, sizeof(base), suffix, sizeof(suffix)); + EXPECT_STREQ(base, "Device.DeviceTime"); + EXPECT_STREQ(suffix, "_Search123"); +} + +TEST_F(SuffixUtilsTest, SplitIssueType_WithNoUnderscore) +{ + char base[64] = {0}; + char suffix[64] = {0}; + split_issue_type("Device.DeviceTime", base, sizeof(base), suffix, sizeof(suffix)); + EXPECT_STREQ(base, "Device.DeviceTime"); + EXPECT_STREQ(suffix, ""); +} + +TEST_F(SuffixUtilsTest, SplitIssueType_WithMultipleUnderscores) +{ + char base[64] = {0}; + char suffix[64] = {0}; + split_issue_type("foo_bar_baz", base, sizeof(base), suffix, sizeof(suffix)); + EXPECT_STREQ(base, "foo"); + EXPECT_STREQ(suffix, "_bar_baz"); +} + +TEST_F(SuffixUtilsTest, SplitIssueType_StartsWithUnderscore) +{ + char base[64] = {0}; + char suffix[64] = {0}; + split_issue_type("_suffix_only", base, sizeof(base), suffix, sizeof(suffix)); + EXPECT_STREQ(base, ""); + EXPECT_STREQ(suffix, "_suffix_only"); +} + +TEST_F(SuffixUtilsTest, SplitIssueType_EmptyString) +{ + char base[64] = {0}; + char suffix[64] = {0}; + split_issue_type("", base, sizeof(base), suffix, sizeof(suffix)); + EXPECT_STREQ(base, ""); + EXPECT_STREQ(suffix, ""); +} + +TEST_F(SuffixUtilsTest, SplitIssueType_NullInputDoesNotCrash) +{ + char base[64] = {0}; + char suffix[64] = {0}; + split_issue_type(NULL, base, sizeof(base), suffix, sizeof(suffix)); + // base and suffix should remain unmodified (empty) + EXPECT_STREQ(base, ""); + EXPECT_STREQ(suffix, ""); +} + +TEST_F(SuffixUtilsTest, SplitIssueType_NullBaseDoesNotCrash) +{ + char suffix[64] = {0}; + // Should not crash when base is NULL + split_issue_type("Device.DeviceTime_Search", NULL, 64, suffix, sizeof(suffix)); +} + +TEST_F(SuffixUtilsTest, SplitIssueType_NullSuffixDoesNotCrash) +{ + char base[64] = {0}; + // Should not crash when suffix is NULL + split_issue_type("Device.DeviceTime_Search", base, sizeof(base), NULL, 64); +} + +TEST_F(SuffixUtilsTest, SplitIssueType_BaseTruncation) +{ + char base[5] = {0}; + char suffix[64] = {0}; + // base_len=5 means max 4 chars + null terminator + split_issue_type("ABCDEF_suffix", base, sizeof(base), suffix, sizeof(suffix)); + EXPECT_STREQ(base, "ABCD"); + EXPECT_STREQ(suffix, "_suffix"); +} + +TEST_F(SuffixUtilsTest, SplitIssueType_RealWorldInput) +{ + char base[128] = {0}; + char suffix[128] = {0}; + split_issue_type("Device.DeviceTime_Search-b6877385-9463-45fc-b19d-a24d77fd0790", + base, sizeof(base), suffix, sizeof(suffix)); + EXPECT_STREQ(base, "Device.DeviceTime"); + EXPECT_STREQ(suffix, "_Search-b6877385-9463-45fc-b19d-a24d77fd0790"); +} + +/* --------------- Test persist_suffix_to_file() from rrdJsonParser --------------- */ + +TEST_F(SuffixUtilsTest, PersistSuffix_NormalValue) +{ + persist_suffix_to_file("_Search123"); + // Verify the file was written + FILE *fp = fopen("/tmp/rrd_suffix.txt", "r"); + ASSERT_NE(fp, nullptr); + char buf[64] = {0}; + ASSERT_NE(fgets(buf, sizeof(buf), fp), nullptr); + fclose(fp); + EXPECT_STREQ(buf, "_Search123"); +} + +TEST_F(SuffixUtilsTest, PersistSuffix_EmptyString) +{ + persist_suffix_to_file(""); + FILE *fp = fopen("/tmp/rrd_suffix.txt", "r"); + ASSERT_NE(fp, nullptr); + char buf[64] = {0}; + // fgets may return NULL for an empty file - that's fine, buf stays empty + fgets(buf, sizeof(buf), fp); + fclose(fp); + EXPECT_STREQ(buf, ""); +} + +TEST_F(SuffixUtilsTest, PersistSuffix_NullDoesNotCrash) +{ + // Passing NULL should not crash; file should be created but empty + persist_suffix_to_file(NULL); + FILE *fp = fopen("/tmp/rrd_suffix.txt", "r"); + ASSERT_NE(fp, nullptr); + char buf[64] = {0}; + fgets(buf, sizeof(buf), fp); + fclose(fp); + EXPECT_STREQ(buf, ""); +} + +TEST_F(SuffixUtilsTest, PersistSuffix_OverwritesPreviousValue) +{ + persist_suffix_to_file("_OldSuffix"); + persist_suffix_to_file("_NewSuffix"); + char buf[64] = {0}; + read_suffix_from_file_to_buf(buf, sizeof(buf)); + EXPECT_STREQ(buf, "_NewSuffix"); +} + +/* --------------- Test read_suffix_from_file_to_buf() from rrdJsonParser --------------- */ + +TEST_F(SuffixUtilsTest, ReadSuffix_AfterPersist) +{ + persist_suffix_to_file("_Search123"); + char buf[64] = {0}; + read_suffix_from_file_to_buf(buf, sizeof(buf)); + EXPECT_STREQ(buf, "_Search123"); +} + +TEST_F(SuffixUtilsTest, ReadSuffix_WhenFileAbsent) +{ + remove("/tmp/rrd_suffix.txt"); + char buf[64] = {0}; + read_suffix_from_file_to_buf(buf, sizeof(buf)); + EXPECT_STREQ(buf, ""); +} + +TEST_F(SuffixUtilsTest, ReadSuffix_NullBufDoesNotCrash) +{ + persist_suffix_to_file("_test"); + // Should not crash when buf is NULL + read_suffix_from_file_to_buf(NULL, 64); +} + +TEST_F(SuffixUtilsTest, ReadSuffix_ZeroBuflenDoesNotCrash) +{ + persist_suffix_to_file("_test"); + char buf[64] = {0}; + // Should not crash when buflen is 0 + read_suffix_from_file_to_buf(buf, 0); +} + +TEST_F(SuffixUtilsTest, ReadSuffix_RoundTrip) +{ + const char *expected = "_Search-b6877385-9463-45fc-b19d-a24d77fd0790"; + persist_suffix_to_file(expected); + char buf[128] = {0}; + read_suffix_from_file_to_buf(buf, sizeof(buf)); + EXPECT_STREQ(buf, expected); +} + +TEST_F(SuffixUtilsTest, ReadSuffix_StripsTrailingNewline) +{ + // Write a value with a trailing newline to the file + FILE *fp = fopen("/tmp/rrd_suffix.txt", "w"); + ASSERT_NE(fp, nullptr); + fputs("_suffix\n", fp); + fclose(fp); + char buf[64] = {0}; + read_suffix_from_file_to_buf(buf, sizeof(buf)); + EXPECT_STREQ(buf, "_suffix"); +} + From 32c5fd5087eb5c95ecac4e6f99888eb69ab86dff Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 3 May 2026 17:35:15 +0000 Subject: [PATCH 21/79] Remove build artifacts and add .gitignore Agent-Logs-Url: https://github.com/rdkcentral/remote_debugger/sessions/60c9ea5b-f5bf-4445-9dee-3bfde1cc11f2 Co-authored-by: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> --- src/unittest/UTJson/device.properties | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/unittest/UTJson/device.properties diff --git a/src/unittest/UTJson/device.properties b/src/unittest/UTJson/device.properties new file mode 100644 index 000000000..e69de29bb From e4afa187a6824a01bc7d1d1fbe66f5fbe4666275 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 3 May 2026 17:35:38 +0000 Subject: [PATCH 22/79] Remove build-generated device.properties from tracking Co-authored-by: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> --- .gitignore | 3 +++ src/unittest/UTJson/device.properties | 0 2 files changed, 3 insertions(+) delete mode 100644 src/unittest/UTJson/device.properties diff --git a/.gitignore b/.gitignore index 62c993b75..dc7427fdd 100644 --- a/.gitignore +++ b/.gitignore @@ -40,3 +40,6 @@ src/unittest/dummy_*/ # Temporary files /tmp/ + +# Test-generated device properties +src/unittest/UTJson/device.properties diff --git a/src/unittest/UTJson/device.properties b/src/unittest/UTJson/device.properties deleted file mode 100644 index e69de29bb..000000000 From 447298c55c29ae75fef154c358020383e197d2e5 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Sun, 3 May 2026 23:37:17 +0530 Subject: [PATCH 23/79] Update rrdJsonParser.c --- src/rrdJsonParser.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/rrdJsonParser.c b/src/rrdJsonParser.c index 21e4e5f8f..8e2b57e75 100644 --- a/src/rrdJsonParser.c +++ b/src/rrdJsonParser.c @@ -89,17 +89,37 @@ void read_suffix_from_file_to_buf(char *buf, size_t buflen) { * @return void */ void split_issue_type(const char *input, char *base, size_t base_len, char *suffix, size_t suffix_len) { - if (!input || !base || !suffix) return; + if (base && base_len > 0) + { + base[0] = '\0'; + } + if (suffix && suffix_len > 0) + { + suffix[0] = '\0'; + } + + if (!input || !base || !suffix) + { + return; + } + + if (base_len == 0 || suffix_len == 0) + { + return; + } RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: [INFO] split_issue_type called with input='%s'\n", __FUNCTION__, __LINE__, input); const char *underscore = strchr(input, '_'); - if (underscore) { + if (underscore) + { size_t b_len = underscore - input; if (b_len >= base_len) b_len = base_len - 1; strncpy(base, input, b_len); base[b_len] = '\0'; strncpy(suffix, underscore, suffix_len - 1); suffix[suffix_len - 1] = '\0'; - } else { + } + else + { strncpy(base, input, base_len - 1); base[base_len - 1] = '\0'; suffix[0] = '\0'; From 1f7555fde4905d9b0aac729e4dda2a55f3b6ab33 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Mon, 4 May 2026 07:30:21 +0530 Subject: [PATCH 24/79] Move suffix file clearing after upload success --- src/rrdJsonParser.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rrdJsonParser.c b/src/rrdJsonParser.c index 8e2b57e75..eddd69c5b 100644 --- a/src/rrdJsonParser.c +++ b/src/rrdJsonParser.c @@ -669,7 +669,6 @@ void checkIssueNodeInfo(issueNodeData *issuestructNode, cJSON *jsoncfg, data_buf } RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: [INFO] Tar file name for upload: '%s'\n", __FUNCTION__, __LINE__, tarName); status = uploadDebugoutput(outdir, tarName); - persist_suffix_to_file(""); // Clear the suffix file after upload if(status != 0) { RDK_LOG(RDK_LOG_ERROR,LOG_REMDEBUG,"[%s:%d]: RRD Upload Script Execution Failed!!! status:%d\n",__FUNCTION__,__LINE__,status); @@ -682,6 +681,7 @@ void checkIssueNodeInfo(issueNodeData *issuestructNode, cJSON *jsoncfg, data_buf free(rfcbuf); // free duplicated rfc data free(buff->mdata); // free rfc data free(buff->jsonPath); // free rrd path info + persist_suffix_to_file(""); // Clear the suffix file after upload } else { From ca6e2b1a6443ad25821e45f7fc5021eed98aa584 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Mon, 4 May 2026 07:35:25 +0530 Subject: [PATCH 25/79] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- src/rrdEventProcess.c | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/rrdEventProcess.c b/src/rrdEventProcess.c index cde6b4505..e308eda01 100644 --- a/src/rrdEventProcess.c +++ b/src/rrdEventProcess.c @@ -91,16 +91,6 @@ void processIssueTypeEvent(data_buf *rbuf) } cmdBuff->appendMode = rbuf->appendMode; cmdBuff->mdata = (char *)calloc(1, dataMsgLen); - /* - if (local_suffix[0] != '\0') - { - persist_suffix_to_file(local_suffix); - } - else - { - persist_suffix_to_file(""); - } - */ /* Suffix is now persisted via file, no struct field needed */ if (cmdBuff->mdata) { From 3010e952a83bd0afa72c429aedb1fe159747a39e Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Mon, 4 May 2026 07:41:15 +0530 Subject: [PATCH 26/79] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- src/rrdEventProcess.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rrdEventProcess.c b/src/rrdEventProcess.c index e308eda01..98fd05e44 100644 --- a/src/rrdEventProcess.c +++ b/src/rrdEventProcess.c @@ -98,12 +98,12 @@ void processIssueTypeEvent(data_buf *rbuf) /* Only persist suffix if input contains an underscore (i.e., is not just the base name) */ if (strchr(cmdMap[index], '_') && local_suffix[0] != '\0') { - RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: [DEBUG] Persisting suffix: '%s' from input: '%s' (index=%d)\n", __FUNCTION__, __LINE__, local_suffix, cmdMap[index], index); + RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: [DEBUG] Persisting suffix: '%s' from input: '%s' (index=%d)\n", __FUNCTION__, __LINE__, local_suffix, cmdMap[index], index); persist_suffix_to_file(local_suffix); } else { - RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: [DEBUG] Not persisting suffix for input: '%s' (index=%d)\n", __FUNCTION__, __LINE__, cmdMap[index], index); + RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: [DEBUG] Not persisting suffix for input: '%s' (index=%d)\n", __FUNCTION__, __LINE__, cmdMap[index], index); } processIssueType(cmdBuff); } From 768421c77e7da4fc0d4e488b0750a71990b26db3 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Mon, 4 May 2026 07:45:19 +0530 Subject: [PATCH 27/79] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- src/rrdEventProcess.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rrdEventProcess.c b/src/rrdEventProcess.c index 98fd05e44..509fc3103 100644 --- a/src/rrdEventProcess.c +++ b/src/rrdEventProcess.c @@ -653,7 +653,7 @@ static void removeSpecialCharacterfromIssueTypeList(char *str) while (str[source] != '\0') { - if (isalnum(str[source]) || str[source] == ',' || str[source] == '.' || str[source] == '_'|| str[source] == '-') + if (isalnum((unsigned char)str[source]) || str[source] == ',' || str[source] == '.' || str[source] == '_'|| str[source] == '-') { str[destination] = str[source]; ++destination; From 2cf9e9efb76b6939ea4700a4fd6903bc639db20b Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Mon, 4 May 2026 07:47:29 +0530 Subject: [PATCH 28/79] Update rrdEventProcess.c --- src/rrdEventProcess.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rrdEventProcess.c b/src/rrdEventProcess.c index 509fc3103..7561fb1b3 100644 --- a/src/rrdEventProcess.c +++ b/src/rrdEventProcess.c @@ -642,7 +642,7 @@ static void freeParsedJson(cJSON *jsonParsed) /* * @function removeSpecialCharacterfromIssueTypeList * @brief Removes special characters from the issue type list, retaining only alphanumeric - * characters, commas, and periods. + * characters, commas, periods, underscores and hyphens * @param char *str - The string from which special characters will be removed. * @return void */ From 73a902290856d8bdad2ebc30a2e7803fd3fe7a85 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Mon, 4 May 2026 07:57:45 +0530 Subject: [PATCH 29/79] Update rrdJsonParser.c --- src/rrdJsonParser.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/rrdJsonParser.c b/src/rrdJsonParser.c index eddd69c5b..30a877ab5 100644 --- a/src/rrdJsonParser.c +++ b/src/rrdJsonParser.c @@ -598,6 +598,7 @@ void checkIssueNodeInfo(issueNodeData *issuestructNode, cJSON *jsoncfg, data_buf RDK_LOG(RDK_LOG_ERROR,LOG_REMDEBUG,"[%s:%d]: Memory allocation failed for rfcbuf\n",__FUNCTION__,__LINE__); free(buff->mdata); // free rfc data free(buff->jsonPath); // free rrd path info + persist_suffix_to_file(""); // Clear the suffix file on early exit return; } @@ -618,6 +619,7 @@ void checkIssueNodeInfo(issueNodeData *issuestructNode, cJSON *jsoncfg, data_buf free(rfcbuf); // free duplicated rfc data free(buff->mdata); // free rfc data free(buff->jsonPath); // free rrd path info + persist_suffix_to_file(""); // Clear the suffix file on early exit return; } else @@ -689,6 +691,7 @@ void checkIssueNodeInfo(issueNodeData *issuestructNode, cJSON *jsoncfg, data_buf free(rfcbuf); // free duplicated rfc data free(buff->mdata); // free rfc data free(buff->jsonPath); // free rrd path info + persist_suffix_to_file(""); // Clear the suffix file } } } From 1a656c9312812fdcc35d4531099cecf96f29aeab Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Mon, 4 May 2026 08:01:33 +0530 Subject: [PATCH 30/79] Update rrdJsonParser.c --- src/rrdJsonParser.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rrdJsonParser.c b/src/rrdJsonParser.c index 30a877ab5..1e6a68aa4 100644 --- a/src/rrdJsonParser.c +++ b/src/rrdJsonParser.c @@ -107,7 +107,7 @@ void split_issue_type(const char *input, char *base, size_t base_len, char *suff { return; } - RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: [INFO] split_issue_type called with input='%s'\n", __FUNCTION__, __LINE__, input); + RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: split_issue_type called with input='%s'\n", __FUNCTION__, __LINE__, input); const char *underscore = strchr(input, '_'); if (underscore) { @@ -124,7 +124,7 @@ void split_issue_type(const char *input, char *base, size_t base_len, char *suff base[base_len - 1] = '\0'; suffix[0] = '\0'; } - RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: [INFO] split_issue_type result: base='%s', suffix='%s'\n", __FUNCTION__, __LINE__, base, suffix); + RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: split_issue_type result: base='%s', suffix='%s'\n", __FUNCTION__, __LINE__, base, suffix); } From 66dab909c9fa93e8a19a536cf4fec63bbab617de Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Mon, 4 May 2026 08:10:21 +0530 Subject: [PATCH 31/79] Update rrdJsonParser.c --- src/rrdJsonParser.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/rrdJsonParser.c b/src/rrdJsonParser.c index 1e6a68aa4..9ee401f2f 100644 --- a/src/rrdJsonParser.c +++ b/src/rrdJsonParser.c @@ -664,13 +664,25 @@ void checkIssueNodeInfo(issueNodeData *issuestructNode, cJSON *jsoncfg, data_buf char suffix[128] = {0}; read_suffix_from_file_to_buf(suffix, sizeof(suffix)); char tarName[512] = {0}; + int tar_name_len = 0; if (suffix[0] != '\0') { - snprintf(tarName, sizeof(tarName), "%s%s", buff->mdata, suffix); - } else { - snprintf(tarName, sizeof(tarName), "%s", buff->mdata); + tar_name_len = snprintf(tarName, sizeof(tarName), "%s%s", buff->mdata, suffix); + } + else + { + tar_name_len = snprintf(tarName, sizeof(tarName), "%s", buff->mdata); } - RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: [INFO] Tar file name for upload: '%s'\n", __FUNCTION__, __LINE__, tarName); - status = uploadDebugoutput(outdir, tarName); + if ((tar_name_len < 0) || ((size_t)tar_name_len >= sizeof(tarName))) + { + RDK_LOG(RDK_LOG_ERROR,LOG_REMDEBUG,"[%s:%d]: Failed to build upload file name for %s. snprintf result:%d, buffer size:%zu\n", __FUNCTION__,__LINE__,buff->mdata,tar_name_len,sizeof(tarName)); + status = -1; + } + else + { + RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: [INFO] Tar file name for upload: '%s'\n", __FUNCTION__, __LINE__, tarName); + status = uploadDebugoutput(outdir, tarName); + } + if(status != 0) { RDK_LOG(RDK_LOG_ERROR,LOG_REMDEBUG,"[%s:%d]: RRD Upload Script Execution Failed!!! status:%d\n",__FUNCTION__,__LINE__,status); From ee73b5f565aaeeca60d851c4afe854adffb2bcb8 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Mon, 4 May 2026 08:13:33 +0530 Subject: [PATCH 32/79] Update rrdEventProcess.c --- src/rrdEventProcess.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rrdEventProcess.c b/src/rrdEventProcess.c index 7561fb1b3..90520f9c0 100644 --- a/src/rrdEventProcess.c +++ b/src/rrdEventProcess.c @@ -79,8 +79,8 @@ void processIssueTypeEvent(data_buf *rbuf) cmdBuff = (data_buf *)malloc(sizeof(data_buf)); if (cmdBuff) { - char base[128] = {0}; - char local_suffix[128] = {0}; + char base[BUF_LEN_128] = {0}; + char local_suffix[BUF_LEN_128] = {0}; split_issue_type(cmdMap[index], base, sizeof(base), local_suffix, sizeof(local_suffix)); dataMsgLen = strlen(base) + 1; RRD_data_buff_init(cmdBuff, EVENT_MSG, RRD_DEEPSLEEP_INVALID_DEFAULT); /* Setting Deafult Values*/ From a92b1762777379dc8415c71f77595d5ba5e78223 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Mon, 4 May 2026 08:44:41 +0530 Subject: [PATCH 33/79] Update rrdJsonParser.c --- src/rrdJsonParser.c | 43 ++++++++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/src/rrdJsonParser.c b/src/rrdJsonParser.c index 9ee401f2f..2cb2a0a9f 100644 --- a/src/rrdJsonParser.c +++ b/src/rrdJsonParser.c @@ -24,6 +24,8 @@ #include #include #include +#define RRD_SUFFIX_DIR "/tmp" +#define RRD_SUFFIX_PATH "/tmp/rrd_suffix.txt" /* * @function removeSpecialChar @@ -46,32 +48,47 @@ void removeSpecialChar(char *str) } } - void persist_suffix_to_file(const char *suffix) { - FILE *fp = fopen("/tmp/rrd_suffix.txt", "w"); - if (fp) { - if (suffix) { - fputs(suffix, fp); + // Ensure directory exists + if (mkdir(RRD_SUFFIX_DIR, 0700) != 0 && errno != EEXIST) { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] Failed to create %s: %s\n", __FUNCTION__, __LINE__, RRD_SUFFIX_DIR, strerror(errno)); + return; + } + int fd = open(RRD_SUFFIX_PATH, O_WRONLY | O_CREAT | O_TRUNC | O_NOFOLLOW | O_CLOEXEC, 0600); + if (fd == -1) { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] Failed to open %s for writing: %s\n", __FUNCTION__, __LINE__, RRD_SUFFIX_PATH, strerror(errno)); + return; + } + if (suffix && suffix[0] != '\0') { + ssize_t written = write(fd, suffix, strlen(suffix)); + if (written < 0) { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] Failed to write suffix: %s\n", __FUNCTION__, __LINE__, strerror(errno)); + } else { + RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: [DEBUG] Suffix '%s' written to %s\n", __FUNCTION__, __LINE__, suffix, RRD_SUFFIX_PATH); } - fclose(fp); + } else { + // Truncate file to empty + ftruncate(fd, 0); + RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: [DEBUG] Suffix cleared in %s\n", __FUNCTION__, __LINE__, RRD_SUFFIX_PATH); } + close(fd); } - - void read_suffix_from_file_to_buf(char *buf, size_t buflen) { if (!buf || buflen == 0) return; - FILE *fp = fopen("/tmp/rrd_suffix.txt", "r"); - if (!fp) { + int fd = open(RRD_SUFFIX_PATH, O_RDONLY | O_NOFOLLOW | O_CLOEXEC); + if (fd == -1) { buf[0] = '\0'; return; } - if (fgets(buf, buflen, fp) == NULL) { + ssize_t r = read(fd, buf, buflen - 1); + if (r < 0) { buf[0] = '\0'; - fclose(fp); + close(fd); return; } - fclose(fp); + buf[r] = '\0'; + close(fd); size_t len = strlen(buf); if (len > 0 && buf[len-1] == '\n') buf[len-1] = '\0'; } From 7ebde8ebb360f91e9cf48aa2c6e40af60ec8f9dd Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Mon, 4 May 2026 08:56:26 +0530 Subject: [PATCH 34/79] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- src/rrdJsonParser.c | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/src/rrdJsonParser.c b/src/rrdJsonParser.c index 2cb2a0a9f..f10cacd3c 100644 --- a/src/rrdJsonParser.c +++ b/src/rrdJsonParser.c @@ -60,16 +60,37 @@ void persist_suffix_to_file(const char *suffix) { return; } if (suffix && suffix[0] != '\0') { - ssize_t written = write(fd, suffix, strlen(suffix)); - if (written < 0) { - RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] Failed to write suffix: %s\n", __FUNCTION__, __LINE__, strerror(errno)); - } else { + size_t suffix_len = strlen(suffix); + size_t total_written = 0; + + while (total_written < suffix_len) { + ssize_t written = write(fd, suffix + total_written, suffix_len - total_written); + if (written < 0) { + if (errno == EINTR) { + continue; + } + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] Failed to write suffix: %s\n", __FUNCTION__, __LINE__, strerror(errno)); + break; + } + + if (written == 0) { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] Short write while writing suffix to %s\n", __FUNCTION__, __LINE__, RRD_SUFFIX_PATH); + break; + } + + total_written += (size_t)written; + } + + if (total_written == suffix_len) { RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: [DEBUG] Suffix '%s' written to %s\n", __FUNCTION__, __LINE__, suffix, RRD_SUFFIX_PATH); } } else { // Truncate file to empty - ftruncate(fd, 0); - RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: [DEBUG] Suffix cleared in %s\n", __FUNCTION__, __LINE__, RRD_SUFFIX_PATH); + if (ftruncate(fd, 0) != 0) { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] Failed to clear suffix in %s: %s\n", __FUNCTION__, __LINE__, RRD_SUFFIX_PATH, strerror(errno)); + } else { + RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: [DEBUG] Suffix cleared in %s\n", __FUNCTION__, __LINE__, RRD_SUFFIX_PATH); + } } close(fd); } From 4bbca629581e2695eaf3c86a4a8ac88d61bf5c81 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Mon, 4 May 2026 08:57:54 +0530 Subject: [PATCH 35/79] Update rrdJsonParser.c --- src/rrdJsonParser.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rrdJsonParser.c b/src/rrdJsonParser.c index f10cacd3c..fa261d4f6 100644 --- a/src/rrdJsonParser.c +++ b/src/rrdJsonParser.c @@ -24,8 +24,8 @@ #include #include #include -#define RRD_SUFFIX_DIR "/tmp" -#define RRD_SUFFIX_PATH "/tmp/rrd_suffix.txt" +#define RRD_SUFFIX_DIR "/tmp/rrd" +#define RRD_SUFFIX_PATH "/tmp/rrd/rrd_suffix.txt" /* * @function removeSpecialChar From b96eb553332bff5e2f93d9f6b047e7f6442115d1 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Mon, 4 May 2026 08:59:34 +0530 Subject: [PATCH 36/79] Update rrdJsonParser.c --- src/rrdJsonParser.c | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/rrdJsonParser.c b/src/rrdJsonParser.c index fa261d4f6..cb0f7b9c8 100644 --- a/src/rrdJsonParser.c +++ b/src/rrdJsonParser.c @@ -48,7 +48,8 @@ void removeSpecialChar(char *str) } } -void persist_suffix_to_file(const char *suffix) { +void persist_suffix_to_file(const char *suffix) +{ // Ensure directory exists if (mkdir(RRD_SUFFIX_DIR, 0700) != 0 && errno != EEXIST) { RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] Failed to create %s: %s\n", __FUNCTION__, __LINE__, RRD_SUFFIX_DIR, strerror(errno)); @@ -59,21 +60,26 @@ void persist_suffix_to_file(const char *suffix) { RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] Failed to open %s for writing: %s\n", __FUNCTION__, __LINE__, RRD_SUFFIX_PATH, strerror(errno)); return; } - if (suffix && suffix[0] != '\0') { + if (suffix && suffix[0] != '\0') + { size_t suffix_len = strlen(suffix); size_t total_written = 0; - while (total_written < suffix_len) { + while (total_written < suffix_len) + { ssize_t written = write(fd, suffix + total_written, suffix_len - total_written); - if (written < 0) { - if (errno == EINTR) { + if (written < 0) + { + if (errno == EINTR) + { continue; } RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] Failed to write suffix: %s\n", __FUNCTION__, __LINE__, strerror(errno)); break; } - if (written == 0) { + if (written == 0) + { RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] Short write while writing suffix to %s\n", __FUNCTION__, __LINE__, RRD_SUFFIX_PATH); break; } @@ -81,14 +87,19 @@ void persist_suffix_to_file(const char *suffix) { total_written += (size_t)written; } - if (total_written == suffix_len) { + if (total_written == suffix_len) + { RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: [DEBUG] Suffix '%s' written to %s\n", __FUNCTION__, __LINE__, suffix, RRD_SUFFIX_PATH); } - } else { + } + else + { // Truncate file to empty - if (ftruncate(fd, 0) != 0) { + if (ftruncate(fd, 0) != 0) + { RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] Failed to clear suffix in %s: %s\n", __FUNCTION__, __LINE__, RRD_SUFFIX_PATH, strerror(errno)); - } else { + } else + { RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: [DEBUG] Suffix cleared in %s\n", __FUNCTION__, __LINE__, RRD_SUFFIX_PATH); } } From be092092b951d2187435659330510bb3b936c2cc Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Mon, 4 May 2026 09:10:25 +0530 Subject: [PATCH 37/79] Update rrdJsonParser.c --- src/rrdJsonParser.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/rrdJsonParser.c b/src/rrdJsonParser.c index cb0f7b9c8..427745df5 100644 --- a/src/rrdJsonParser.c +++ b/src/rrdJsonParser.c @@ -24,9 +24,12 @@ #include #include #include +#include +#include #define RRD_SUFFIX_DIR "/tmp/rrd" #define RRD_SUFFIX_PATH "/tmp/rrd/rrd_suffix.txt" + /* * @function removeSpecialChar * @brief Removes special characters ('\r' and '\n') from the device properties parameter string. From edb1a3ee33ee5904d38808d3d00318976f6842a7 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Mon, 4 May 2026 09:15:18 +0530 Subject: [PATCH 38/79] Improve error handling in persist_suffix_to_file Refactor error handling and add checks for file properties. --- src/rrdJsonParser.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/rrdJsonParser.c b/src/rrdJsonParser.c index 427745df5..01b196f4f 100644 --- a/src/rrdJsonParser.c +++ b/src/rrdJsonParser.c @@ -54,15 +54,26 @@ void removeSpecialChar(char *str) void persist_suffix_to_file(const char *suffix) { // Ensure directory exists - if (mkdir(RRD_SUFFIX_DIR, 0700) != 0 && errno != EEXIST) { + if (mkdir(RRD_SUFFIX_DIR, 0700) != 0 && errno != EEXIST) + { RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] Failed to create %s: %s\n", __FUNCTION__, __LINE__, RRD_SUFFIX_DIR, strerror(errno)); return; } + int fd = open(RRD_SUFFIX_PATH, O_WRONLY | O_CREAT | O_TRUNC | O_NOFOLLOW | O_CLOEXEC, 0600); if (fd == -1) { RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] Failed to open %s for writing: %s\n", __FUNCTION__, __LINE__, RRD_SUFFIX_PATH, strerror(errno)); return; } + + struct stat st; + if (fstat(fd, &st) != 0 || !S_ISREG(st.st_mode)) + { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] %s is not a regular file!\n", __FUNCTION__, __LINE__, RRD_SUFFIX_PATH); + close(fd); + return; + } + if (suffix && suffix[0] != '\0') { size_t suffix_len = strlen(suffix); From c619616257e2858b3cab4b073d793b066eb363d4 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Mon, 4 May 2026 09:17:48 +0530 Subject: [PATCH 39/79] Update rrdJsonParser.c --- src/rrdJsonParser.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/rrdJsonParser.c b/src/rrdJsonParser.c index 01b196f4f..4d02f395a 100644 --- a/src/rrdJsonParser.c +++ b/src/rrdJsonParser.c @@ -26,6 +26,7 @@ #include #include #include +#include #define RRD_SUFFIX_DIR "/tmp/rrd" #define RRD_SUFFIX_PATH "/tmp/rrd/rrd_suffix.txt" From a194be8e0a6c9c4c10a91c480fa49dca86168709 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Mon, 4 May 2026 09:19:18 +0530 Subject: [PATCH 40/79] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- src/rrdJsonParser.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/rrdJsonParser.c b/src/rrdJsonParser.c index 4d02f395a..71f1823fe 100644 --- a/src/rrdJsonParser.c +++ b/src/rrdJsonParser.c @@ -122,13 +122,19 @@ void persist_suffix_to_file(const char *suffix) } void read_suffix_from_file_to_buf(char *buf, size_t buflen) { + ssize_t r = -1; + if (!buf || buflen == 0) return; int fd = open(RRD_SUFFIX_PATH, O_RDONLY | O_NOFOLLOW | O_CLOEXEC); if (fd == -1) { buf[0] = '\0'; return; } - ssize_t r = read(fd, buf, buflen - 1); + + do { + r = read(fd, buf, buflen - 1); + } while (r < 0 && errno == EINTR); + if (r < 0) { buf[0] = '\0'; close(fd); From ab3aaccb69b43f5651443a65361cb34be37528a8 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Mon, 4 May 2026 09:21:11 +0530 Subject: [PATCH 41/79] Update rrdJsonParser.c --- src/rrdJsonParser.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/rrdJsonParser.c b/src/rrdJsonParser.c index 71f1823fe..361038b06 100644 --- a/src/rrdJsonParser.c +++ b/src/rrdJsonParser.c @@ -126,16 +126,19 @@ void read_suffix_from_file_to_buf(char *buf, size_t buflen) { if (!buf || buflen == 0) return; int fd = open(RRD_SUFFIX_PATH, O_RDONLY | O_NOFOLLOW | O_CLOEXEC); - if (fd == -1) { + if (fd == -1) + { buf[0] = '\0'; return; } - do { + do + { r = read(fd, buf, buflen - 1); } while (r < 0 && errno == EINTR); - if (r < 0) { + if (r < 0) + { buf[0] = '\0'; close(fd); return; From 40187fa7ce1b2c9f0f25803362d1ea95d5ff9633 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Mon, 4 May 2026 09:31:46 +0530 Subject: [PATCH 42/79] Update rrdJsonParser.c --- src/rrdJsonParser.c | 213 +++++++++++++++++++++----------------------- 1 file changed, 101 insertions(+), 112 deletions(-) diff --git a/src/rrdJsonParser.c b/src/rrdJsonParser.c index 361038b06..96d7f1e5a 100644 --- a/src/rrdJsonParser.c +++ b/src/rrdJsonParser.c @@ -24,12 +24,6 @@ #include #include #include -#include -#include -#include -#define RRD_SUFFIX_DIR "/tmp/rrd" -#define RRD_SUFFIX_PATH "/tmp/rrd/rrd_suffix.txt" - /* * @function removeSpecialChar @@ -52,99 +46,123 @@ void removeSpecialChar(char *str) } } -void persist_suffix_to_file(const char *suffix) -{ - // Ensure directory exists - if (mkdir(RRD_SUFFIX_DIR, 0700) != 0 && errno != EEXIST) - { - RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] Failed to create %s: %s\n", __FUNCTION__, __LINE__, RRD_SUFFIX_DIR, strerror(errno)); - return; + + +#include +#include +#include + + + +#define RRD_SUFFIX_DIR "/tmp/rrd" +#define RRD_SUFFIX_FILE "rrd_suffix.txt" + +#include +#include + +static int secure_open_rrd_dir(void) { + struct stat st; + if (lstat(RRD_SUFFIX_DIR, &st) == 0) { + if (!S_ISDIR(st.st_mode)) { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] %s exists but is not a directory!\n", __FUNCTION__, __LINE__, RRD_SUFFIX_DIR); + return -1; + } + // Optionally check ownership: must be root or current user + uid_t uid = geteuid(); + if (st.st_uid != 0 && st.st_uid != uid) { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] %s not owned by root or current user!\n", __FUNCTION__, __LINE__, RRD_SUFFIX_DIR); + return -1; + } + } else { + if (mkdir(RRD_SUFFIX_DIR, 0700) != 0 && errno != EEXIST) { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] Failed to create %s: %s\n", __FUNCTION__, __LINE__, RRD_SUFFIX_DIR, strerror(errno)); + return -1; + } + } + int dirfd = open(RRD_SUFFIX_DIR, O_DIRECTORY | O_NOFOLLOW | O_CLOEXEC); + if (dirfd == -1) { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] Failed to securely open %s: %s\n", __FUNCTION__, __LINE__, RRD_SUFFIX_DIR, strerror(errno)); + return -1; } - - int fd = open(RRD_SUFFIX_PATH, O_WRONLY | O_CREAT | O_TRUNC | O_NOFOLLOW | O_CLOEXEC, 0600); + return dirfd; +} + +void persist_suffix_to_file(const char *suffix) { + int dirfd = secure_open_rrd_dir(); + if (dirfd == -1) return; + int fd = openat(dirfd, RRD_SUFFIX_FILE, O_WRONLY | O_CREAT | O_TRUNC | O_NOFOLLOW | O_CLOEXEC, 0600); if (fd == -1) { - RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] Failed to open %s for writing: %s\n", __FUNCTION__, __LINE__, RRD_SUFFIX_PATH, strerror(errno)); + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] Failed to openat %s/%s for writing: %s\n", __FUNCTION__, __LINE__, RRD_SUFFIX_DIR, RRD_SUFFIX_FILE, strerror(errno)); + close(dirfd); return; } - - struct stat st; - if (fstat(fd, &st) != 0 || !S_ISREG(st.st_mode)) - { - RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] %s is not a regular file!\n", __FUNCTION__, __LINE__, RRD_SUFFIX_PATH); + struct stat st; + if (fstat(fd, &st) != 0 || !S_ISREG(st.st_mode)) { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] %s/%s is not a regular file!\n", __FUNCTION__, __LINE__, RRD_SUFFIX_DIR, RRD_SUFFIX_FILE); close(fd); + close(dirfd); return; } - - if (suffix && suffix[0] != '\0') - { + if (suffix && suffix[0] != '\0') { size_t suffix_len = strlen(suffix); size_t total_written = 0; - - while (total_written < suffix_len) - { + while (total_written < suffix_len) { ssize_t written = write(fd, suffix + total_written, suffix_len - total_written); - if (written < 0) - { - if (errno == EINTR) - { - continue; - } + if (written < 0) { RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] Failed to write suffix: %s\n", __FUNCTION__, __LINE__, strerror(errno)); break; } - - if (written == 0) - { - RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] Short write while writing suffix to %s\n", __FUNCTION__, __LINE__, RRD_SUFFIX_PATH); + if (written == 0) { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] Zero bytes written, aborting.\n", __FUNCTION__, __LINE__); break; } - total_written += (size_t)written; + if (total_written > suffix_len) { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] total_written overflow, aborting.\n", __FUNCTION__, __LINE__); + break; + } } - - if (total_written == suffix_len) - { - RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: [DEBUG] Suffix '%s' written to %s\n", __FUNCTION__, __LINE__, suffix, RRD_SUFFIX_PATH); - } - } - else - { - // Truncate file to empty - if (ftruncate(fd, 0) != 0) - { - RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] Failed to clear suffix in %s: %s\n", __FUNCTION__, __LINE__, RRD_SUFFIX_PATH, strerror(errno)); - } else - { - RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: [DEBUG] Suffix cleared in %s\n", __FUNCTION__, __LINE__, RRD_SUFFIX_PATH); + if (total_written == suffix_len) { + RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: [DEBUG] Suffix '%s' written to %s/%s\n", __FUNCTION__, __LINE__, suffix, RRD_SUFFIX_DIR, RRD_SUFFIX_FILE); } + } else { + ftruncate(fd, 0); + RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: [DEBUG] Suffix cleared in %s/%s\n", __FUNCTION__, __LINE__, RRD_SUFFIX_DIR, RRD_SUFFIX_FILE); } close(fd); + close(dirfd); } -void read_suffix_from_file_to_buf(char *buf, size_t buflen) { - ssize_t r = -1; + +void read_suffix_from_file_to_buf(char *buf, size_t buflen) { if (!buf || buflen == 0) return; - int fd = open(RRD_SUFFIX_PATH, O_RDONLY | O_NOFOLLOW | O_CLOEXEC); - if (fd == -1) - { + int dirfd = secure_open_rrd_dir(); + if (dirfd == -1) { buf[0] = '\0'; return; } + int fd = openat(dirfd, RRD_SUFFIX_FILE, O_RDONLY | O_NOFOLLOW | O_CLOEXEC); + if (fd == -1) { buf[0] = '\0'; + close(dirfd); return; } - - do - { - r = read(fd, buf, buflen - 1); - } while (r < 0 && errno == EINTR); - - if (r < 0) - { + struct stat st; + if (fstat(fd, &st) != 0 || !S_ISREG(st.st_mode)) { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] %s/%s is not a regular file!\n", __FUNCTION__, __LINE__, RRD_SUFFIX_DIR, RRD_SUFFIX_FILE); + close(fd); + close(dirfd); + buf[0] = '\0'; + return; + } + ssize_t r = read(fd, buf, buflen - 1); + if (r < 0) { buf[0] = '\0'; close(fd); + close(dirfd); return; } buf[r] = '\0'; close(fd); + close(dirfd); size_t len = strlen(buf); if (len > 0 && buf[len-1] == '\n') buf[len-1] = '\0'; } @@ -162,42 +180,22 @@ void read_suffix_from_file_to_buf(char *buf, size_t buflen) { * @return void */ void split_issue_type(const char *input, char *base, size_t base_len, char *suffix, size_t suffix_len) { - if (base && base_len > 0) - { - base[0] = '\0'; - } - if (suffix && suffix_len > 0) - { - suffix[0] = '\0'; - } - - if (!input || !base || !suffix) - { - return; - } - - if (base_len == 0 || suffix_len == 0) - { - return; - } - RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: split_issue_type called with input='%s'\n", __FUNCTION__, __LINE__, input); + if (!input || !base || !suffix) return; + RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: [INFO] split_issue_type called with input='%s'\n", __FUNCTION__, __LINE__, input); const char *underscore = strchr(input, '_'); - if (underscore) - { + if (underscore) { size_t b_len = underscore - input; if (b_len >= base_len) b_len = base_len - 1; strncpy(base, input, b_len); base[b_len] = '\0'; strncpy(suffix, underscore, suffix_len - 1); suffix[suffix_len - 1] = '\0'; - } - else - { + } else { strncpy(base, input, base_len - 1); base[base_len - 1] = '\0'; suffix[0] = '\0'; } - RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: split_issue_type result: base='%s', suffix='%s'\n", __FUNCTION__, __LINE__, base, suffix); + RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: [INFO] split_issue_type result: base='%s', suffix='%s'\n", __FUNCTION__, __LINE__, base, suffix); } @@ -361,6 +359,7 @@ void getIssueInfo(char *issuestr, issueNodeData *issue) RDK_LOG(RDK_LOG_INFO,LOG_REMDEBUG,"[%s:%d]: Received Main Node= %s, SubNode= %s\n",__FUNCTION__,__LINE__,issue->Node,issue->subNode); } + /* * @function findIssueInParsedJSON * @brief Finds if an issue category and issue type is present in the parsed JSON. @@ -671,7 +670,6 @@ void checkIssueNodeInfo(issueNodeData *issuestructNode, cJSON *jsoncfg, data_buf RDK_LOG(RDK_LOG_ERROR,LOG_REMDEBUG,"[%s:%d]: Memory allocation failed for rfcbuf\n",__FUNCTION__,__LINE__); free(buff->mdata); // free rfc data free(buff->jsonPath); // free rrd path info - persist_suffix_to_file(""); // Clear the suffix file on early exit return; } @@ -692,7 +690,6 @@ void checkIssueNodeInfo(issueNodeData *issuestructNode, cJSON *jsoncfg, data_buf free(rfcbuf); // free duplicated rfc data free(buff->mdata); // free rfc data free(buff->jsonPath); // free rrd path info - persist_suffix_to_file(""); // Clear the suffix file on early exit return; } else @@ -737,25 +734,19 @@ void checkIssueNodeInfo(issueNodeData *issuestructNode, cJSON *jsoncfg, data_buf char suffix[128] = {0}; read_suffix_from_file_to_buf(suffix, sizeof(suffix)); char tarName[512] = {0}; - int tar_name_len = 0; if (suffix[0] != '\0') { - tar_name_len = snprintf(tarName, sizeof(tarName), "%s%s", buff->mdata, suffix); - } - else - { - tar_name_len = snprintf(tarName, sizeof(tarName), "%s", buff->mdata); - } - if ((tar_name_len < 0) || ((size_t)tar_name_len >= sizeof(tarName))) - { - RDK_LOG(RDK_LOG_ERROR,LOG_REMDEBUG,"[%s:%d]: Failed to build upload file name for %s. snprintf result:%d, buffer size:%zu\n", __FUNCTION__,__LINE__,buff->mdata,tar_name_len,sizeof(tarName)); - status = -1; + snprintf(tarName, sizeof(tarName), "%s%s", buff->mdata, suffix); + } else { + snprintf(tarName, sizeof(tarName), "%s", buff->mdata); } - else - { - RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: [INFO] Tar file name for upload: '%s'\n", __FUNCTION__, __LINE__, tarName); - status = uploadDebugoutput(outdir, tarName); - } - + RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Tar file name for upload: '%s'\n", __FUNCTION__, __LINE__, tarName); + RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: [INFO] Tar file name for upload: '%s'\n", __FUNCTION__, __LINE__, tarName); + RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: [INFO] Directory for upload: '%s'\n", __FUNCTION__, __LINE__, outdir); + RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: [INFO] Original issue string: '%s'\n", __FUNCTION__, __LINE__, buff->mdata); + RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: [INFO] Suffix used for upload: '%s'\n", __FUNCTION__, __LINE__, suffix); + RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: [INFO] Tar file name for upload: '%s'\n", __FUNCTION__, __LINE__, tarName); + status = uploadDebugoutput(outdir, tarName); + persist_suffix_to_file(""); // Clear the suffix file after upload if(status != 0) { RDK_LOG(RDK_LOG_ERROR,LOG_REMDEBUG,"[%s:%d]: RRD Upload Script Execution Failed!!! status:%d\n",__FUNCTION__,__LINE__,status); @@ -768,7 +759,6 @@ void checkIssueNodeInfo(issueNodeData *issuestructNode, cJSON *jsoncfg, data_buf free(rfcbuf); // free duplicated rfc data free(buff->mdata); // free rfc data free(buff->jsonPath); // free rrd path info - persist_suffix_to_file(""); // Clear the suffix file after upload } else { @@ -776,7 +766,6 @@ void checkIssueNodeInfo(issueNodeData *issuestructNode, cJSON *jsoncfg, data_buf free(rfcbuf); // free duplicated rfc data free(buff->mdata); // free rfc data free(buff->jsonPath); // free rrd path info - persist_suffix_to_file(""); // Clear the suffix file } } } From 362f1ae45df926b286b66276976998cfe19884cb Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Mon, 4 May 2026 09:32:39 +0530 Subject: [PATCH 43/79] Update rrdJsonParser.c From 8bc8315744349881fffc086c2a38967cffe7156a Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Mon, 4 May 2026 09:34:32 +0530 Subject: [PATCH 44/79] Update rrdJsonParser.c --- src/rrdJsonParser.c | 213 +++++++++++++++++++++++--------------------- 1 file changed, 112 insertions(+), 101 deletions(-) diff --git a/src/rrdJsonParser.c b/src/rrdJsonParser.c index 96d7f1e5a..361038b06 100644 --- a/src/rrdJsonParser.c +++ b/src/rrdJsonParser.c @@ -24,6 +24,12 @@ #include #include #include +#include +#include +#include +#define RRD_SUFFIX_DIR "/tmp/rrd" +#define RRD_SUFFIX_PATH "/tmp/rrd/rrd_suffix.txt" + /* * @function removeSpecialChar @@ -46,123 +52,99 @@ void removeSpecialChar(char *str) } } - - -#include -#include -#include - - - -#define RRD_SUFFIX_DIR "/tmp/rrd" -#define RRD_SUFFIX_FILE "rrd_suffix.txt" - -#include -#include - -static int secure_open_rrd_dir(void) { - struct stat st; - if (lstat(RRD_SUFFIX_DIR, &st) == 0) { - if (!S_ISDIR(st.st_mode)) { - RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] %s exists but is not a directory!\n", __FUNCTION__, __LINE__, RRD_SUFFIX_DIR); - return -1; - } - // Optionally check ownership: must be root or current user - uid_t uid = geteuid(); - if (st.st_uid != 0 && st.st_uid != uid) { - RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] %s not owned by root or current user!\n", __FUNCTION__, __LINE__, RRD_SUFFIX_DIR); - return -1; - } - } else { - if (mkdir(RRD_SUFFIX_DIR, 0700) != 0 && errno != EEXIST) { - RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] Failed to create %s: %s\n", __FUNCTION__, __LINE__, RRD_SUFFIX_DIR, strerror(errno)); - return -1; - } - } - int dirfd = open(RRD_SUFFIX_DIR, O_DIRECTORY | O_NOFOLLOW | O_CLOEXEC); - if (dirfd == -1) { - RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] Failed to securely open %s: %s\n", __FUNCTION__, __LINE__, RRD_SUFFIX_DIR, strerror(errno)); - return -1; +void persist_suffix_to_file(const char *suffix) +{ + // Ensure directory exists + if (mkdir(RRD_SUFFIX_DIR, 0700) != 0 && errno != EEXIST) + { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] Failed to create %s: %s\n", __FUNCTION__, __LINE__, RRD_SUFFIX_DIR, strerror(errno)); + return; } - return dirfd; -} - -void persist_suffix_to_file(const char *suffix) { - int dirfd = secure_open_rrd_dir(); - if (dirfd == -1) return; - int fd = openat(dirfd, RRD_SUFFIX_FILE, O_WRONLY | O_CREAT | O_TRUNC | O_NOFOLLOW | O_CLOEXEC, 0600); + + int fd = open(RRD_SUFFIX_PATH, O_WRONLY | O_CREAT | O_TRUNC | O_NOFOLLOW | O_CLOEXEC, 0600); if (fd == -1) { - RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] Failed to openat %s/%s for writing: %s\n", __FUNCTION__, __LINE__, RRD_SUFFIX_DIR, RRD_SUFFIX_FILE, strerror(errno)); - close(dirfd); + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] Failed to open %s for writing: %s\n", __FUNCTION__, __LINE__, RRD_SUFFIX_PATH, strerror(errno)); return; } - struct stat st; - if (fstat(fd, &st) != 0 || !S_ISREG(st.st_mode)) { - RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] %s/%s is not a regular file!\n", __FUNCTION__, __LINE__, RRD_SUFFIX_DIR, RRD_SUFFIX_FILE); + + struct stat st; + if (fstat(fd, &st) != 0 || !S_ISREG(st.st_mode)) + { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] %s is not a regular file!\n", __FUNCTION__, __LINE__, RRD_SUFFIX_PATH); close(fd); - close(dirfd); return; } - if (suffix && suffix[0] != '\0') { + + if (suffix && suffix[0] != '\0') + { size_t suffix_len = strlen(suffix); size_t total_written = 0; - while (total_written < suffix_len) { + + while (total_written < suffix_len) + { ssize_t written = write(fd, suffix + total_written, suffix_len - total_written); - if (written < 0) { + if (written < 0) + { + if (errno == EINTR) + { + continue; + } RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] Failed to write suffix: %s\n", __FUNCTION__, __LINE__, strerror(errno)); break; } - if (written == 0) { - RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] Zero bytes written, aborting.\n", __FUNCTION__, __LINE__); + + if (written == 0) + { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] Short write while writing suffix to %s\n", __FUNCTION__, __LINE__, RRD_SUFFIX_PATH); break; } + total_written += (size_t)written; - if (total_written > suffix_len) { - RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] total_written overflow, aborting.\n", __FUNCTION__, __LINE__); - break; - } } - if (total_written == suffix_len) { - RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: [DEBUG] Suffix '%s' written to %s/%s\n", __FUNCTION__, __LINE__, suffix, RRD_SUFFIX_DIR, RRD_SUFFIX_FILE); + + if (total_written == suffix_len) + { + RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: [DEBUG] Suffix '%s' written to %s\n", __FUNCTION__, __LINE__, suffix, RRD_SUFFIX_PATH); + } + } + else + { + // Truncate file to empty + if (ftruncate(fd, 0) != 0) + { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] Failed to clear suffix in %s: %s\n", __FUNCTION__, __LINE__, RRD_SUFFIX_PATH, strerror(errno)); + } else + { + RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: [DEBUG] Suffix cleared in %s\n", __FUNCTION__, __LINE__, RRD_SUFFIX_PATH); } - } else { - ftruncate(fd, 0); - RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: [DEBUG] Suffix cleared in %s/%s\n", __FUNCTION__, __LINE__, RRD_SUFFIX_DIR, RRD_SUFFIX_FILE); } close(fd); - close(dirfd); } - - void read_suffix_from_file_to_buf(char *buf, size_t buflen) { + ssize_t r = -1; + if (!buf || buflen == 0) return; - int dirfd = secure_open_rrd_dir(); - if (dirfd == -1) { buf[0] = '\0'; return; } - int fd = openat(dirfd, RRD_SUFFIX_FILE, O_RDONLY | O_NOFOLLOW | O_CLOEXEC); - if (fd == -1) { - buf[0] = '\0'; - close(dirfd); - return; - } - struct stat st; - if (fstat(fd, &st) != 0 || !S_ISREG(st.st_mode)) { - RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] %s/%s is not a regular file!\n", __FUNCTION__, __LINE__, RRD_SUFFIX_DIR, RRD_SUFFIX_FILE); - close(fd); - close(dirfd); + int fd = open(RRD_SUFFIX_PATH, O_RDONLY | O_NOFOLLOW | O_CLOEXEC); + if (fd == -1) + { buf[0] = '\0'; return; } - ssize_t r = read(fd, buf, buflen - 1); - if (r < 0) { + + do + { + r = read(fd, buf, buflen - 1); + } while (r < 0 && errno == EINTR); + + if (r < 0) + { buf[0] = '\0'; close(fd); - close(dirfd); return; } buf[r] = '\0'; close(fd); - close(dirfd); size_t len = strlen(buf); if (len > 0 && buf[len-1] == '\n') buf[len-1] = '\0'; } @@ -180,22 +162,42 @@ void read_suffix_from_file_to_buf(char *buf, size_t buflen) { * @return void */ void split_issue_type(const char *input, char *base, size_t base_len, char *suffix, size_t suffix_len) { - if (!input || !base || !suffix) return; - RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: [INFO] split_issue_type called with input='%s'\n", __FUNCTION__, __LINE__, input); + if (base && base_len > 0) + { + base[0] = '\0'; + } + if (suffix && suffix_len > 0) + { + suffix[0] = '\0'; + } + + if (!input || !base || !suffix) + { + return; + } + + if (base_len == 0 || suffix_len == 0) + { + return; + } + RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: split_issue_type called with input='%s'\n", __FUNCTION__, __LINE__, input); const char *underscore = strchr(input, '_'); - if (underscore) { + if (underscore) + { size_t b_len = underscore - input; if (b_len >= base_len) b_len = base_len - 1; strncpy(base, input, b_len); base[b_len] = '\0'; strncpy(suffix, underscore, suffix_len - 1); suffix[suffix_len - 1] = '\0'; - } else { + } + else + { strncpy(base, input, base_len - 1); base[base_len - 1] = '\0'; suffix[0] = '\0'; } - RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: [INFO] split_issue_type result: base='%s', suffix='%s'\n", __FUNCTION__, __LINE__, base, suffix); + RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: split_issue_type result: base='%s', suffix='%s'\n", __FUNCTION__, __LINE__, base, suffix); } @@ -359,7 +361,6 @@ void getIssueInfo(char *issuestr, issueNodeData *issue) RDK_LOG(RDK_LOG_INFO,LOG_REMDEBUG,"[%s:%d]: Received Main Node= %s, SubNode= %s\n",__FUNCTION__,__LINE__,issue->Node,issue->subNode); } - /* * @function findIssueInParsedJSON * @brief Finds if an issue category and issue type is present in the parsed JSON. @@ -670,6 +671,7 @@ void checkIssueNodeInfo(issueNodeData *issuestructNode, cJSON *jsoncfg, data_buf RDK_LOG(RDK_LOG_ERROR,LOG_REMDEBUG,"[%s:%d]: Memory allocation failed for rfcbuf\n",__FUNCTION__,__LINE__); free(buff->mdata); // free rfc data free(buff->jsonPath); // free rrd path info + persist_suffix_to_file(""); // Clear the suffix file on early exit return; } @@ -690,6 +692,7 @@ void checkIssueNodeInfo(issueNodeData *issuestructNode, cJSON *jsoncfg, data_buf free(rfcbuf); // free duplicated rfc data free(buff->mdata); // free rfc data free(buff->jsonPath); // free rrd path info + persist_suffix_to_file(""); // Clear the suffix file on early exit return; } else @@ -734,19 +737,25 @@ void checkIssueNodeInfo(issueNodeData *issuestructNode, cJSON *jsoncfg, data_buf char suffix[128] = {0}; read_suffix_from_file_to_buf(suffix, sizeof(suffix)); char tarName[512] = {0}; + int tar_name_len = 0; if (suffix[0] != '\0') { - snprintf(tarName, sizeof(tarName), "%s%s", buff->mdata, suffix); - } else { - snprintf(tarName, sizeof(tarName), "%s", buff->mdata); + tar_name_len = snprintf(tarName, sizeof(tarName), "%s%s", buff->mdata, suffix); + } + else + { + tar_name_len = snprintf(tarName, sizeof(tarName), "%s", buff->mdata); + } + if ((tar_name_len < 0) || ((size_t)tar_name_len >= sizeof(tarName))) + { + RDK_LOG(RDK_LOG_ERROR,LOG_REMDEBUG,"[%s:%d]: Failed to build upload file name for %s. snprintf result:%d, buffer size:%zu\n", __FUNCTION__,__LINE__,buff->mdata,tar_name_len,sizeof(tarName)); + status = -1; } - RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Tar file name for upload: '%s'\n", __FUNCTION__, __LINE__, tarName); - RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: [INFO] Tar file name for upload: '%s'\n", __FUNCTION__, __LINE__, tarName); - RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: [INFO] Directory for upload: '%s'\n", __FUNCTION__, __LINE__, outdir); - RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: [INFO] Original issue string: '%s'\n", __FUNCTION__, __LINE__, buff->mdata); - RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: [INFO] Suffix used for upload: '%s'\n", __FUNCTION__, __LINE__, suffix); - RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: [INFO] Tar file name for upload: '%s'\n", __FUNCTION__, __LINE__, tarName); - status = uploadDebugoutput(outdir, tarName); - persist_suffix_to_file(""); // Clear the suffix file after upload + else + { + RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: [INFO] Tar file name for upload: '%s'\n", __FUNCTION__, __LINE__, tarName); + status = uploadDebugoutput(outdir, tarName); + } + if(status != 0) { RDK_LOG(RDK_LOG_ERROR,LOG_REMDEBUG,"[%s:%d]: RRD Upload Script Execution Failed!!! status:%d\n",__FUNCTION__,__LINE__,status); @@ -759,6 +768,7 @@ void checkIssueNodeInfo(issueNodeData *issuestructNode, cJSON *jsoncfg, data_buf free(rfcbuf); // free duplicated rfc data free(buff->mdata); // free rfc data free(buff->jsonPath); // free rrd path info + persist_suffix_to_file(""); // Clear the suffix file after upload } else { @@ -766,6 +776,7 @@ void checkIssueNodeInfo(issueNodeData *issuestructNode, cJSON *jsoncfg, data_buf free(rfcbuf); // free duplicated rfc data free(buff->mdata); // free rfc data free(buff->jsonPath); // free rrd path info + persist_suffix_to_file(""); // Clear the suffix file } } } From 9887ec7cf53eacca6e0076c31930f48587609bfd Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Mon, 4 May 2026 09:52:22 +0530 Subject: [PATCH 45/79] Update rrdJsonParser.c --- src/rrdJsonParser.c | 92 ++++++--------------------------------------- 1 file changed, 11 insertions(+), 81 deletions(-) diff --git a/src/rrdJsonParser.c b/src/rrdJsonParser.c index 361038b06..47cdc6a0c 100644 --- a/src/rrdJsonParser.c +++ b/src/rrdJsonParser.c @@ -52,99 +52,29 @@ void removeSpecialChar(char *str) } } -void persist_suffix_to_file(const char *suffix) -{ - // Ensure directory exists - if (mkdir(RRD_SUFFIX_DIR, 0700) != 0 && errno != EEXIST) - { - RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] Failed to create %s: %s\n", __FUNCTION__, __LINE__, RRD_SUFFIX_DIR, strerror(errno)); - return; - } - - int fd = open(RRD_SUFFIX_PATH, O_WRONLY | O_CREAT | O_TRUNC | O_NOFOLLOW | O_CLOEXEC, 0600); - if (fd == -1) { - RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] Failed to open %s for writing: %s\n", __FUNCTION__, __LINE__, RRD_SUFFIX_PATH, strerror(errno)); - return; - } - - struct stat st; - if (fstat(fd, &st) != 0 || !S_ISREG(st.st_mode)) - { - RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] %s is not a regular file!\n", __FUNCTION__, __LINE__, RRD_SUFFIX_PATH); - close(fd); - return; - } - - if (suffix && suffix[0] != '\0') - { - size_t suffix_len = strlen(suffix); - size_t total_written = 0; - - while (total_written < suffix_len) - { - ssize_t written = write(fd, suffix + total_written, suffix_len - total_written); - if (written < 0) - { - if (errno == EINTR) - { - continue; - } - RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] Failed to write suffix: %s\n", __FUNCTION__, __LINE__, strerror(errno)); - break; - } - - if (written == 0) - { - RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] Short write while writing suffix to %s\n", __FUNCTION__, __LINE__, RRD_SUFFIX_PATH); - break; - } - - total_written += (size_t)written; - } - - if (total_written == suffix_len) - { - RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: [DEBUG] Suffix '%s' written to %s\n", __FUNCTION__, __LINE__, suffix, RRD_SUFFIX_PATH); - } - } - else - { - // Truncate file to empty - if (ftruncate(fd, 0) != 0) - { - RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] Failed to clear suffix in %s: %s\n", __FUNCTION__, __LINE__, RRD_SUFFIX_PATH, strerror(errno)); - } else - { - RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: [DEBUG] Suffix cleared in %s\n", __FUNCTION__, __LINE__, RRD_SUFFIX_PATH); +void persist_suffix_to_file(const char *suffix) { + FILE *fp = fopen("/tmp/rrd_suffix.txt", "w"); + if (fp) { + if (suffix) { + fputs(suffix, fp); } + fclose(fp); } - close(fd); } void read_suffix_from_file_to_buf(char *buf, size_t buflen) { - ssize_t r = -1; - if (!buf || buflen == 0) return; - int fd = open(RRD_SUFFIX_PATH, O_RDONLY | O_NOFOLLOW | O_CLOEXEC); - if (fd == -1) - { + FILE *fp = fopen("/tmp/rrd_suffix.txt", "r"); + if (!fp) { buf[0] = '\0'; return; } - - do - { - r = read(fd, buf, buflen - 1); - } while (r < 0 && errno == EINTR); - - if (r < 0) - { + if (fgets(buf, buflen, fp) == NULL) { buf[0] = '\0'; - close(fd); + fclose(fp); return; } - buf[r] = '\0'; - close(fd); + fclose(fp); size_t len = strlen(buf); if (len > 0 && buf[len-1] == '\n') buf[len-1] = '\0'; } From 1afb92b5e23895a8a7ffcad561e4a5089746ecc0 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Mon, 4 May 2026 09:53:45 +0530 Subject: [PATCH 46/79] Update rrdJsonParser.c --- src/rrdJsonParser.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rrdJsonParser.c b/src/rrdJsonParser.c index 47cdc6a0c..9648f72bd 100644 --- a/src/rrdJsonParser.c +++ b/src/rrdJsonParser.c @@ -53,7 +53,7 @@ void removeSpecialChar(char *str) } void persist_suffix_to_file(const char *suffix) { - FILE *fp = fopen("/tmp/rrd_suffix.txt", "w"); + FILE *fp = fopen(RRD_SUFFIX_PATH, "w"); if (fp) { if (suffix) { fputs(suffix, fp); @@ -64,7 +64,7 @@ void persist_suffix_to_file(const char *suffix) { void read_suffix_from_file_to_buf(char *buf, size_t buflen) { if (!buf || buflen == 0) return; - FILE *fp = fopen("/tmp/rrd_suffix.txt", "r"); + FILE *fp = fopen(RRD_SUFFIX_PATH, "r"); if (!fp) { buf[0] = '\0'; return; From 33a0011232a7dd997d5f1d91f9b69ef11a0edf26 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Mon, 4 May 2026 10:11:02 +0530 Subject: [PATCH 47/79] Update rrdUnitTestRunner.cpp --- src/unittest/rrdUnitTestRunner.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/unittest/rrdUnitTestRunner.cpp b/src/unittest/rrdUnitTestRunner.cpp index bbbe8a773..be8cad007 100644 --- a/src/unittest/rrdUnitTestRunner.cpp +++ b/src/unittest/rrdUnitTestRunner.cpp @@ -5823,7 +5823,7 @@ class SuffixUtilsTest : public ::testing::Test { protected: void TearDown() override { // Remove suffix temp file to avoid state leakage between tests - remove("/tmp/rrd_suffix.txt"); + remove("/tmp/rrd/rrd_suffix.txt"); } }; @@ -5924,7 +5924,7 @@ TEST_F(SuffixUtilsTest, PersistSuffix_NormalValue) { persist_suffix_to_file("_Search123"); // Verify the file was written - FILE *fp = fopen("/tmp/rrd_suffix.txt", "r"); + FILE *fp = fopen("/tmp/rrd/rrd_suffix.txt", "r"); ASSERT_NE(fp, nullptr); char buf[64] = {0}; ASSERT_NE(fgets(buf, sizeof(buf), fp), nullptr); @@ -5935,7 +5935,7 @@ TEST_F(SuffixUtilsTest, PersistSuffix_NormalValue) TEST_F(SuffixUtilsTest, PersistSuffix_EmptyString) { persist_suffix_to_file(""); - FILE *fp = fopen("/tmp/rrd_suffix.txt", "r"); + FILE *fp = fopen("/tmp/rrd/rrd_suffix.txt", "r"); ASSERT_NE(fp, nullptr); char buf[64] = {0}; // fgets may return NULL for an empty file - that's fine, buf stays empty @@ -5948,7 +5948,7 @@ TEST_F(SuffixUtilsTest, PersistSuffix_NullDoesNotCrash) { // Passing NULL should not crash; file should be created but empty persist_suffix_to_file(NULL); - FILE *fp = fopen("/tmp/rrd_suffix.txt", "r"); + FILE *fp = fopen("/tmp/rrd/rrd_suffix.txt", "r"); ASSERT_NE(fp, nullptr); char buf[64] = {0}; fgets(buf, sizeof(buf), fp); @@ -5977,7 +5977,7 @@ TEST_F(SuffixUtilsTest, ReadSuffix_AfterPersist) TEST_F(SuffixUtilsTest, ReadSuffix_WhenFileAbsent) { - remove("/tmp/rrd_suffix.txt"); + remove("/tmp/rrd/rrd_suffix.txt"); char buf[64] = {0}; read_suffix_from_file_to_buf(buf, sizeof(buf)); EXPECT_STREQ(buf, ""); @@ -6010,7 +6010,7 @@ TEST_F(SuffixUtilsTest, ReadSuffix_RoundTrip) TEST_F(SuffixUtilsTest, ReadSuffix_StripsTrailingNewline) { // Write a value with a trailing newline to the file - FILE *fp = fopen("/tmp/rrd_suffix.txt", "w"); + FILE *fp = fopen("/tmp/rrd/rrd_suffix.txt", "w"); ASSERT_NE(fp, nullptr); fputs("_suffix\n", fp); fclose(fp); From 0fa6173b4b8f86edb26a59ed5537e456706e8266 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Mon, 4 May 2026 10:18:23 +0530 Subject: [PATCH 48/79] Update rrdJsonParser.c --- src/rrdJsonParser.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/rrdJsonParser.c b/src/rrdJsonParser.c index 9648f72bd..994818900 100644 --- a/src/rrdJsonParser.c +++ b/src/rrdJsonParser.c @@ -24,9 +24,6 @@ #include #include #include -#include -#include -#include #define RRD_SUFFIX_DIR "/tmp/rrd" #define RRD_SUFFIX_PATH "/tmp/rrd/rrd_suffix.txt" From 23b7ad35720ccdb5f04d3b5129e031d3e2b69d5e Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Mon, 4 May 2026 10:31:04 +0530 Subject: [PATCH 49/79] Update rrdJsonParser.c --- src/rrdJsonParser.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/rrdJsonParser.c b/src/rrdJsonParser.c index 994818900..e23529528 100644 --- a/src/rrdJsonParser.c +++ b/src/rrdJsonParser.c @@ -49,14 +49,31 @@ void removeSpecialChar(char *str) } } -void persist_suffix_to_file(const char *suffix) { - FILE *fp = fopen(RRD_SUFFIX_PATH, "w"); - if (fp) { - if (suffix) { - fputs(suffix, fp); +int persist_suffix_to_file(const char *suffix) { + struct stat st; + if (lstat(RRD_SUFFIX_DIR, &st) == 0) { + if (!S_ISDIR(st.st_mode)) { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] %s exists but is not a directory!\n", __FUNCTION__, __LINE__, RRD_SUFFIX_DIR); + return -1; + } + } else { + if (mkdir(RRD_SUFFIX_DIR, 0700) != 0 && errno != EEXIST) { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] Failed to create %s: %s\n", __FUNCTION__, __LINE__, RRD_SUFFIX_DIR, strerror(errno)); + return -1; } + } + FILE *fp = fopen(RRD_SUFFIX_PATH, "w"); + if (!fp) { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] Failed to open %s for writing: %s\n", __FUNCTION__, __LINE__, RRD_SUFFIX_PATH, strerror(errno)); + return -1; + } + if (suffix && fputs(suffix, fp) < 0) { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] Failed to write suffix to %s: %s\n", __FUNCTION__, __LINE__, RRD_SUFFIX_PATH, strerror(errno)); fclose(fp); + return -1; } + fclose(fp); + return 0; } void read_suffix_from_file_to_buf(char *buf, size_t buflen) { From 23f2c670dc6cd7aaa45e4a32ada20837f6638d44 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Mon, 4 May 2026 10:32:27 +0530 Subject: [PATCH 50/79] Delete .gitignore --- .gitignore | 45 --------------------------------------------- 1 file changed, 45 deletions(-) delete mode 100644 .gitignore diff --git a/.gitignore b/.gitignore deleted file mode 100644 index dc7427fdd..000000000 --- a/.gitignore +++ /dev/null @@ -1,45 +0,0 @@ -# Build artifacts -*.o -*.gcda -*.gcno -*.Po -*.a -*.so -*.la -*.lo - -# Autotools generated files -Makefile -Makefile.in -aclocal.m4 -autom4te.cache/ -config.guess -config.log -config.status -config.sub -configure -compile -depcomp -install-sh -missing -COPYING -INSTALL -libtool -ltmain.sh -stamp-h1 -.deps/ -.libs/ - -# Test binaries and outputs -src/unittest/remotedebugger_gtest -src/unittest/dummy_*/ - -# Coverage files -*.gcda -*.gcno - -# Temporary files -/tmp/ - -# Test-generated device properties -src/unittest/UTJson/device.properties From c7b743a6c6c9313fecf8aec490efc5e398e69813 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Mon, 4 May 2026 10:35:49 +0530 Subject: [PATCH 51/79] Update rrdJsonParser.c --- src/rrdJsonParser.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/src/rrdJsonParser.c b/src/rrdJsonParser.c index e23529528..d2c167d63 100644 --- a/src/rrdJsonParser.c +++ b/src/rrdJsonParser.c @@ -51,23 +51,30 @@ void removeSpecialChar(char *str) int persist_suffix_to_file(const char *suffix) { struct stat st; - if (lstat(RRD_SUFFIX_DIR, &st) == 0) { - if (!S_ISDIR(st.st_mode)) { + if (lstat(RRD_SUFFIX_DIR, &st) == 0) + { + if (!S_ISDIR(st.st_mode)) + { RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] %s exists but is not a directory!\n", __FUNCTION__, __LINE__, RRD_SUFFIX_DIR); return -1; } - } else { - if (mkdir(RRD_SUFFIX_DIR, 0700) != 0 && errno != EEXIST) { + } + else + { + if (mkdir(RRD_SUFFIX_DIR, 0700) != 0 && errno != EEXIST) + { RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] Failed to create %s: %s\n", __FUNCTION__, __LINE__, RRD_SUFFIX_DIR, strerror(errno)); return -1; } } FILE *fp = fopen(RRD_SUFFIX_PATH, "w"); - if (!fp) { + if (!fp) + { RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] Failed to open %s for writing: %s\n", __FUNCTION__, __LINE__, RRD_SUFFIX_PATH, strerror(errno)); return -1; } - if (suffix && fputs(suffix, fp) < 0) { + if (suffix && fputs(suffix, fp) < 0) + { RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] Failed to write suffix to %s: %s\n", __FUNCTION__, __LINE__, RRD_SUFFIX_PATH, strerror(errno)); fclose(fp); return -1; @@ -76,14 +83,17 @@ int persist_suffix_to_file(const char *suffix) { return 0; } -void read_suffix_from_file_to_buf(char *buf, size_t buflen) { +void read_suffix_from_file_to_buf(char *buf, size_t buflen) +{ if (!buf || buflen == 0) return; FILE *fp = fopen(RRD_SUFFIX_PATH, "r"); - if (!fp) { + if (!fp) + { buf[0] = '\0'; return; } - if (fgets(buf, buflen, fp) == NULL) { + if (fgets(buf, buflen, fp) == NULL) + { buf[0] = '\0'; fclose(fp); return; From e30155e3360342b3ef533ca2144f35f06c60873c Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Mon, 4 May 2026 10:49:08 +0530 Subject: [PATCH 52/79] Update rrdJsonParser.c --- src/rrdJsonParser.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/rrdJsonParser.c b/src/rrdJsonParser.c index d2c167d63..91793d0f1 100644 --- a/src/rrdJsonParser.c +++ b/src/rrdJsonParser.c @@ -24,6 +24,7 @@ #include #include #include +#include #define RRD_SUFFIX_DIR "/tmp/rrd" #define RRD_SUFFIX_PATH "/tmp/rrd/rrd_suffix.txt" From d3c7fe9782774510c8196c6f6970d1fa4b9110f3 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Mon, 4 May 2026 11:30:45 +0530 Subject: [PATCH 53/79] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- src/rrdJsonParser.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rrdJsonParser.h b/src/rrdJsonParser.h index 7b63f5375..8ca7bd261 100644 --- a/src/rrdJsonParser.h +++ b/src/rrdJsonParser.h @@ -48,7 +48,7 @@ bool processAllDebugCommand(cJSON *jsoncfg, issueNodeData *issuestructNode, char bool processAllDeepSleepAwkMetricsCommands(cJSON *jsoncfg, issueNodeData *issuestructNode, char *rfcbuf); -void persist_suffix_to_file(const char *suffix); +int persist_suffix_to_file(const char *suffix); void read_suffix_from_file_to_buf(char *buf, size_t buflen); void split_issue_type(const char *input, char *base, size_t base_len, char *suffix, size_t suffix_len); From 441b8e82d130d54df74638801fdd7be865074f0b Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Mon, 4 May 2026 14:00:21 +0530 Subject: [PATCH 54/79] Update rrdJsonParser.c --- src/rrdJsonParser.c | 34 +++++----------------------------- 1 file changed, 5 insertions(+), 29 deletions(-) diff --git a/src/rrdJsonParser.c b/src/rrdJsonParser.c index 91793d0f1..7363ead74 100644 --- a/src/rrdJsonParser.c +++ b/src/rrdJsonParser.c @@ -50,38 +50,14 @@ void removeSpecialChar(char *str) } } -int persist_suffix_to_file(const char *suffix) { - struct stat st; - if (lstat(RRD_SUFFIX_DIR, &st) == 0) - { - if (!S_ISDIR(st.st_mode)) - { - RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] %s exists but is not a directory!\n", __FUNCTION__, __LINE__, RRD_SUFFIX_DIR); - return -1; - } - } - else - { - if (mkdir(RRD_SUFFIX_DIR, 0700) != 0 && errno != EEXIST) - { - RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] Failed to create %s: %s\n", __FUNCTION__, __LINE__, RRD_SUFFIX_DIR, strerror(errno)); - return -1; +void persist_suffix_to_file(const char *suffix) { + FILE *fp = fopen("/tmp/rrd_suffix.txt", "w"); + if (fp) { + if (suffix) { + fputs(suffix, fp); } - } - FILE *fp = fopen(RRD_SUFFIX_PATH, "w"); - if (!fp) - { - RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] Failed to open %s for writing: %s\n", __FUNCTION__, __LINE__, RRD_SUFFIX_PATH, strerror(errno)); - return -1; - } - if (suffix && fputs(suffix, fp) < 0) - { - RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] Failed to write suffix to %s: %s\n", __FUNCTION__, __LINE__, RRD_SUFFIX_PATH, strerror(errno)); fclose(fp); - return -1; } - fclose(fp); - return 0; } void read_suffix_from_file_to_buf(char *buf, size_t buflen) From cfb9158628b8d4294440d63b7d562e2c1efff5fe Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Mon, 4 May 2026 14:01:24 +0530 Subject: [PATCH 55/79] Replace hardcoded file path with constant --- src/rrdJsonParser.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rrdJsonParser.c b/src/rrdJsonParser.c index 7363ead74..f8c682f0c 100644 --- a/src/rrdJsonParser.c +++ b/src/rrdJsonParser.c @@ -51,7 +51,7 @@ void removeSpecialChar(char *str) } void persist_suffix_to_file(const char *suffix) { - FILE *fp = fopen("/tmp/rrd_suffix.txt", "w"); + FILE *fp = fopen(RRD_SUFFIX_PATH, "w"); if (fp) { if (suffix) { fputs(suffix, fp); From 0dc234863cd078f15cb204a7c0f3575c0377e5cb Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Mon, 4 May 2026 14:02:18 +0530 Subject: [PATCH 56/79] Update rrdJsonParser.h --- src/rrdJsonParser.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rrdJsonParser.h b/src/rrdJsonParser.h index 8ca7bd261..7b63f5375 100644 --- a/src/rrdJsonParser.h +++ b/src/rrdJsonParser.h @@ -48,7 +48,7 @@ bool processAllDebugCommand(cJSON *jsoncfg, issueNodeData *issuestructNode, char bool processAllDeepSleepAwkMetricsCommands(cJSON *jsoncfg, issueNodeData *issuestructNode, char *rfcbuf); -int persist_suffix_to_file(const char *suffix); +void persist_suffix_to_file(const char *suffix); void read_suffix_from_file_to_buf(char *buf, size_t buflen); void split_issue_type(const char *input, char *base, size_t base_len, char *suffix, size_t suffix_len); From 833c2e74eb6ea184e8e40bf0926d07f90c4730e5 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Mon, 4 May 2026 14:09:21 +0530 Subject: [PATCH 57/79] Update rrdJsonParser.c --- src/rrdJsonParser.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/rrdJsonParser.c b/src/rrdJsonParser.c index f8c682f0c..581492fa0 100644 --- a/src/rrdJsonParser.c +++ b/src/rrdJsonParser.c @@ -50,8 +50,8 @@ void removeSpecialChar(char *str) } } -void persist_suffix_to_file(const char *suffix) { - FILE *fp = fopen(RRD_SUFFIX_PATH, "w"); +void persist_suffix_to_file(const char *filename, const char *suffix) { + FILE *fp = fopen(filename, "w"); if (fp) { if (suffix) { fputs(suffix, fp); @@ -60,17 +60,17 @@ void persist_suffix_to_file(const char *suffix) { } } -void read_suffix_from_file_to_buf(char *buf, size_t buflen) +void read_suffix_from_file_to_buf(const char *filename, char *buf, size_t buflen) { - if (!buf || buflen == 0) return; - FILE *fp = fopen(RRD_SUFFIX_PATH, "r"); + if (!buf || buflen == 0 || !filename) return; + FILE *fp = fopen(filename, "r"); if (!fp) - { + { buf[0] = '\0'; return; } if (fgets(buf, buflen, fp) == NULL) - { + { buf[0] = '\0'; fclose(fp); return; @@ -602,7 +602,7 @@ void checkIssueNodeInfo(issueNodeData *issuestructNode, cJSON *jsoncfg, data_buf RDK_LOG(RDK_LOG_ERROR,LOG_REMDEBUG,"[%s:%d]: Memory allocation failed for rfcbuf\n",__FUNCTION__,__LINE__); free(buff->mdata); // free rfc data free(buff->jsonPath); // free rrd path info - persist_suffix_to_file(""); // Clear the suffix file on early exit + persist_suffix_to_file(RRD_SUFFIX_PATH,""); // Clear the suffix file on early exit return; } @@ -623,7 +623,7 @@ void checkIssueNodeInfo(issueNodeData *issuestructNode, cJSON *jsoncfg, data_buf free(rfcbuf); // free duplicated rfc data free(buff->mdata); // free rfc data free(buff->jsonPath); // free rrd path info - persist_suffix_to_file(""); // Clear the suffix file on early exit + persist_suffix_to_file(RRD_SUFFIX_PATH,""); // Clear the suffix file on early exit return; } else @@ -666,7 +666,7 @@ void checkIssueNodeInfo(issueNodeData *issuestructNode, cJSON *jsoncfg, data_buf RDK_LOG(RDK_LOG_DEBUG,LOG_REMDEBUG,"[%s:%d]: Continue uploading Debug Report for %s from %s... \n",__FUNCTION__,__LINE__,buff->mdata,outdir); // Use the persisted suffix from file for upload char suffix[128] = {0}; - read_suffix_from_file_to_buf(suffix, sizeof(suffix)); + read_suffix_from_file_to_buf(RRD_SUFFIX_PATH , suffix, sizeof(suffix)); char tarName[512] = {0}; int tar_name_len = 0; if (suffix[0] != '\0') { @@ -699,7 +699,7 @@ void checkIssueNodeInfo(issueNodeData *issuestructNode, cJSON *jsoncfg, data_buf free(rfcbuf); // free duplicated rfc data free(buff->mdata); // free rfc data free(buff->jsonPath); // free rrd path info - persist_suffix_to_file(""); // Clear the suffix file after upload + persist_suffix_to_file(RRD_SUFFIX_PATH,""); // Clear the suffix file after upload } else { @@ -707,7 +707,7 @@ void checkIssueNodeInfo(issueNodeData *issuestructNode, cJSON *jsoncfg, data_buf free(rfcbuf); // free duplicated rfc data free(buff->mdata); // free rfc data free(buff->jsonPath); // free rrd path info - persist_suffix_to_file(""); // Clear the suffix file + persist_suffix_to_file(RRD_SUFFIX_PATH,""); // Clear the suffix file } } } From af163dc641268e956780d2859b61f82b3114960d Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Mon, 4 May 2026 14:10:35 +0530 Subject: [PATCH 58/79] Update read_suffix_from_file_to_buf function signature --- src/rrdJsonParser.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rrdJsonParser.h b/src/rrdJsonParser.h index 7b63f5375..82bbcd988 100644 --- a/src/rrdJsonParser.h +++ b/src/rrdJsonParser.h @@ -49,7 +49,7 @@ bool processAllDeepSleepAwkMetricsCommands(cJSON *jsoncfg, issueNodeData *issues void persist_suffix_to_file(const char *suffix); -void read_suffix_from_file_to_buf(char *buf, size_t buflen); +void read_suffix_from_file_to_buf(const char *filename, char *buf, size_t buflen); void split_issue_type(const char *input, char *base, size_t base_len, char *suffix, size_t suffix_len); #ifdef __cplusplus From d52de13c1fcd9f1b423cb7608785755c0f794c6d Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Mon, 4 May 2026 14:17:03 +0530 Subject: [PATCH 59/79] Update rrdJsonParser.h --- src/rrdJsonParser.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rrdJsonParser.h b/src/rrdJsonParser.h index 82bbcd988..d9d693159 100644 --- a/src/rrdJsonParser.h +++ b/src/rrdJsonParser.h @@ -48,7 +48,7 @@ bool processAllDebugCommand(cJSON *jsoncfg, issueNodeData *issuestructNode, char bool processAllDeepSleepAwkMetricsCommands(cJSON *jsoncfg, issueNodeData *issuestructNode, char *rfcbuf); -void persist_suffix_to_file(const char *suffix); +void persist_suffix_to_file(const char *filename, const char *suffix); void read_suffix_from_file_to_buf(const char *filename, char *buf, size_t buflen); void split_issue_type(const char *input, char *base, size_t base_len, char *suffix, size_t suffix_len); From 748c70118b8d545c29cce1f20e3a82a6d588d2f6 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Mon, 4 May 2026 14:18:44 +0530 Subject: [PATCH 60/79] Update rrdEventProcess.c --- src/rrdEventProcess.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rrdEventProcess.c b/src/rrdEventProcess.c index 90520f9c0..b1594f63f 100644 --- a/src/rrdEventProcess.c +++ b/src/rrdEventProcess.c @@ -99,7 +99,7 @@ void processIssueTypeEvent(data_buf *rbuf) if (strchr(cmdMap[index], '_') && local_suffix[0] != '\0') { RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: [DEBUG] Persisting suffix: '%s' from input: '%s' (index=%d)\n", __FUNCTION__, __LINE__, local_suffix, cmdMap[index], index); - persist_suffix_to_file(local_suffix); + persist_suffix_to_file(RRD_SUFFIX_PATH,local_suffix); } else { From 774137b1b61a037938c97c992d3231cb95e69f75 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Mon, 4 May 2026 14:23:08 +0530 Subject: [PATCH 61/79] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- src/rrdEventProcess.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/rrdEventProcess.c b/src/rrdEventProcess.c index b1594f63f..e704076e8 100644 --- a/src/rrdEventProcess.c +++ b/src/rrdEventProcess.c @@ -82,6 +82,13 @@ void processIssueTypeEvent(data_buf *rbuf) char base[BUF_LEN_128] = {0}; char local_suffix[BUF_LEN_128] = {0}; split_issue_type(cmdMap[index], base, sizeof(base), local_suffix, sizeof(local_suffix)); + if (base[0] == '\0') + { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: Invalid IssueType [%s] - empty base after split, skipping\n", __FUNCTION__, __LINE__, cmdMap[index]); + free(cmdBuff); + cmdBuff = NULL; + continue; + } dataMsgLen = strlen(base) + 1; RRD_data_buff_init(cmdBuff, EVENT_MSG, RRD_DEEPSLEEP_INVALID_DEFAULT); /* Setting Deafult Values*/ cmdBuff->inDynamic = rbuf->inDynamic; From 1dc5b48f7835d792b46eb639e8947576dadfa4fc Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Mon, 4 May 2026 14:25:40 +0530 Subject: [PATCH 62/79] Update rrdCommon.h --- src/rrdCommon.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/rrdCommon.h b/src/rrdCommon.h index b91ff6f7b..06adb245e 100644 --- a/src/rrdCommon.h +++ b/src/rrdCommon.h @@ -67,6 +67,7 @@ extern "C" #define BUF_LEN_128 128 #define APPEND_SUFFIX "_apnd" +#define RRD_SUFFIX_PATH "/tmp/rrd/rrd_suffix.txt" /* Enum for Messages Queue*/ typedef enum { From 47ee21474efc932a5e4bb544c1d52f2f68bc0c5d Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Mon, 4 May 2026 14:26:06 +0530 Subject: [PATCH 63/79] Update rrdJsonParser.c --- src/rrdJsonParser.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rrdJsonParser.c b/src/rrdJsonParser.c index 581492fa0..1b2b2d2c7 100644 --- a/src/rrdJsonParser.c +++ b/src/rrdJsonParser.c @@ -25,8 +25,8 @@ #include #include #include -#define RRD_SUFFIX_DIR "/tmp/rrd" -#define RRD_SUFFIX_PATH "/tmp/rrd/rrd_suffix.txt" +//#define RRD_SUFFIX_DIR "/tmp/rrd" +//#define RRD_SUFFIX_PATH "/tmp/rrd/rrd_suffix.txt" /* From f7021776d08feec934a376332754218f571df48f Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Mon, 4 May 2026 14:50:28 +0530 Subject: [PATCH 64/79] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- src/rrdJsonParser.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/rrdJsonParser.c b/src/rrdJsonParser.c index 1b2b2d2c7..69ea92dfe 100644 --- a/src/rrdJsonParser.c +++ b/src/rrdJsonParser.c @@ -51,13 +51,26 @@ void removeSpecialChar(char *str) } void persist_suffix_to_file(const char *filename, const char *suffix) { + if (!filename) { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: persist_suffix_to_file called with NULL filename\n", __FUNCTION__, __LINE__); + return; + } + FILE *fp = fopen(filename, "w"); - if (fp) { - if (suffix) { - fputs(suffix, fp); + if (!fp) { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: failed to open file '%s' for writing: %s\n", + __FUNCTION__, __LINE__, filename, strerror(errno)); + return; + } + + if (suffix) { + if (fputs(suffix, fp) == EOF) { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: failed to write suffix to file '%s': %s\n", + __FUNCTION__, __LINE__, filename, strerror(errno)); } - fclose(fp); } + + fclose(fp); } void read_suffix_from_file_to_buf(const char *filename, char *buf, size_t buflen) From 70b33bffd532f48c201b3bb549bbc6c13d4a0a3c Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Mon, 4 May 2026 15:06:54 +0530 Subject: [PATCH 65/79] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- src/unittest/rrdUnitTestRunner.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/unittest/rrdUnitTestRunner.cpp b/src/unittest/rrdUnitTestRunner.cpp index be8cad007..2ffbf7b7f 100644 --- a/src/unittest/rrdUnitTestRunner.cpp +++ b/src/unittest/rrdUnitTestRunner.cpp @@ -5821,6 +5821,15 @@ TEST_F(RRDProfileHandlerTest, SetHandler_MaxLengthString) class SuffixUtilsTest : public ::testing::Test { protected: + void SetUp() override { + struct stat dir_stat = {}; + + if (mkdir("/tmp/rrd", 0777) != 0) { + ASSERT_EQ(stat("/tmp/rrd", &dir_stat), 0) << "Failed to access /tmp/rrd"; + ASSERT_TRUE(S_ISDIR(dir_stat.st_mode)) << "/tmp/rrd exists but is not a directory"; + } + } + void TearDown() override { // Remove suffix temp file to avoid state leakage between tests remove("/tmp/rrd/rrd_suffix.txt"); From 20d67861f0bf4b033c61902cb59bcc56fa3bd942 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Mon, 4 May 2026 15:10:53 +0530 Subject: [PATCH 66/79] Update rrdUnitTestRunner.cpp --- src/unittest/rrdUnitTestRunner.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/unittest/rrdUnitTestRunner.cpp b/src/unittest/rrdUnitTestRunner.cpp index 2ffbf7b7f..5314716ce 100644 --- a/src/unittest/rrdUnitTestRunner.cpp +++ b/src/unittest/rrdUnitTestRunner.cpp @@ -5931,7 +5931,7 @@ TEST_F(SuffixUtilsTest, SplitIssueType_RealWorldInput) TEST_F(SuffixUtilsTest, PersistSuffix_NormalValue) { - persist_suffix_to_file("_Search123"); + persist_suffix_to_file("/tmp/rrd/rrd_suffix.txt","_Search123"); // Verify the file was written FILE *fp = fopen("/tmp/rrd/rrd_suffix.txt", "r"); ASSERT_NE(fp, nullptr); @@ -5943,7 +5943,7 @@ TEST_F(SuffixUtilsTest, PersistSuffix_NormalValue) TEST_F(SuffixUtilsTest, PersistSuffix_EmptyString) { - persist_suffix_to_file(""); + persist_suffix_to_file("/tmp/rrd/rrd_suffix.txt",""); FILE *fp = fopen("/tmp/rrd/rrd_suffix.txt", "r"); ASSERT_NE(fp, nullptr); char buf[64] = {0}; @@ -5956,7 +5956,7 @@ TEST_F(SuffixUtilsTest, PersistSuffix_EmptyString) TEST_F(SuffixUtilsTest, PersistSuffix_NullDoesNotCrash) { // Passing NULL should not crash; file should be created but empty - persist_suffix_to_file(NULL); + persist_suffix_to_file("/tmp/rrd/rrd_suffix.txt",NULL); FILE *fp = fopen("/tmp/rrd/rrd_suffix.txt", "r"); ASSERT_NE(fp, nullptr); char buf[64] = {0}; @@ -5967,10 +5967,10 @@ TEST_F(SuffixUtilsTest, PersistSuffix_NullDoesNotCrash) TEST_F(SuffixUtilsTest, PersistSuffix_OverwritesPreviousValue) { - persist_suffix_to_file("_OldSuffix"); - persist_suffix_to_file("_NewSuffix"); + persist_suffix_to_file("/tmp/rrd/rrd_suffix.txt","_OldSuffix"); + persist_suffix_to_file("/tmp/rrd/rrd_suffix.txt","_NewSuffix"); char buf[64] = {0}; - read_suffix_from_file_to_buf(buf, sizeof(buf)); + read_suffix_from_file_to_buf("/tmp/rrd/rrd_suffix.txt",buf, sizeof(buf)); EXPECT_STREQ(buf, "_NewSuffix"); } @@ -5978,9 +5978,9 @@ TEST_F(SuffixUtilsTest, PersistSuffix_OverwritesPreviousValue) TEST_F(SuffixUtilsTest, ReadSuffix_AfterPersist) { - persist_suffix_to_file("_Search123"); + persist_suffix_to_file("/tmp/rrd/rrd_suffix.txt","_Search123"); char buf[64] = {0}; - read_suffix_from_file_to_buf(buf, sizeof(buf)); + read_suffix_from_file_to_buf("/tmp/rrd/rrd_suffix.txt",buf, sizeof(buf)); EXPECT_STREQ(buf, "_Search123"); } @@ -5988,7 +5988,7 @@ TEST_F(SuffixUtilsTest, ReadSuffix_WhenFileAbsent) { remove("/tmp/rrd/rrd_suffix.txt"); char buf[64] = {0}; - read_suffix_from_file_to_buf(buf, sizeof(buf)); + read_suffix_from_file_to_buf("/tmp/rrd/rrd_suffix.txt",buf, sizeof(buf)); EXPECT_STREQ(buf, ""); } @@ -5996,7 +5996,7 @@ TEST_F(SuffixUtilsTest, ReadSuffix_NullBufDoesNotCrash) { persist_suffix_to_file("_test"); // Should not crash when buf is NULL - read_suffix_from_file_to_buf(NULL, 64); + read_suffix_from_file_to_buf("/tmp/rrd/rrd_suffix.txt",NULL, 64); } TEST_F(SuffixUtilsTest, ReadSuffix_ZeroBuflenDoesNotCrash) @@ -6004,7 +6004,7 @@ TEST_F(SuffixUtilsTest, ReadSuffix_ZeroBuflenDoesNotCrash) persist_suffix_to_file("_test"); char buf[64] = {0}; // Should not crash when buflen is 0 - read_suffix_from_file_to_buf(buf, 0); + read_suffix_from_file_to_buf("/tmp/rrd/rrd_suffix.txt",buf, 0); } TEST_F(SuffixUtilsTest, ReadSuffix_RoundTrip) @@ -6012,7 +6012,7 @@ TEST_F(SuffixUtilsTest, ReadSuffix_RoundTrip) const char *expected = "_Search-b6877385-9463-45fc-b19d-a24d77fd0790"; persist_suffix_to_file(expected); char buf[128] = {0}; - read_suffix_from_file_to_buf(buf, sizeof(buf)); + read_suffix_from_file_to_buf("/tmp/rrd/rrd_suffix.txt",buf, sizeof(buf)); EXPECT_STREQ(buf, expected); } @@ -6024,7 +6024,7 @@ TEST_F(SuffixUtilsTest, ReadSuffix_StripsTrailingNewline) fputs("_suffix\n", fp); fclose(fp); char buf[64] = {0}; - read_suffix_from_file_to_buf(buf, sizeof(buf)); + read_suffix_from_file_to_buf("/tmp/rrd/rrd_suffix.txt",buf, sizeof(buf)); EXPECT_STREQ(buf, "_suffix"); } From 003b5eff77d22de6034ef729d724a28596c54111 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Mon, 4 May 2026 15:23:36 +0530 Subject: [PATCH 67/79] Update rrdUnitTestRunner.cpp --- src/unittest/rrdUnitTestRunner.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/unittest/rrdUnitTestRunner.cpp b/src/unittest/rrdUnitTestRunner.cpp index 5314716ce..04d57ffbf 100644 --- a/src/unittest/rrdUnitTestRunner.cpp +++ b/src/unittest/rrdUnitTestRunner.cpp @@ -5994,14 +5994,14 @@ TEST_F(SuffixUtilsTest, ReadSuffix_WhenFileAbsent) TEST_F(SuffixUtilsTest, ReadSuffix_NullBufDoesNotCrash) { - persist_suffix_to_file("_test"); + persist_suffix_to_file("/tmp/rrd/rrd_suffix.txt","_test"); // Should not crash when buf is NULL read_suffix_from_file_to_buf("/tmp/rrd/rrd_suffix.txt",NULL, 64); } TEST_F(SuffixUtilsTest, ReadSuffix_ZeroBuflenDoesNotCrash) { - persist_suffix_to_file("_test"); + persist_suffix_to_file("/tmp/rrd/rrd_suffix.txt","_test"); char buf[64] = {0}; // Should not crash when buflen is 0 read_suffix_from_file_to_buf("/tmp/rrd/rrd_suffix.txt",buf, 0); @@ -6010,7 +6010,7 @@ TEST_F(SuffixUtilsTest, ReadSuffix_ZeroBuflenDoesNotCrash) TEST_F(SuffixUtilsTest, ReadSuffix_RoundTrip) { const char *expected = "_Search-b6877385-9463-45fc-b19d-a24d77fd0790"; - persist_suffix_to_file(expected); + persist_suffix_to_file("/tmp/rrd/rrd_suffix.txt",expected); char buf[128] = {0}; read_suffix_from_file_to_buf("/tmp/rrd/rrd_suffix.txt",buf, sizeof(buf)); EXPECT_STREQ(buf, expected); From 7d722c006504479029209c8e8259ddab480ba6da Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Mon, 4 May 2026 15:30:51 +0530 Subject: [PATCH 68/79] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- src/rrdJsonParser.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/rrdJsonParser.c b/src/rrdJsonParser.c index 69ea92dfe..95aaac8f6 100644 --- a/src/rrdJsonParser.c +++ b/src/rrdJsonParser.c @@ -24,9 +24,6 @@ #include #include #include -#include -//#define RRD_SUFFIX_DIR "/tmp/rrd" -//#define RRD_SUFFIX_PATH "/tmp/rrd/rrd_suffix.txt" /* From 0c1fbf08068a9fa77bf2312358b61a650dc0a77f Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Mon, 4 May 2026 15:32:55 +0530 Subject: [PATCH 69/79] Update rrdJsonParser.c --- src/rrdJsonParser.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rrdJsonParser.c b/src/rrdJsonParser.c index 95aaac8f6..da5b9755e 100644 --- a/src/rrdJsonParser.c +++ b/src/rrdJsonParser.c @@ -24,7 +24,7 @@ #include #include #include - +#include /* * @function removeSpecialChar From 39dedf55335a63c437e0bf9f226e847b2daa87c4 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Mon, 4 May 2026 15:35:54 +0530 Subject: [PATCH 70/79] Update rrdJsonParser.c --- src/rrdJsonParser.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/rrdJsonParser.c b/src/rrdJsonParser.c index da5b9755e..a5de735b4 100644 --- a/src/rrdJsonParser.c +++ b/src/rrdJsonParser.c @@ -48,22 +48,24 @@ void removeSpecialChar(char *str) } void persist_suffix_to_file(const char *filename, const char *suffix) { - if (!filename) { + if (!filename) + { RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: persist_suffix_to_file called with NULL filename\n", __FUNCTION__, __LINE__); return; } FILE *fp = fopen(filename, "w"); - if (!fp) { - RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: failed to open file '%s' for writing: %s\n", - __FUNCTION__, __LINE__, filename, strerror(errno)); + if (!fp) + { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: failed to open file '%s' for writing: %s\n", __FUNCTION__, __LINE__, filename, strerror(errno)); return; } - if (suffix) { - if (fputs(suffix, fp) == EOF) { - RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: failed to write suffix to file '%s': %s\n", - __FUNCTION__, __LINE__, filename, strerror(errno)); + if (suffix) + { + if (fputs(suffix, fp) == EOF) + { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: failed to write suffix to file '%s': %s\n", __FUNCTION__, __LINE__, filename, strerror(errno)); } } From 8900d98d5cb4161cfb11f9855cc0bddea3482b00 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Mon, 4 May 2026 15:50:50 +0530 Subject: [PATCH 71/79] Update rrdJsonParser.c --- src/rrdJsonParser.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/rrdJsonParser.c b/src/rrdJsonParser.c index a5de735b4..ff76c9a39 100644 --- a/src/rrdJsonParser.c +++ b/src/rrdJsonParser.c @@ -47,29 +47,31 @@ void removeSpecialChar(char *str) } } -void persist_suffix_to_file(const char *filename, const char *suffix) { - if (!filename) +void persist_suffix_to_file(const char *filename, const char *suffix) +{ + int fd; + if (!filename) { RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: persist_suffix_to_file called with NULL filename\n", __FUNCTION__, __LINE__); return; } - - FILE *fp = fopen(filename, "w"); - if (!fp) - { - RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: failed to open file '%s' for writing: %s\n", __FUNCTION__, __LINE__, filename, strerror(errno)); - return; - } - - if (suffix) + fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_NOFOLLOW, 0600); + if (fd >= 0) { - if (fputs(suffix, fp) == EOF) + FILE *fp = fdopen(fd, "w"); + if (fp) + { + if (fprintf(fp, "%s\n", suffix) > 0) + { + RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: write suffix to file '%s'\n", __FUNCTION__, __LINE__, filename); + } + fclose(fp); // This also closes the underlying fd + } + else { - RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: failed to write suffix to file '%s': %s\n", __FUNCTION__, __LINE__, filename, strerror(errno)); + close(fd); // Close fd if fdopen failed } } - - fclose(fp); } void read_suffix_from_file_to_buf(const char *filename, char *buf, size_t buflen) From 1d06c26cae6223643a868298e119e72a16578fe9 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Mon, 4 May 2026 15:51:21 +0530 Subject: [PATCH 72/79] Update rrdCommon.h --- src/rrdCommon.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rrdCommon.h b/src/rrdCommon.h index 06adb245e..e2ee5a20c 100644 --- a/src/rrdCommon.h +++ b/src/rrdCommon.h @@ -67,7 +67,7 @@ extern "C" #define BUF_LEN_128 128 #define APPEND_SUFFIX "_apnd" -#define RRD_SUFFIX_PATH "/tmp/rrd/rrd_suffix.txt" +#define RRD_SUFFIX_PATH "/tmp/rrd_suffix.txt" /* Enum for Messages Queue*/ typedef enum { From 788335e9fd668ba79a89625817acf77be96df4e1 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Mon, 4 May 2026 15:55:49 +0530 Subject: [PATCH 73/79] Add fcntl.h include for file control operations --- src/rrdJsonParser.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/rrdJsonParser.c b/src/rrdJsonParser.c index ff76c9a39..e4a8b3012 100644 --- a/src/rrdJsonParser.c +++ b/src/rrdJsonParser.c @@ -25,6 +25,7 @@ #include #include #include +#include /* * @function removeSpecialChar From d9ca84437c583f02fd07e95058ad25996c29ce10 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Mon, 4 May 2026 16:04:06 +0530 Subject: [PATCH 74/79] Update rrdJsonParser.c --- src/rrdJsonParser.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/rrdJsonParser.c b/src/rrdJsonParser.c index e4a8b3012..27d28421e 100644 --- a/src/rrdJsonParser.c +++ b/src/rrdJsonParser.c @@ -62,10 +62,14 @@ void persist_suffix_to_file(const char *filename, const char *suffix) FILE *fp = fdopen(fd, "w"); if (fp) { - if (fprintf(fp, "%s\n", suffix) > 0) - { - RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: write suffix to file '%s'\n", __FUNCTION__, __LINE__, filename); + if (suffix) + { + if (fputs(suffix, fp) == EOF) + { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: failed to write suffix to file '%s': %s\n", __FUNCTION__, __LINE__, filename, strerror(errno)); + } } + fclose(fp); // This also closes the underlying fd } else From 7c7dde7a709cb0fae37fa05c2b12ec4c638b6d34 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Mon, 4 May 2026 17:09:05 +0530 Subject: [PATCH 75/79] Update rrdJsonParser.c --- src/rrdJsonParser.c | 53 +++++++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 21 deletions(-) diff --git a/src/rrdJsonParser.c b/src/rrdJsonParser.c index 27d28421e..c637ed4fc 100644 --- a/src/rrdJsonParser.c +++ b/src/rrdJsonParser.c @@ -51,32 +51,43 @@ void removeSpecialChar(char *str) void persist_suffix_to_file(const char *filename, const char *suffix) { int fd; - if (!filename) - { + if (!filename) + { RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: persist_suffix_to_file called with NULL filename\n", __FUNCTION__, __LINE__); return; } - fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_NOFOLLOW, 0600); - if (fd >= 0) - { - FILE *fp = fdopen(fd, "w"); - if (fp) - { - if (suffix) - { - if (fputs(suffix, fp) == EOF) - { - RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: failed to write suffix to file '%s': %s\n", __FUNCTION__, __LINE__, filename, strerror(errno)); - } - } - - fclose(fp); // This also closes the underlying fd - } - else - { - close(fd); // Close fd if fdopen failed + fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_NOFOLLOW | O_CLOEXEC, 0600); + if (fd < 0) + { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: Failed to open '%s' for writing: %s\n", __FUNCTION__, __LINE__, filename, strerror(errno)); + return; + } + struct stat st; + if (fstat(fd, &st) != 0) { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: fstat failed on '%s': %s\n", __FUNCTION__, __LINE__, filename, strerror(errno)); + close(fd); + return; + } + if (!S_ISREG(st.st_mode)) { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: '%s' is not a regular file!\n", __FUNCTION__, __LINE__, filename); + close(fd); + return; + } + FILE *fp = fdopen(fd, "w"); + if (!fp) + { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: fdopen failed on '%s': %s\n", __FUNCTION__, __LINE__, filename, strerror(errno)); + close(fd); + return; + } + if (suffix) + { + if (fputs(suffix, fp) == EOF) + { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: failed to write suffix to file '%s': %s\n", __FUNCTION__, __LINE__, filename, strerror(errno)); } } + fclose(fp); // This also closes the underlying fd } void read_suffix_from_file_to_buf(const char *filename, char *buf, size_t buflen) From 929196ef48336c3f913e907c91cc6ccb18aacf9f Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Mon, 4 May 2026 17:10:03 +0530 Subject: [PATCH 76/79] Update rrdJsonParser.c --- src/rrdJsonParser.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/rrdJsonParser.c b/src/rrdJsonParser.c index c637ed4fc..bae9cbb2f 100644 --- a/src/rrdJsonParser.c +++ b/src/rrdJsonParser.c @@ -63,12 +63,14 @@ void persist_suffix_to_file(const char *filename, const char *suffix) return; } struct stat st; - if (fstat(fd, &st) != 0) { + if (fstat(fd, &st) != 0) + { RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: fstat failed on '%s': %s\n", __FUNCTION__, __LINE__, filename, strerror(errno)); close(fd); return; } - if (!S_ISREG(st.st_mode)) { + if (!S_ISREG(st.st_mode)) + { RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: '%s' is not a regular file!\n", __FUNCTION__, __LINE__, filename); close(fd); return; From 3a3c937a71946de7ab4012fe256b6fe219af01ac Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Mon, 4 May 2026 17:13:13 +0530 Subject: [PATCH 77/79] Update rrdJsonParser.c --- src/rrdJsonParser.c | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/src/rrdJsonParser.c b/src/rrdJsonParser.c index bae9cbb2f..dd1a8f145 100644 --- a/src/rrdJsonParser.c +++ b/src/rrdJsonParser.c @@ -94,15 +94,36 @@ void persist_suffix_to_file(const char *filename, const char *suffix) void read_suffix_from_file_to_buf(const char *filename, char *buf, size_t buflen) { - if (!buf || buflen == 0 || !filename) return; - FILE *fp = fopen(filename, "r"); - if (!fp) - { + if (!buf || buflen == 0 || !filename) { + return; + } + int fd = open(filename, O_RDONLY | O_NOFOLLOW | O_CLOEXEC); + if (fd < 0) { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: Failed to open '%s' for reading: %s\n", __FUNCTION__, __LINE__, filename, strerror(errno)); buf[0] = '\0'; return; } - if (fgets(buf, buflen, fp) == NULL) - { + struct stat st; + if (fstat(fd, &st) != 0) { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: fstat failed on '%s': %s\n", __FUNCTION__, __LINE__, filename, strerror(errno)); + close(fd); + buf[0] = '\0'; + return; + } + if (!S_ISREG(st.st_mode)) { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: '%s' is not a regular file!\n", __FUNCTION__, __LINE__, filename); + close(fd); + buf[0] = '\0'; + return; + } + FILE *fp = fdopen(fd, "r"); + if (!fp) { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: fdopen failed on '%s': %s\n", __FUNCTION__, __LINE__, filename, strerror(errno)); + close(fd); + buf[0] = '\0'; + return; + } + if (fgets(buf, buflen, fp) == NULL) { buf[0] = '\0'; fclose(fp); return; From 85a6c29984a8e3884919cd015c71c8b8985df190 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Mon, 4 May 2026 17:25:14 +0530 Subject: [PATCH 78/79] Update rrdUnitTestRunner.cpp --- src/unittest/rrdUnitTestRunner.cpp | 42 +++++++++++++++--------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/unittest/rrdUnitTestRunner.cpp b/src/unittest/rrdUnitTestRunner.cpp index 04d57ffbf..bbc20dfd4 100644 --- a/src/unittest/rrdUnitTestRunner.cpp +++ b/src/unittest/rrdUnitTestRunner.cpp @@ -5832,7 +5832,7 @@ class SuffixUtilsTest : public ::testing::Test { void TearDown() override { // Remove suffix temp file to avoid state leakage between tests - remove("/tmp/rrd/rrd_suffix.txt"); + remove("/tmp/rrd_suffix.txt"); } }; @@ -5931,9 +5931,9 @@ TEST_F(SuffixUtilsTest, SplitIssueType_RealWorldInput) TEST_F(SuffixUtilsTest, PersistSuffix_NormalValue) { - persist_suffix_to_file("/tmp/rrd/rrd_suffix.txt","_Search123"); + persist_suffix_to_file("/tmp/rrd_suffix.txt","_Search123"); // Verify the file was written - FILE *fp = fopen("/tmp/rrd/rrd_suffix.txt", "r"); + FILE *fp = fopen("/tmp/rrd_suffix.txt", "r"); ASSERT_NE(fp, nullptr); char buf[64] = {0}; ASSERT_NE(fgets(buf, sizeof(buf), fp), nullptr); @@ -5943,8 +5943,8 @@ TEST_F(SuffixUtilsTest, PersistSuffix_NormalValue) TEST_F(SuffixUtilsTest, PersistSuffix_EmptyString) { - persist_suffix_to_file("/tmp/rrd/rrd_suffix.txt",""); - FILE *fp = fopen("/tmp/rrd/rrd_suffix.txt", "r"); + persist_suffix_to_file("/tmp/rrd_suffix.txt",""); + FILE *fp = fopen("/tmp/rrd_suffix.txt", "r"); ASSERT_NE(fp, nullptr); char buf[64] = {0}; // fgets may return NULL for an empty file - that's fine, buf stays empty @@ -5956,8 +5956,8 @@ TEST_F(SuffixUtilsTest, PersistSuffix_EmptyString) TEST_F(SuffixUtilsTest, PersistSuffix_NullDoesNotCrash) { // Passing NULL should not crash; file should be created but empty - persist_suffix_to_file("/tmp/rrd/rrd_suffix.txt",NULL); - FILE *fp = fopen("/tmp/rrd/rrd_suffix.txt", "r"); + persist_suffix_to_file("/tmp/rrd_suffix.txt",NULL); + FILE *fp = fopen("/tmp/rrd_suffix.txt", "r"); ASSERT_NE(fp, nullptr); char buf[64] = {0}; fgets(buf, sizeof(buf), fp); @@ -5967,8 +5967,8 @@ TEST_F(SuffixUtilsTest, PersistSuffix_NullDoesNotCrash) TEST_F(SuffixUtilsTest, PersistSuffix_OverwritesPreviousValue) { - persist_suffix_to_file("/tmp/rrd/rrd_suffix.txt","_OldSuffix"); - persist_suffix_to_file("/tmp/rrd/rrd_suffix.txt","_NewSuffix"); + persist_suffix_to_file("/tmp/rrd_suffix.txt","_OldSuffix"); + persist_suffix_to_file("/tmp/rrd_suffix.txt","_NewSuffix"); char buf[64] = {0}; read_suffix_from_file_to_buf("/tmp/rrd/rrd_suffix.txt",buf, sizeof(buf)); EXPECT_STREQ(buf, "_NewSuffix"); @@ -5978,53 +5978,53 @@ TEST_F(SuffixUtilsTest, PersistSuffix_OverwritesPreviousValue) TEST_F(SuffixUtilsTest, ReadSuffix_AfterPersist) { - persist_suffix_to_file("/tmp/rrd/rrd_suffix.txt","_Search123"); + persist_suffix_to_file("/tmp/rrd_suffix.txt","_Search123"); char buf[64] = {0}; - read_suffix_from_file_to_buf("/tmp/rrd/rrd_suffix.txt",buf, sizeof(buf)); + read_suffix_from_file_to_buf("/tmp/rrd_suffix.txt",buf, sizeof(buf)); EXPECT_STREQ(buf, "_Search123"); } TEST_F(SuffixUtilsTest, ReadSuffix_WhenFileAbsent) { - remove("/tmp/rrd/rrd_suffix.txt"); + remove("/tmp/rrd_suffix.txt"); char buf[64] = {0}; - read_suffix_from_file_to_buf("/tmp/rrd/rrd_suffix.txt",buf, sizeof(buf)); + read_suffix_from_file_to_buf("/tmp/rrd_suffix.txt",buf, sizeof(buf)); EXPECT_STREQ(buf, ""); } TEST_F(SuffixUtilsTest, ReadSuffix_NullBufDoesNotCrash) { - persist_suffix_to_file("/tmp/rrd/rrd_suffix.txt","_test"); + persist_suffix_to_file("/tmp/rrd_suffix.txt","_test"); // Should not crash when buf is NULL - read_suffix_from_file_to_buf("/tmp/rrd/rrd_suffix.txt",NULL, 64); + read_suffix_from_file_to_buf("/tmp/rrd_suffix.txt",NULL, 64); } TEST_F(SuffixUtilsTest, ReadSuffix_ZeroBuflenDoesNotCrash) { - persist_suffix_to_file("/tmp/rrd/rrd_suffix.txt","_test"); + persist_suffix_to_file("/tmp/rrd_suffix.txt","_test"); char buf[64] = {0}; // Should not crash when buflen is 0 - read_suffix_from_file_to_buf("/tmp/rrd/rrd_suffix.txt",buf, 0); + read_suffix_from_file_to_buf("/tmp/rrd_suffix.txt",buf, 0); } TEST_F(SuffixUtilsTest, ReadSuffix_RoundTrip) { const char *expected = "_Search-b6877385-9463-45fc-b19d-a24d77fd0790"; - persist_suffix_to_file("/tmp/rrd/rrd_suffix.txt",expected); + persist_suffix_to_file("/tmp/rrd_suffix.txt",expected); char buf[128] = {0}; - read_suffix_from_file_to_buf("/tmp/rrd/rrd_suffix.txt",buf, sizeof(buf)); + read_suffix_from_file_to_buf("/tmp/rrd_suffix.txt",buf, sizeof(buf)); EXPECT_STREQ(buf, expected); } TEST_F(SuffixUtilsTest, ReadSuffix_StripsTrailingNewline) { // Write a value with a trailing newline to the file - FILE *fp = fopen("/tmp/rrd/rrd_suffix.txt", "w"); + FILE *fp = fopen("/tmp/rrd_suffix.txt", "w"); ASSERT_NE(fp, nullptr); fputs("_suffix\n", fp); fclose(fp); char buf[64] = {0}; - read_suffix_from_file_to_buf("/tmp/rrd/rrd_suffix.txt",buf, sizeof(buf)); + read_suffix_from_file_to_buf("/tmp/rrd_suffix.txt",buf, sizeof(buf)); EXPECT_STREQ(buf, "_suffix"); } From 05c6b2cbd21aeaa156918cf8351dcb250fc4dc62 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Mon, 4 May 2026 17:34:27 +0530 Subject: [PATCH 79/79] Update rrdUnitTestRunner.cpp --- src/unittest/rrdUnitTestRunner.cpp | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/unittest/rrdUnitTestRunner.cpp b/src/unittest/rrdUnitTestRunner.cpp index bbc20dfd4..cecc2f010 100644 --- a/src/unittest/rrdUnitTestRunner.cpp +++ b/src/unittest/rrdUnitTestRunner.cpp @@ -5821,15 +5821,6 @@ TEST_F(RRDProfileHandlerTest, SetHandler_MaxLengthString) class SuffixUtilsTest : public ::testing::Test { protected: - void SetUp() override { - struct stat dir_stat = {}; - - if (mkdir("/tmp/rrd", 0777) != 0) { - ASSERT_EQ(stat("/tmp/rrd", &dir_stat), 0) << "Failed to access /tmp/rrd"; - ASSERT_TRUE(S_ISDIR(dir_stat.st_mode)) << "/tmp/rrd exists but is not a directory"; - } - } - void TearDown() override { // Remove suffix temp file to avoid state leakage between tests remove("/tmp/rrd_suffix.txt"); @@ -5970,7 +5961,7 @@ TEST_F(SuffixUtilsTest, PersistSuffix_OverwritesPreviousValue) persist_suffix_to_file("/tmp/rrd_suffix.txt","_OldSuffix"); persist_suffix_to_file("/tmp/rrd_suffix.txt","_NewSuffix"); char buf[64] = {0}; - read_suffix_from_file_to_buf("/tmp/rrd/rrd_suffix.txt",buf, sizeof(buf)); + read_suffix_from_file_to_buf("/tmp/rrd_suffix.txt",buf, sizeof(buf)); EXPECT_STREQ(buf, "_NewSuffix"); }