[v2.12]fix: handle NULL json_str case to avoid undefined behavior#2522
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR addresses a potential undefined behavior issue in the MQTT plugin by adding a NULL check for the json_str variable before using it in string operations. The fix prevents crashes or undefined behavior that could occur when the JSON string generation fails or returns NULL.
- Adds NULL pointer validation for
json_strbefore callingstrlen() - Wraps the string length calculation in a conditional block to ensure safe execution
| if (json_str != NULL) { | ||
| size = strlen(json_str); | ||
| } | ||
| } |
There was a problem hiding this comment.
The closing brace appears to be misaligned or creates unbalanced braces. The NULL check for json_str should wrap only the strlen() operation, but this closing brace suggests it may be closing an outer scope incorrectly.
| } |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## v2.12 #2522 +/- ##
==========================================
- Coverage 66.71% 66.66% -0.05%
==========================================
Files 121 121
Lines 27550 27551 +1
==========================================
- Hits 18379 18368 -11
- Misses 9171 9183 +12 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
No description provided.