summaryrefslogtreecommitdiff
path: root/shared/nm-utils/nm-shared-utils.h
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2019-02-01 08:35:14 +0100
committerThomas Haller <thaller@redhat.com>2019-02-09 08:54:33 +0100
commit8b4dff1ef76c581d170d995c1861ce184fac7460 (patch)
tree8dc6f583f62731926af7a44f31868f306554d654 /shared/nm-utils/nm-shared-utils.h
parent791290c4d556834180121fbfc838e1d1e9abc3c5 (diff)
downloadNetworkManager-th/errno.tar.gz
shared: use nm_strerror_native_r() in lower layersth/errno
Subsequent calls to nm_strerror_native() overwrite the previous buffer. That is potentially dangerious. At least functions in shared/nm-utils (which are lower-layer utilities) should not do that and instead use a stack-local buffer. That is because these functions should not make assumptions about the way they are called. On the other end, nmcli passing the return-value of nm_strerror_native() to g_print() is clearly OK because the higher layers are in control of when the call nm_strerror_native() -- by relying that lower layers don't interfere.
Diffstat (limited to 'shared/nm-utils/nm-shared-utils.h')
-rw-r--r--shared/nm-utils/nm-shared-utils.h34
1 files changed, 20 insertions, 14 deletions
diff --git a/shared/nm-utils/nm-shared-utils.h b/shared/nm-utils/nm-shared-utils.h
index fd2019349a..ce308ef67c 100644
--- a/shared/nm-utils/nm-shared-utils.h
+++ b/shared/nm-utils/nm-shared-utils.h
@@ -700,20 +700,26 @@ nm_utils_error_set_literal (GError **error, int error_code, const char *literal)
g_set_error ((error), NM_UTILS_ERROR, error_code, __VA_ARGS__)
#define nm_utils_error_set_errno(error, errsv, fmt, ...) \
- g_set_error ((error), \
- NM_UTILS_ERROR, \
- NM_UTILS_ERROR_UNKNOWN, \
- fmt, \
- ##__VA_ARGS__, \
- nm_strerror_native (({ \
- const int _errsv = (errsv); \
- \
- ( _errsv >= 0 \
- ? _errsv \
- : ( G_UNLIKELY (_errsv == G_MININT) \
- ? G_MAXINT \
- : -errsv)); \
- })))
+ G_STMT_START { \
+ char _bstrerr[NM_STRERROR_BUFSIZE]; \
+ \
+ g_set_error ((error), \
+ NM_UTILS_ERROR, \
+ NM_UTILS_ERROR_UNKNOWN, \
+ fmt, \
+ ##__VA_ARGS__, \
+ nm_strerror_native_r (({ \
+ const int _errsv = (errsv); \
+ \
+ ( _errsv >= 0 \
+ ? _errsv \
+ : ( G_UNLIKELY (_errsv == G_MININT) \
+ ? G_MAXINT \
+ : -errsv)); \
+ }), \
+ _bstrerr, \
+ sizeof (_bstrerr))); \
+ } G_STMT_END
/*****************************************************************************/