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/66] 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/66] 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/66] 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/66] 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/66] 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/66] 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/66] 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/66] 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/66] 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/66] 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/66] 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/66] 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/66] 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/66] 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/66] 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/66] 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/66] 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/66] 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/66] 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/66] 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/66] 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/66] 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/66] 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/66] 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/66] 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/66] 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/66] 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/66] 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/66] 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/66] 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/66] 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/66] 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/66] 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/66] 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/66] 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/66] 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/66] 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/66] 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/66] 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/66] 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/66] 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/66] 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/66] 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/66] 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/66] 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/66] 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/66] 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/66] 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/66] 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/66] 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/66] 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/66] 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/66] 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 2e1057a1b11894e26cdcfe515a3afe27f6ca1099 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Mon, 4 May 2026 11:39:19 +0530 Subject: [PATCH 54/66] Update rrdJsonParser.c --- src/rrdJsonParser.c | 77 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 59 insertions(+), 18 deletions(-) diff --git a/src/rrdJsonParser.c b/src/rrdJsonParser.c index 91793d0f1..7a486ce3d 100644 --- a/src/rrdJsonParser.c +++ b/src/rrdJsonParser.c @@ -52,35 +52,76 @@ 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)) - { + uid_t uid = getuid(); + 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) - { + if (st.st_uid != uid || (st.st_mode & 0777) != 0700) { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] %s not owned by current user or not mode 0700!\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; } + // After creation, check ownership and mode + if (lstat(RRD_SUFFIX_DIR, &st) != 0 || !S_ISDIR(st.st_mode) || st.st_uid != uid || (st.st_mode & 0777) != 0700) { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] %s not owned by current user or not mode 0700 after creation!\n", __FUNCTION__, __LINE__, RRD_SUFFIX_DIR); + 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)); + + // Write to a temp file first + char tmp_path[256]; + snprintf(tmp_path, sizeof(tmp_path), "%s/.rrd_suffix.tmpXXXXXX", RRD_SUFFIX_DIR); + int tmpfd = mkstemp(tmp_path); + if (tmpfd == -1) { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] Failed to create temp file in %s: %s\n", __FUNCTION__, __LINE__, RRD_SUFFIX_DIR, 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); + // Set restrictive permissions + if (fchmod(tmpfd, 0600) != 0) { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] Failed to set permissions on temp file: %s\n", __FUNCTION__, __LINE__, strerror(errno)); + close(tmpfd); + unlink(tmp_path); + return -1; + } + // Write suffix + if (suffix && suffix[0] != '\0') { + size_t len = strlen(suffix); + ssize_t written = write(tmpfd, suffix, len); + if (written != (ssize_t)len) { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] Failed to write suffix to temp file: %s\n", __FUNCTION__, __LINE__, strerror(errno)); + close(tmpfd); + unlink(tmp_path); + return -1; + } + } + // Flush and verify + if (fsync(tmpfd) != 0) { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] fsync failed on temp file: %s\n", __FUNCTION__, __LINE__, strerror(errno)); + close(tmpfd); + unlink(tmp_path); + return -1; + } + struct stat fst; + if (fstat(tmpfd, &fst) != 0 || !S_ISREG(fst.st_mode)) { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] Temp file is not a regular file!\n", __FUNCTION__, __LINE__); + close(tmpfd); + unlink(tmp_path); + return -1; + } + close(tmpfd); + + // Atomically rename temp file to target + if (rename(tmp_path, RRD_SUFFIX_PATH) != 0) { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] Failed to rename temp file to %s: %s\n", __FUNCTION__, __LINE__, RRD_SUFFIX_PATH, strerror(errno)); + unlink(tmp_path); return -1; } - fclose(fp); return 0; } From 11c6577c7b3495fd31fc4435ded8518ad28836cd Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Mon, 4 May 2026 11:45:29 +0530 Subject: [PATCH 55/66] Update rrdJsonParser.c --- src/rrdJsonParser.c | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/src/rrdJsonParser.c b/src/rrdJsonParser.c index 7a486ce3d..c4ba2d7c8 100644 --- a/src/rrdJsonParser.c +++ b/src/rrdJsonParser.c @@ -50,20 +50,27 @@ void removeSpecialChar(char *str) } } -int persist_suffix_to_file(const char *suffix) { +int persist_suffix_to_file(const char *suffix) +{ struct stat st; uid_t uid = getuid(); - 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; } - if (st.st_uid != uid || (st.st_mode & 0777) != 0700) { + if (st.st_uid != uid || (st.st_mode & 0777) != 0700) + { RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] %s not owned by current user or not mode 0700!\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; } @@ -78,22 +85,26 @@ int persist_suffix_to_file(const char *suffix) { char tmp_path[256]; snprintf(tmp_path, sizeof(tmp_path), "%s/.rrd_suffix.tmpXXXXXX", RRD_SUFFIX_DIR); int tmpfd = mkstemp(tmp_path); - if (tmpfd == -1) { + if (tmpfd == -1) + { RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] Failed to create temp file in %s: %s\n", __FUNCTION__, __LINE__, RRD_SUFFIX_DIR, strerror(errno)); return -1; } // Set restrictive permissions - if (fchmod(tmpfd, 0600) != 0) { + if (fchmod(tmpfd, 0600) != 0) + { RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] Failed to set permissions on temp file: %s\n", __FUNCTION__, __LINE__, strerror(errno)); close(tmpfd); unlink(tmp_path); return -1; } // Write suffix - if (suffix && suffix[0] != '\0') { + if (suffix && suffix[0] != '\0') + { size_t len = strlen(suffix); ssize_t written = write(tmpfd, suffix, len); - if (written != (ssize_t)len) { + if (written != (ssize_t)len) + { RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] Failed to write suffix to temp file: %s\n", __FUNCTION__, __LINE__, strerror(errno)); close(tmpfd); unlink(tmp_path); @@ -101,14 +112,16 @@ int persist_suffix_to_file(const char *suffix) { } } // Flush and verify - if (fsync(tmpfd) != 0) { + if (fsync(tmpfd) != 0) + { RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] fsync failed on temp file: %s\n", __FUNCTION__, __LINE__, strerror(errno)); close(tmpfd); unlink(tmp_path); return -1; } struct stat fst; - if (fstat(tmpfd, &fst) != 0 || !S_ISREG(fst.st_mode)) { + if (fstat(tmpfd, &fst) != 0 || !S_ISREG(fst.st_mode)) + { RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] Temp file is not a regular file!\n", __FUNCTION__, __LINE__); close(tmpfd); unlink(tmp_path); @@ -117,7 +130,8 @@ int persist_suffix_to_file(const char *suffix) { close(tmpfd); // Atomically rename temp file to target - if (rename(tmp_path, RRD_SUFFIX_PATH) != 0) { + if (rename(tmp_path, RRD_SUFFIX_PATH) != 0) + { RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] Failed to rename temp file to %s: %s\n", __FUNCTION__, __LINE__, RRD_SUFFIX_PATH, strerror(errno)); unlink(tmp_path); return -1; From 83ed3fc07c10d91852e87262600818c18317971d Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Mon, 4 May 2026 12:06:51 +0530 Subject: [PATCH 56/66] Update rrdJsonParser.c --- src/rrdJsonParser.c | 120 ++++++++++++++++++++++++++------------------ 1 file changed, 70 insertions(+), 50 deletions(-) diff --git a/src/rrdJsonParser.c b/src/rrdJsonParser.c index c4ba2d7c8..4f534d024 100644 --- a/src/rrdJsonParser.c +++ b/src/rrdJsonParser.c @@ -50,90 +50,99 @@ void removeSpecialChar(char *str) } } -int persist_suffix_to_file(const char *suffix) -{ +int persist_suffix_to_file(const char *suffix) { struct stat st; uid_t uid = getuid(); - 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; - } - if (st.st_uid != uid || (st.st_mode & 0777) != 0700) - { - RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] %s not owned by current user or not mode 0700!\n", __FUNCTION__, __LINE__, RRD_SUFFIX_DIR); - return -1; - } - } - else - { - if (mkdir(RRD_SUFFIX_DIR, 0700) != 0 && errno != EEXIST) - { + int dirfd = open(RRD_SUFFIX_DIR, O_PATH | O_NOFOLLOW | O_DIRECTORY); + if (dirfd == -1) { + // Directory does not exist, try to create + 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; } - // After creation, check ownership and mode - if (lstat(RRD_SUFFIX_DIR, &st) != 0 || !S_ISDIR(st.st_mode) || st.st_uid != uid || (st.st_mode & 0777) != 0700) { - RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] %s not owned by current user or not mode 0700 after creation!\n", __FUNCTION__, __LINE__, RRD_SUFFIX_DIR); + dirfd = open(RRD_SUFFIX_DIR, O_PATH | O_NOFOLLOW | O_DIRECTORY); + if (dirfd == -1) { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] Could not open %s after creation: %s\n", __FUNCTION__, __LINE__, RRD_SUFFIX_DIR, strerror(errno)); return -1; } } + if (fstat(dirfd, &st) != 0 || !S_ISDIR(st.st_mode) || st.st_uid != uid || (st.st_mode & 0777) != 0700) { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] %s not owned by current user or not mode 0700!\n", __FUNCTION__, __LINE__, RRD_SUFFIX_DIR); + close(dirfd); + return -1; + } + close(dirfd); // Write to a temp file first char tmp_path[256]; snprintf(tmp_path, sizeof(tmp_path), "%s/.rrd_suffix.tmpXXXXXX", RRD_SUFFIX_DIR); int tmpfd = mkstemp(tmp_path); - if (tmpfd == -1) - { + if (tmpfd == -1) { RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] Failed to create temp file in %s: %s\n", __FUNCTION__, __LINE__, RRD_SUFFIX_DIR, strerror(errno)); return -1; } // Set restrictive permissions - if (fchmod(tmpfd, 0600) != 0) - { + if (fchmod(tmpfd, 0600) != 0) { RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] Failed to set permissions on temp file: %s\n", __FUNCTION__, __LINE__, strerror(errno)); close(tmpfd); - unlink(tmp_path); + if (unlink(tmp_path) != 0) { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] unlink failed on %s: %s\n", __FUNCTION__, __LINE__, tmp_path, strerror(errno)); + } return -1; } // Write suffix - if (suffix && suffix[0] != '\0') - { + if (suffix && suffix[0] != '\0') { size_t len = strlen(suffix); - ssize_t written = write(tmpfd, suffix, len); - if (written != (ssize_t)len) - { - RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] Failed to write suffix to temp file: %s\n", __FUNCTION__, __LINE__, strerror(errno)); - close(tmpfd); - unlink(tmp_path); - return -1; + size_t total_written = 0; + while (total_written < len) { + ssize_t written = write(tmpfd, suffix + total_written, len - total_written); + if (written == -1) { + if (errno == EINTR) + continue; + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] Failed to write suffix to temp file: %s\n", __FUNCTION__, __LINE__, strerror(errno)); + close(tmpfd); + if (unlink(tmp_path) != 0) { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] unlink failed on %s: %s\n", __FUNCTION__, __LINE__, tmp_path, strerror(errno)); + } + return -1; + } + if (written == 0) { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] Short write (0 bytes) to temp file\n", __FUNCTION__, __LINE__); + close(tmpfd); + if (unlink(tmp_path) != 0) { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] unlink failed on %s: %s\n", __FUNCTION__, __LINE__, tmp_path, strerror(errno)); + } + return -1; + } + total_written += (size_t)written; } } // Flush and verify - if (fsync(tmpfd) != 0) - { + if (fsync(tmpfd) != 0) { RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] fsync failed on temp file: %s\n", __FUNCTION__, __LINE__, strerror(errno)); close(tmpfd); - unlink(tmp_path); + if (unlink(tmp_path) != 0) { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] unlink failed on %s: %s\n", __FUNCTION__, __LINE__, tmp_path, strerror(errno)); + } return -1; } struct stat fst; - if (fstat(tmpfd, &fst) != 0 || !S_ISREG(fst.st_mode)) - { + if (fstat(tmpfd, &fst) != 0 || !S_ISREG(fst.st_mode)) { RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] Temp file is not a regular file!\n", __FUNCTION__, __LINE__); close(tmpfd); - unlink(tmp_path); + if (unlink(tmp_path) != 0) { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] unlink failed on %s: %s\n", __FUNCTION__, __LINE__, tmp_path, strerror(errno)); + } return -1; } close(tmpfd); // Atomically rename temp file to target - if (rename(tmp_path, RRD_SUFFIX_PATH) != 0) - { + if (rename(tmp_path, RRD_SUFFIX_PATH) != 0) { RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] Failed to rename temp file to %s: %s\n", __FUNCTION__, __LINE__, RRD_SUFFIX_PATH, strerror(errno)); - unlink(tmp_path); + if (unlink(tmp_path) != 0) { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] unlink failed on %s: %s\n", __FUNCTION__, __LINE__, tmp_path, strerror(errno)); + } return -1; } return 0; @@ -142,14 +151,25 @@ int 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(RRD_SUFFIX_PATH, "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) - { + struct stat st; + if (fstat(fd, &st) != 0 || !S_ISREG(st.st_mode) || st.st_uid != getuid() || (st.st_mode & 022) != 0) { + // Not a regular file, not owned by us, or group/other-writable + buf[0] = '\0'; + close(fd); + return; + } + FILE *fp = fdopen(fd, "r"); + if (!fp) { + buf[0] = '\0'; + close(fd); + return; + } + if (fgets(buf, buflen, fp) == NULL) { buf[0] = '\0'; fclose(fp); return; From 36fdc3862d114667968bc46f9074a84ea0fd8f25 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Mon, 4 May 2026 12:10:11 +0530 Subject: [PATCH 57/66] Update rrdJsonParser.c --- src/rrdJsonParser.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/rrdJsonParser.c b/src/rrdJsonParser.c index 4f534d024..4ec36ccda 100644 --- a/src/rrdJsonParser.c +++ b/src/rrdJsonParser.c @@ -76,7 +76,9 @@ int persist_suffix_to_file(const char *suffix) { // Write to a temp file first char tmp_path[256]; snprintf(tmp_path, sizeof(tmp_path), "%s/.rrd_suffix.tmpXXXXXX", RRD_SUFFIX_DIR); + mode_t old_umask = umask(077); int tmpfd = mkstemp(tmp_path); + umask(old_umask); if (tmpfd == -1) { RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] Failed to create temp file in %s: %s\n", __FUNCTION__, __LINE__, RRD_SUFFIX_DIR, strerror(errno)); return -1; From 9626d79219c2509a4ddc9dee89713b37520fa899 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Mon, 4 May 2026 12:13:52 +0530 Subject: [PATCH 58/66] Update rrdJsonParser.c --- src/rrdJsonParser.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/rrdJsonParser.c b/src/rrdJsonParser.c index 4ec36ccda..a562ae417 100644 --- a/src/rrdJsonParser.c +++ b/src/rrdJsonParser.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #define RRD_SUFFIX_DIR "/tmp/rrd" #define RRD_SUFFIX_PATH "/tmp/rrd/rrd_suffix.txt" From 45ae798878b3502ceec981a3b0348a1546784758 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Mon, 4 May 2026 12:28:45 +0530 Subject: [PATCH 59/66] Update rrdJsonParser.c --- src/rrdJsonParser.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/rrdJsonParser.c b/src/rrdJsonParser.c index a562ae417..d153ed6bd 100644 --- a/src/rrdJsonParser.c +++ b/src/rrdJsonParser.c @@ -23,9 +23,10 @@ #include "rrdCommandSanity.h" #include #include -#include #include +#include #include + #define RRD_SUFFIX_DIR "/tmp/rrd" #define RRD_SUFFIX_PATH "/tmp/rrd/rrd_suffix.txt" @@ -54,14 +55,14 @@ void removeSpecialChar(char *str) int persist_suffix_to_file(const char *suffix) { struct stat st; uid_t uid = getuid(); - int dirfd = open(RRD_SUFFIX_DIR, O_PATH | O_NOFOLLOW | O_DIRECTORY); + int dirfd = open(RRD_SUFFIX_DIR, O_NOFOLLOW | O_DIRECTORY); if (dirfd == -1) { // Directory does not exist, try to create 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; } - dirfd = open(RRD_SUFFIX_DIR, O_PATH | O_NOFOLLOW | O_DIRECTORY); + dirfd = open(RRD_SUFFIX_DIR, O_NOFOLLOW | O_DIRECTORY); if (dirfd == -1) { RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] Could not open %s after creation: %s\n", __FUNCTION__, __LINE__, RRD_SUFFIX_DIR, strerror(errno)); return -1; From d2c3ffa0bf0557851ae5eb07619966a52458a0b7 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Mon, 4 May 2026 12:36:56 +0530 Subject: [PATCH 60/66] Update rrdJsonParser.c --- src/rrdJsonParser.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/rrdJsonParser.c b/src/rrdJsonParser.c index d153ed6bd..078fd6292 100644 --- a/src/rrdJsonParser.c +++ b/src/rrdJsonParser.c @@ -705,7 +705,9 @@ 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 + if (persist_suffix_to_file("") != 0) { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] Failed to clear suffix file on early exit\n", __FUNCTION__, __LINE__); + } return; } @@ -726,7 +728,9 @@ 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 + if (persist_suffix_to_file("") != 0) { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] Failed to clear suffix file on early exit\n", __FUNCTION__, __LINE__); + } return; } else @@ -802,7 +806,9 @@ 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 + if (persist_suffix_to_file("") != 0) { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] Failed to clear suffix file after upload\n", __FUNCTION__, __LINE__); + } } else { @@ -810,7 +816,9 @@ 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 + if (persist_suffix_to_file("") != 0) { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] Failed to clear suffix file after upload\n", __FUNCTION__, __LINE__); + } } } } From 49bc54ff303834c43c766af8851d6ad495587702 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Mon, 4 May 2026 12:41:44 +0530 Subject: [PATCH 61/66] Update rrdEventProcess.c --- src/rrdEventProcess.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/rrdEventProcess.c b/src/rrdEventProcess.c index 90520f9c0..86c978014 100644 --- a/src/rrdEventProcess.c +++ b/src/rrdEventProcess.c @@ -99,7 +99,10 @@ 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); + if (persist_suffix_to_file(local_suffix) != 0) + { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] Failed to persist suffix '%s' from input: '%s' (index=%d)\n", __FUNCTION__, __LINE__, local_suffix, cmdMap[index], index); + } } else { From 30e9c9524ba34022dad834d5667e59365f320c9d Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Mon, 4 May 2026 12:47:23 +0530 Subject: [PATCH 62/66] Update rrdJsonParser.c --- src/rrdJsonParser.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/rrdJsonParser.c b/src/rrdJsonParser.c index 078fd6292..1a0e983e6 100644 --- a/src/rrdJsonParser.c +++ b/src/rrdJsonParser.c @@ -99,7 +99,25 @@ int persist_suffix_to_file(const char *suffix) { size_t len = strlen(suffix); size_t total_written = 0; while (total_written < len) { - ssize_t written = write(tmpfd, suffix + total_written, len - total_written); + /* Coverity fix: ensure no underflow/overflow in len - total_written */ + if (total_written > len) { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] total_written (%zu) > len (%zu), possible integer overflow\n", __FUNCTION__, __LINE__, total_written, len); + close(tmpfd); + if (unlink(tmp_path) != 0) { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] unlink failed on %s: %s\n", __FUNCTION__, __LINE__, tmp_path, strerror(errno)); + } + return -1; + } + size_t to_write = len - total_written; + if (to_write > SSIZE_MAX) { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] to_write (%zu) > SSIZE_MAX (%zd), refusing to write\n", __FUNCTION__, __LINE__, to_write, (ssize_t)SSIZE_MAX); + close(tmpfd); + if (unlink(tmp_path) != 0) { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] unlink failed on %s: %s\n", __FUNCTION__, __LINE__, tmp_path, strerror(errno)); + } + return -1; + } + ssize_t written = write(tmpfd, suffix + total_written, (ssize_t)to_write); if (written == -1) { if (errno == EINTR) continue; From 6542863b447ce01398df8b98332d28959092cbe1 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Mon, 4 May 2026 13:03:52 +0530 Subject: [PATCH 63/66] Update rrdJsonParser.c --- src/rrdJsonParser.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/rrdJsonParser.c b/src/rrdJsonParser.c index 1a0e983e6..547655ec3 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 dff2b1e6cdb2d50b43e00250c4c033a428f2ca9f Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Mon, 4 May 2026 13:43:05 +0530 Subject: [PATCH 64/66] Update rrdJsonParser.c --- src/rrdJsonParser.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/rrdJsonParser.c b/src/rrdJsonParser.c index 547655ec3..1e1280507 100644 --- a/src/rrdJsonParser.c +++ b/src/rrdJsonParser.c @@ -26,7 +26,6 @@ #include #include #include -#include #define RRD_SUFFIX_DIR "/tmp/rrd" #define RRD_SUFFIX_PATH "/tmp/rrd/rrd_suffix.txt" @@ -118,7 +117,25 @@ int persist_suffix_to_file(const char *suffix) { } return -1; } - ssize_t written = write(tmpfd, suffix + total_written, (ssize_t)to_write); + if (to_write == 0) { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] to_write is 0, nothing to write\n", __FUNCTION__, __LINE__); + close(tmpfd); + if (unlink(tmp_path) != 0) { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] unlink failed on %s: %s\n", __FUNCTION__, __LINE__, tmp_path, strerror(errno)); + } + return -1; + } + /* Defensive: never cast a negative value, but size_t is unsigned, so only check upper bound */ + ssize_t write_len = (ssize_t)to_write; + if (write_len <= 0) { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] write_len (%zd) <= 0, refusing to write\n", __FUNCTION__, __LINE__, write_len); + close(tmpfd); + if (unlink(tmp_path) != 0) { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: [ERROR] unlink failed on %s: %s\n", __FUNCTION__, __LINE__, tmp_path, strerror(errno)); + } + return -1; + } + ssize_t written = write(tmpfd, suffix + total_written, write_len); if (written == -1) { if (errno == EINTR) continue; From 021cb298ea2c2c2c9b068fee93c8cec8df56396a Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Mon, 4 May 2026 13:54:09 +0530 Subject: [PATCH 65/66] Update rrdJsonParser.c --- src/rrdJsonParser.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/rrdJsonParser.c b/src/rrdJsonParser.c index 1e1280507..03206a0e7 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 d455cf6c6a5d1f8c0935af44cf25b397cd3728ac Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Mon, 4 May 2026 14:58:25 +0530 Subject: [PATCH 66/66] Update rrdUnitTestRunner.cpp --- src/unittest/rrdUnitTestRunner.cpp | 32 +++++++++++++++--------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/unittest/rrdUnitTestRunner.cpp b/src/unittest/rrdUnitTestRunner.cpp index be8cad007..c050489f1 100644 --- a/src/unittest/rrdUnitTestRunner.cpp +++ b/src/unittest/rrdUnitTestRunner.cpp @@ -5922,7 +5922,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); @@ -5934,7 +5934,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}; @@ -5947,7 +5947,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}; @@ -5958,10 +5958,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"); } @@ -5969,9 +5969,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"); } @@ -5979,31 +5979,31 @@ 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, ""); } 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(NULL, 64); + 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(buf, 0); + read_suffix_from_file_to_buf("/tmp/rrd/rrd_suffix.txt",buf, 0); } 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(buf, sizeof(buf)); + read_suffix_from_file_to_buf("/tmp/rrd/rrd_suffix.txt",buf, sizeof(buf)); EXPECT_STREQ(buf, expected); } @@ -6015,7 +6015,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"); }