Skip to content

Feature/fileissue#191

Open
Abhinavpv28 wants to merge 66 commits intodevelopfrom
feature/fileissue
Open

Feature/fileissue#191
Abhinavpv28 wants to merge 66 commits intodevelopfrom
feature/fileissue

Conversation

@Abhinavpv28
Copy link
Copy Markdown
Contributor

No description provided.

Abhinavpv28 and others added 30 commits May 3, 2026 19:13
…d 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>
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>
Co-authored-by: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 4, 2026 07:17
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 4, 2026

Code Coverage Summary

                               Total:|83.0%   6176|97.2%  1615|    -      0

Comment thread src/rrdJsonParser.c
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

Comment thread src/rrdEventProcess.c
Comment on lines +98 to +110
/* 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_DEBUG, LOG_REMDEBUG, "[%s:%d]: [DEBUG] Persisting suffix: '%s' from input: '%s' (index=%d)\n", __FUNCTION__, __LINE__, local_suffix, cmdMap[index], index);
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
{
RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: [DEBUG] Not persisting suffix for input: '%s' (index=%d)\n", __FUNCTION__, __LINE__, cmdMap[index], index);
}
Comment thread src/unittest/rrdUnitTestRunner.cpp Outdated
Comment thread src/rrdJsonParser.c
Comment thread src/rrdJsonParser.c
Copilot AI review requested due to automatic review settings May 4, 2026 07:33
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 4, 2026

Code Coverage Summary

                               Total:|83.0%   6176|97.2%  1615|    -      0

Comment thread src/rrdJsonParser.c Outdated
}
return -1;
}
ssize_t written = write(tmpfd, suffix + total_written, (ssize_t)to_write);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverity Issue - Overflowed integer argument

"(ssize_t)to_write", which might have underflowed, is passed to "write(tmpfd, suffix + total_written, (ssize_t)to_write)".

High Impact, CWE-190
INTEGER_OVERFLOW

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

Comment thread src/rrdJsonParser.c
Comment thread src/rrdEventProcess.c
dataMsgLen = strlen(cmdMap[index]) + 1;
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));
Comment thread src/rrdEventProcess.c
}
else
{
RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: [DEBUG] Not persisting suffix for input: '%s' (index=%d)\n", __FUNCTION__, __LINE__, cmdMap[index], index);
Comment thread src/rrdJsonParser.c
Comment thread src/unittest/rrdUnitTestRunner.cpp
Comment thread src/rrdJsonParser.c Outdated
}
return -1;
}
ssize_t written = write(tmpfd, suffix + total_written, (ssize_t)to_write);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverity Issue - Overflowed integer argument

"(ssize_t)to_write", which might have underflowed, is passed to "write(tmpfd, suffix + total_written, (ssize_t)to_write)".

High Impact, CWE-190
INTEGER_OVERFLOW

Copilot AI review requested due to automatic review settings May 4, 2026 08:13
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 4, 2026

Code Coverage Summary

                               Total:|82.8%   6189|97.2%  1615|    -      0

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

Comment thread src/unittest/rrdUnitTestRunner.cpp
Comment thread src/rrdJsonParser.c
Comment on lines 30 to +75
@@ -46,6 +52,225 @@ 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_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_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;
}
Comment thread src/rrdJsonParser.c
Comment on lines +111 to +114
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);
Comment thread src/rrdEventProcess.c
Comment on lines 82 to +110
@@ -88,9 +91,23 @@ void processIssueTypeEvent(data_buf *rbuf)
}
cmdBuff->appendMode = rbuf->appendMode;
cmdBuff->mdata = (char *)calloc(1, dataMsgLen);
/* Suffix is now persisted via file, no struct field needed */
if (cmdBuff->mdata)
{
strncpy((char *)cmdBuff->mdata, cmdMap[index], 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_DEBUG, LOG_REMDEBUG, "[%s:%d]: [DEBUG] Persisting suffix: '%s' from input: '%s' (index=%d)\n", __FUNCTION__, __LINE__, local_suffix, cmdMap[index], index);
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
{
RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: [DEBUG] Not persisting suffix for input: '%s' (index=%d)\n", __FUNCTION__, __LINE__, cmdMap[index], index);
}
Copilot AI review requested due to automatic review settings May 4, 2026 08:24
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 4, 2026

Code Coverage Summary

                               Total:|82.8%   6189|97.2%  1615|    -      0

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

Comment thread src/unittest/rrdUnitTestRunner.cpp
Comment thread src/rrdJsonParser.c
Comment on lines +56 to +76
int persist_suffix_to_file(const char *suffix) {
struct stat st;
uid_t uid = getuid();
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_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;
}
Comment thread src/rrdEventProcess.c
Comment on lines 82 to 111
@@ -88,9 +91,23 @@ void processIssueTypeEvent(data_buf *rbuf)
}
cmdBuff->appendMode = rbuf->appendMode;
cmdBuff->mdata = (char *)calloc(1, dataMsgLen);
/* Suffix is now persisted via file, no struct field needed */
if (cmdBuff->mdata)
{
strncpy((char *)cmdBuff->mdata, cmdMap[index], 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_DEBUG, LOG_REMDEBUG, "[%s:%d]: [DEBUG] Persisting suffix: '%s' from input: '%s' (index=%d)\n", __FUNCTION__, __LINE__, local_suffix, cmdMap[index], index);
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
{
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);
Comment thread src/rrdJsonParser.c
/* 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);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverity Issue - Logically dead code

Execution cannot reach this statement: "rdk_logger_msg_printf(RDK_L...".

Medium Impact, CWE-561
DEADCODE

Comment thread src/rrdJsonParser.c
}
return -1;
}
ssize_t written = write(tmpfd, suffix + total_written, write_len);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverity Issue - Overflowed integer argument

"write_len", which might have underflowed, is passed to "write(tmpfd, suffix + total_written, write_len)".

High Impact, CWE-190
INTEGER_OVERFLOW

Comment thread src/rrdJsonParser.c
/* 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);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverity Issue - Logically dead code

Execution cannot reach this statement: "rdk_logger_msg_printf(RDK_L...".

Medium Impact, CWE-561
DEADCODE

Comment thread src/rrdJsonParser.c
}
return -1;
}
ssize_t written = write(tmpfd, suffix + total_written, write_len);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverity Issue - Overflowed integer argument

"write_len", which might have underflowed, is passed to "write(tmpfd, suffix + total_written, write_len)".

High Impact, CWE-190
INTEGER_OVERFLOW

Copilot AI review requested due to automatic review settings May 4, 2026 09:28
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

Comment on lines +5923 to +5928
TEST_F(SuffixUtilsTest, PersistSuffix_NormalValue)
{
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);
Comment on lines +5961 to +5965
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("/tmp/rrd/rrd_suffix.txt",buf, sizeof(buf));
EXPECT_STREQ(buf, "_NewSuffix");
Comment thread src/rrdJsonParser.c
#include <fcntl.h>
#include <ctype.h>
#include <errno.h>
#include <limits.h>
Comment thread src/rrdJsonParser.c
Comment on lines +31 to +32
#define RRD_SUFFIX_DIR "/tmp/rrd"
#define RRD_SUFFIX_PATH "/tmp/rrd/rrd_suffix.txt"
Comment thread src/rrdEventProcess.c
}
else
{
RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: [DEBUG] Not persisting suffix for input: '%s' (index=%d)\n", __FUNCTION__, __LINE__, cmdMap[index], index);
Comment thread src/rrdJsonParser.c
/* 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);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverity Issue - Logically dead code

Execution cannot reach this statement: "rdk_logger_msg_printf(RDK_L...".

Medium Impact, CWE-561
DEADCODE

Comment thread src/rrdJsonParser.c
}
return -1;
}
ssize_t written = write(tmpfd, suffix + total_written, write_len);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverity Issue - Overflowed integer argument

"write_len", which might have underflowed, is passed to "write(tmpfd, suffix + total_written, write_len)".

High Impact, CWE-190
INTEGER_OVERFLOW

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants