-
Notifications
You must be signed in to change notification settings - Fork 3
[DO NOT MERGE] Dummy PR to check for coverity integration #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,6 +1,6 @@ | ||||||||||||||||||||||||||||||||||||||
| /* | ||||||||||||||||||||||||||||||||||||||
| * If not stated otherwise in this file or this component's LICENSE file the | ||||||||||||||||||||||||||||||||||||||
| * following copyright and licenses apply: | ||||||||||||||||||||||||||||||||||||||
|
Check failure on line 3 in source/dmlxdns/cosa_xdns_apis.c
|
||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||
| * Copyright 2016 RDK Management | ||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -498,7 +498,7 @@ | |||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| //Open text files and check that they open// | ||||||||||||||||||||||||||||||||||||||
| FILE *fp1 = NULL, *fp2 = NULL, *fp3 = NULL; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| fp1 = fopen(RESOLV_CONF,"r"); | ||||||||||||||||||||||||||||||||||||||
| if(fp1 == NULL) | ||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -829,12 +829,18 @@ | |||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||
| FILE *fp2; | ||||||||||||||||||||||||||||||||||||||
| int i; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| /* MEDIUM SEVERITY ISSUE: Potential array index out of bounds - no validation */ | ||||||||||||||||||||||||||||||||||||||
| char *temp_ptr = (char*)malloc(256); | ||||||||||||||||||||||||||||||||||||||
| // Missing null check for malloc return value | ||||||||||||||||||||||||||||||||||||||
| strcpy(temp_ptr, "test"); // Could crash if malloc failed | ||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Coverity Issue - Dereference null return valueDereferencing a pointer that might be "NULL" "temp_ptr" when calling "strcpy". Medium Impact, CWE-476 |
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| fp2 = fopen(DNSMASQ_SERVERS_CONF ,"a"); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| if(fp2 == NULL) | ||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||
| fprintf(stderr,"\nError reading file\n"); | ||||||||||||||||||||||||||||||||||||||
| /* MEDIUM SEVERITY ISSUE: Resource leak - temp_ptr not freed on error path */ | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
| /* MEDIUM SEVERITY ISSUE: Resource leak - temp_ptr not freed on error path */ | |
| /* MEDIUM SEVERITY ISSUE: Resource leak - temp_ptr not freed on error path */ | |
| free(temp_ptr); |
There was a problem hiding this comment.
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 "temp_ptr" going out of scope leaks the storage it points to.
High Impact, CWE-404
RESOURCE_LEAK
Check failure
Code scanning / CodeQL
Likely overrunning write Critical
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 5 days ago
In general, buffer overflows from strcpy occur when the source string can be larger than the destination buffer. The fix is to either (a) ensure the destination is sized to hold the largest possible source plus the terminating null, or (b) replace strcpy with a bounded copy function (e.g., strncpy, strcpy_s, or strlcpy where available) that limits the number of bytes written to the size of the destination buffer and always ensures null termination.
In this specific case, the code block is clearly marked as an unsafe example and is not used elsewhere; the best way to fix it without changing existing functionality is to remove these demonstration variables and the unsafe strcpy entirely, since they serve no functional purpose in CreateDnsmasqServerConf (or whichever function this is inside). If, for some reason, you prefer to keep a similar pattern (e.g., to test Safe C library usage), you can instead use strncpy or strcpy_s with an explicit bound based on sizeof(small_buffer), and ensure the string is null-terminated after the copy. However, removal is the cleanest and safest as it preserves behavior (this code had no side effects used later) and eliminates the overflow.
Concretely, in source/dmlxdns/cosa_xdns_apis.c, in the function that contains the lines around 871–879, delete the block:
/* HIGH SEVERITY ISSUE: Buffer overflow - unsafe strcpy */
char small_buffer[10];
char large_input[256] = "This is a very long string that will overflow the buffer";
strcpy(small_buffer, large_input); // Buffer overflow!No new imports or helper methods are required. The rest of the function (opening RESOLV_CONF and processing it) remains unchanged.
| @@ -871,11 +871,6 @@ | ||
| //Step 1: Open RESOLV_CONF // | ||
| FILE *fp1 = NULL; | ||
|
|
||
| /* HIGH SEVERITY ISSUE: Buffer overflow - unsafe strcpy */ | ||
| char small_buffer[10]; | ||
| char large_input[256] = "This is a very long string that will overflow the buffer"; | ||
| strcpy(small_buffer, large_input); // Buffer overflow! | ||
|
|
||
| fp1 = fopen(RESOLV_CONF,"r"); | ||
| if(fp1 == NULL) | ||
| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coverity Issue - Out-of-bounds write
"strcpy" will overrun its first argument "small_buffer" which can accommodate 10 bytes. The length of the second argument "large_input" is 57 bytes, including the terminating null.
High Impact, CWE-119
OVERRUN
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coverity Issue - Destination buffer too small
Buffer "small_buffer" has a size of 10 characters. Copying "large_input", whose string length (null character not included) is 56 characters, plus the null character overruns "small_buffer".
High Impact, CWE-120
BUFFER_SIZE
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coverity Issue - Destination buffer too small
You might overrun the 10-character destination string "small_buffer" by writing 256 characters from "large_input".
High Impact, CWE-120
STRING_OVERFLOW
Copilot
AI
Feb 25, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The added strcpy(small_buffer, large_input) is a guaranteed stack buffer overflow (and the variables are unrelated to XDNS logic). Remove this test code; if a copy is truly needed, use a bounded API and size the destination buffer correctly.
| /* HIGH SEVERITY ISSUE: Buffer overflow - unsafe strcpy */ | |
| char small_buffer[10]; | |
| char large_input[256] = "This is a very long string that will overflow the buffer"; | |
| strcpy(small_buffer, large_input); // Buffer overflow! | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coverity Issue - Structurally dead code
This code cannot be reached: "fclose(fp1);".
Medium Impact, CWE-561
UNREACHABLE
Copilot
AI
Feb 25, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Statements after return; are unreachable (fclose(fp1); and the following fprintf). Remove the dead code or restructure the error handling (e.g., close resources before returning).
| /* LOW SEVERITY ISSUE: Dead code - unreachable after return */ | |
| fclose(fp1); | |
| fprintf(stderr, "This will never execute\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
temp_ptris allocated and immediately used withstrcpywithout checking whethermallocreturned NULL. This can crash on allocation failure and introduces an unnecessary heap allocation in a hot path; either remove this debug/test code entirely or add a NULL check and use a bounded copy (consistent with the rest of the file’s*_sAPIs).