From eeaae2e758a4ab0fd889d95331129ad300c25a52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Jaramago=20Fern=C3=A1ndez?= Date: Fri, 12 Jul 2024 18:54:53 +0200 Subject: [PATCH] Make 'proxy_debug_func' saves/restore 'errno' Several calls inside 'proxy_debug_func' (specially if database logging is enabled) could alter 'errno', which could influence error handling. --- include/proxysql.h | 4 ++++ lib/debug.cpp | 13 +++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/include/proxysql.h b/include/proxysql.h index 90c881d414..8b6d1d4d50 100644 --- a/include/proxysql.h +++ b/include/proxysql.h @@ -117,6 +117,10 @@ void proxy_info_(const char* msg, ...); #ifdef DEBUG void init_debug_struct(); void init_debug_struct_from_cmdline(); +/** + * @brief Add a debug entry in the error log. To be used through 'proxy_debug' macro. + * @details This function saves/restores the previous 'errno' value. + */ __attribute__((__format__ (__printf__, 7, 8))) void proxy_debug_func(enum debug_module, int, int, const char *, int, const char *, const char *, ...); void proxy_debug_get_filters(std::set&); diff --git a/lib/debug.cpp b/lib/debug.cpp index e4eda648f5..4f3755c9c0 100644 --- a/lib/debug.cpp +++ b/lib/debug.cpp @@ -131,15 +131,22 @@ void proxy_debug_load_filters(std::set& f) { //pthread_mutex_unlock(&debug_mutex); } +// REMINDER: This function should always save/restore 'errno', otherwise it could influence error handling. void proxy_debug_func(enum debug_module module, int verbosity, int thr, const char *__file, int __line, const char *__func, const char *fmt, ...) { + int saved_errno = errno; assert(module