mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-26 15:50:07 +01:00
all: reimplement g_strstrip() macro to avoid Coverity warning
Coverity has issues with functions that handle ownership like
g_strstrip(). Thus the scan is full of false positives like:
Error: RESOURCE_LEAK (CWE-772): [#def45] [important]
NetworkManager-1.31.5/src/core/devices/wwan/nm-service-providers.c:134: alloc_fn: Storage is returned from allocation function "g_strdup".
NetworkManager-1.31.5/src/core/devices/wwan/nm-service-providers.c:134: noescape: Resource "g_strdup(attribute_values[i])" is not freed or pointed-to in "g_strchug".
NetworkManager-1.31.5/src/core/devices/wwan/nm-service-providers.c:134: leaked_storage: Failing to save or free storage allocated by "g_strdup(attribute_values[i])" leaks it.
# 132| if (strcmp(attribute_names[i], "value") == 0) {
# 133| parse_context->state = PARSER_METHOD_GSM_APN;
# 134|-> parse_context->apn = g_strstrip(g_strdup(attribute_values[i]));
# 135| break;
# 136| }
Add a workaround for that.
There are other functions that have the same problem, but the usage
g_strstrip(g_strdup(...)) is common to warrant a special workaround.
This commit is contained in:
parent
9154f0128a
commit
8fcbbdd7a4
1 changed files with 14 additions and 0 deletions
|
|
@ -693,4 +693,18 @@ _nm_g_cancellable_reset(GCancellable *cancellable);
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
/* Coverity gets confused by g_strstrip(g_strdup(foo)). Reimplement the macro
|
||||
* in a way that hopefully works better to avoid the false positive. */
|
||||
#undef g_strstrip
|
||||
#define g_strstrip(str) \
|
||||
({ \
|
||||
char *const _str = (str); \
|
||||
\
|
||||
g_strchug(_str); \
|
||||
g_strchomp(_str); \
|
||||
_str; \
|
||||
})
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
#endif /* __NM_GLIB_H__ */
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue