From: Michal Privoznik Date: Thu, 18 Apr 2024 07:25:07 +0000 (+0200) Subject: libvirt_nss: Fix ERROR() macro X-Git-Tag: v10.3.0-rc1~36 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=753064963ce35434c91e3b6ae6bfcd1754197db2;p=thirdparty%2Flibvirt.git libvirt_nss: Fix ERROR() macro The purpose of ERROR() macro in our NSS module is to print error message provided as arguments followed by error string corresponding to errno. Historically, we've used strerror_r() for that (please note, we want our NSS module to be free of libvirt internal functions, or glib even - hence, g_strerror() is off the table). Now strerror_r() is documented as: Returns ... a pointer to a string that the function stores in buf, or a pointer to some (immutable) static string (in which case buf is unused). Therefore, we can't rely the string being stored in the buf and really need to store the retval and print that instead. While touching this area, decrease the ebuf size, since its current size (1KiB) is triggering our stack limit (2KiB) in some cases. Signed-off-by: Michal Privoznik Reviewed-by: Peter Krempa --- diff --git a/tools/nss/libvirt_nss.h b/tools/nss/libvirt_nss.h index 2bb313f329..5f356618f3 100644 --- a/tools/nss/libvirt_nss.h +++ b/tools/nss/libvirt_nss.h @@ -37,11 +37,11 @@ # define NULLSTR(s) ((s) ? (s) : "") # define ERROR(...) \ do { \ - char ebuf[1024]; \ - strerror_r(errno, ebuf, sizeof(ebuf)); \ + char ebuf[512]; \ + const char *errmsg = strerror_r(errno, ebuf, sizeof(ebuf)); \ fprintf(stderr, "ERROR %s:%d : ", __FUNCTION__, __LINE__); \ fprintf(stderr, __VA_ARGS__); \ - fprintf(stderr, " : %s\n", ebuf); \ + fprintf(stderr, " : %s\n", errmsg); \ fprintf(stderr, "\n"); \ } while (0)