On a Thursday in 2025, Michal Privoznik via Devel wrote:
From: Michal Privoznik <mprivozn(a)redhat.com>
So far, inside of the ERROR() macro there's pretty large buffer
allocated on the stack (for use by strerror_r()). Problem is,
with our current stack size limit of 2048 bytes we may come
pretty close to the limit or even overshoot it, e.g. in aiforaf()
where the function itself declares another stack allocated buffer
1024 bytes long.
Just allocate the buffer dynamically.
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
tools/nss/libvirt_nss.h | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/tools/nss/libvirt_nss.h b/tools/nss/libvirt_nss.h
index a43731de45..54a0216013 100644
--- a/tools/nss/libvirt_nss.h
+++ b/tools/nss/libvirt_nss.h
@@ -35,14 +35,17 @@
#if 0
# include <errno.h>
# include <stdio.h>
+# include <string.h>
# define NULLSTR(s) ((s) ? (s) : "<null>")
# define ERROR(...) \
do { \
- char ebuf[512]; \
- const char *errmsg = strerror_r(errno, ebuf, sizeof(ebuf)); \
+ int saved_errno = errno; \
+ const size_t ebuf_size = 512; \
+ g_autofree char *ebuf = calloc(ebuf_size, sizeof(*ebuf)); \
+ if (ebuf) strerror_r(saved_errno, ebuf, ebuf_size); \
Please put the body of the if on a separate line.
fprintf(stderr, "ERROR %s:%d : ", __FUNCTION__,
__LINE__); \
fprintf(stderr, __VA_ARGS__); \
- fprintf(stderr, " : %s\n", errmsg); \
+ fprintf(stderr, " : %s\n", NULLSTR(ebuf)); \
fprintf(stderr, "\n"); \
} while (0)
Reviewed-by: Ján Tomko <jtomko(a)redhat.com>
Jano