From 209ca5f83995b1624a479449515352bd2e959d51 Mon Sep 17 00:00:00 2001 From: Michal Privoznik Date: Wed, 21 May 2025 18:14:38 +0200 Subject: [PATCH] libvirt_nss: Allocate buffer in ERROR() dynamically MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Jiri Denemark Reviewed-by: Ján Tomko --- tools/nss/libvirt_nss.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tools/nss/libvirt_nss.h b/tools/nss/libvirt_nss.h index a43731de45..84db044409 100644 --- a/tools/nss/libvirt_nss.h +++ b/tools/nss/libvirt_nss.h @@ -35,14 +35,18 @@ #if 0 # include # include +# include # define NULLSTR(s) ((s) ? (s) : "") # 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); \ 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) -- 2.47.2