From: Michal Privoznik Date: Wed, 21 May 2025 16:14:38 +0000 (+0200) Subject: libvirt_nss: Allocate buffer in ERROR() dynamically X-Git-Tag: v11.4.0-rc1~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=209ca5f83995b1624a479449515352bd2e959d51;p=thirdparty%2Flibvirt.git libvirt_nss: Allocate buffer in ERROR() dynamically 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 --- 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)