Guarantees of gpg_strerror_r may not hold
NIIBE Yutaka
gniibe at fsij.org
Wed Nov 30 04:38:13 CET 2022
Hello,
John Scott via Gnupg-devel <gnupg-devel at gnupg.org> wrote:
> That means that if the caller didn't initialize their buffer, there is
> a risk of their buffer starting with uninitialized memory, something
> the GPGME docs say won't happen.
Thank you for your suggestion.
To be consistent to other parts of the code, something like this is more
appropriate, I suppose.
==========================
diff --git a/src/strerror.c b/src/strerror.c
index fb1bebf..51e57d8 100644
--- a/src/strerror.c
+++ b/src/strerror.c
@@ -96,7 +96,21 @@ system_strerror_r (int no, char *buf, size_t buflen)
static int
system_strerror_r (int no, char *buf, size_t buflen)
{
- return strerror_r (no, buf, buflen);
+ int saved_errno;
+ int r = strerror_r (no, buf, buflen);
+
+ if (r)
+ {
+ if (r < 0)
+ saved_errno = errno;
+ else
+ saved_errno = r;
+
+ snprintf (buf, buflen, "strerror_r failed: %i\n", r);
+ return saved_errno;
+ }
+
+ return 0;
}
#endif /* STRERROR_R_CHAR_P */
--
More information about the Gnupg-devel
mailing list