RDKB-50706 : Resolve Coverity issues in xupnp component - #11
Open
rahul012345 wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR focuses on hardening the discovery/IDM code paths by improving string safety, memory cleanup, and list/mutex handling to reduce leaks and undefined behavior.
Changes:
- Fixes unsafe string copies (bounds + explicit null termination) and a hashing bitwise-operation bug.
- Adds missing frees/cleanup in multiple discovery callbacks and config parsing paths.
- Refactors mutex usage around shared device lists and adjusts list iteration/freeing logic.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 10 comments.
| File | Description |
|---|---|
| src/xdiscovery.c | Fixes hash folding, MAC string termination, adds cleanup in callbacks, and adjusts discovery result list handling |
| src/idm_server.c | Replaces unsafe copies with bounded copies / safe CRT usage |
| src/idm_client.c | Improves string safety, adds mutex protection for shared list access, and adjusts TLS interaction return behavior |
| broadband/lib/src/xcal-device-library.c | Adds missing frees, improves pipe read handling, and strengthens parsing/error cleanup |
Comments suppressed due to low confidence (1)
src/idm_client.c:1
- The mutex is locked at line 588 but never unlocked on the success path (returns
TRUEat line 619). This will deadlock other threads attempting to accessxdevlist. Ensureg_mutex_unlock(mutex);is executed on all return paths (e.g., unlock just beforereturn TRUE;or use a single exit path).
/*
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+303
to
+305
| errno_t rc = -1; | ||
| strncpy(interface,Interface,IPv4_ADDR_SIZE-1); | ||
| interface[IPv4_ADDR_SIZE-1] = '0'; |
Comment on lines
+629
to
630
| g_mutex_unlock(mutex); | ||
| return FALSE; |
Comment on lines
378
to
383
| { | ||
| g_tls_connection_set_certificate (connection, cert); | ||
| g_object_unref (cert); | ||
| return G_TLS_INTERACTION_HANDLED; | ||
| } | ||
| return G_TLS_INTERACTION_FAILED; | ||
| return G_TLS_INTERACTION_HANDLED; | ||
| } |
Comment on lines
+3374
to
+3380
| GList *element, *element_root; | ||
| element_root = element = g_list_first(xdevlistDup); | ||
| if(element_root == NULL) { | ||
| g_string_free(localOutputContents, TRUE); | ||
| g_string_free(logDevicesList, TRUE); | ||
| return FALSE; | ||
| } |
Comment on lines
+3508
to
3511
| if(element_root) | ||
| g_list_free(element_root); | ||
| if(xdevlistDup) | ||
| g_list_free(xdevlistDup); |
Comment on lines
+415
to
417
| short index, pindex, tindex; | ||
|
|
||
| if (((index = dpnode_lookup(ipaddr, macaddr, &stat, &pindex)) >= 0) && (index != DP_WLIST_ERROR)) |
| { | ||
| int rvalue=0; | ||
| if(!(dc_obj->interface)||(dc_obj->port)==0||(dc_obj->discovery_interval)==0||(dc_obj->loss_detection_window)==0) | ||
| if((dc_obj->interface[0]=='\0')||(dc_obj->port)==0||(dc_obj->discovery_interval)==0||(dc_obj->loss_detection_window)==0) |
Comment on lines
865
to
868
| while(element) | ||
| { | ||
| GwyDeviceData *gwydata = element->data; | ||
| g_mutex_lock(mutex); | ||
| xdevlist = g_list_remove_link(xdevlist,element); |
Comment on lines
884
to
885
| element = g_list_next(element); | ||
| } |
| g_string_printf(data, "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x", mac[0], mac[1], mac[2], | ||
| mac[3], mac[4], mac[5]); | ||
| return data->str; | ||
| return g_string_free(data, FALSE);; |
Reason for change: Fixing the coverity issue Test Procedure: Locally tested Risks: Low Signed-off-by:rahul.sharma4@sky.uk
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reason for change: Fixing the coverity issue
Test Procedure: Locally tested
Risks: Low
Signed-off-by:rahul.sharma4@sky.uk