Skip to content

[DO NOT MERGE] Dummy PR to check for coverity integration#50

Closed
sowmiyachelliah wants to merge 1 commit intodevelopfrom
feature/coverity_dummy_PR
Closed

[DO NOT MERGE] Dummy PR to check for coverity integration#50
sowmiyachelliah wants to merge 1 commit intodevelopfrom
feature/coverity_dummy_PR

Conversation

@sowmiyachelliah
Copy link
Contributor

@sowmiyachelliah sowmiyachelliah commented Feb 25, 2026

[DO NOT MERGE] Dummy PR to check for coverity integration

Copilot AI review requested due to automatic review settings February 25, 2026 07:06
@sowmiyachelliah sowmiyachelliah requested review from a team as code owners February 25, 2026 07:06
Copy link
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

This PR appears to be a dummy change set intended to validate Coverity/static-analysis integration by intentionally introducing patterns that analyzers should flag.

Changes:

  • Introduces an intentional file-handle leak on an error path in advsec_read_from_file.
  • Adds a use-after-free/NULL %s formatting issue in CosaAdvSecFetchSbConfig’s JSON parse failure path.
  • Adds an unused local variable in CosaAdvSecGetLookupTimeoutExceededCount.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

FILE *fp;
char buf[COMMAND_MAX] = {0};
// LOW IMPACT ISSUE: Unused variable declared but never used
int retry_attempts = 0;
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

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

retry_attempts is declared but never used, which will trigger an unused-variable warning (and can fail builds if warnings are treated as errors). Remove it or use it in the intended retry logic.

Suggested change
int retry_attempts = 0;

Copilot uses AI. Check for mistakes.
Comment on lines +320 to +321
// MEDIUM IMPACT ISSUE: Resource leak - file not closed in error path
//fclose(file);
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

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

The snprintf error path returns without closing file, which leaks the file descriptor/FILE* when fopen succeeded. Close the file before returning (or refactor to a single exit path that always fcloses when file is non-NULL).

Suggested change
// MEDIUM IMPACT ISSUE: Resource leak - file not closed in error path
//fclose(file);
fclose(file);

Copilot uses AI. Check for mistakes.
Comment on lines 674 to 685
json = cJSON_Parse(data);
if (data != NULL)
{
free(data);
data = NULL;
}
if( !json )
{
CcspTraceWarning(("json file parser error %s:%d\n", __FUNCTION__,__LINE__));
// HIGH IMPACT ISSUE: Use after free - data is freed above but used here
CcspTraceError(("Failed to parse JSON data: %s\n", data));
return ANSC_STATUS_FAILURE;
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

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

data is freed (and set to NULL) before this error log, but the log still formats it with %s. Passing a freed/NULL pointer to %s is undefined behavior and can crash on JSON parse failure. Log before freeing, or preserve the buffer until after all uses (or log the file path / length instead).

Copilot uses AI. Check for mistakes.
fclose(file);
// MEDIUM IMPACT ISSUE: Resource leak - file not closed in error path
//fclose(file);
return 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

Coverity Issue - Resource leak

Variable "file" going out of scope leaks the storage it points to.

High Impact, CWE-404
RESOURCE_LEAK

@github-actions github-actions bot locked and limited conversation to collaborators Feb 25, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants