aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/o_str.c
diff options
context:
space:
mode:
authorJung-uk Kim <jkim@FreeBSD.org>2019-05-28 20:08:17 +0000
committerJung-uk Kim <jkim@FreeBSD.org>2019-05-28 20:08:17 +0000
commit375b8e6770f750fb915859470f6f1fe43f35cc48 (patch)
tree5db6744924edfc112439ad2366f52f246baa21d1 /crypto/o_str.c
parent851f7386fd78b9787f4f6669ad271886a2a003f1 (diff)
downloadsrc-375b8e6770f750fb915859470f6f1fe43f35cc48.tar.gz
src-375b8e6770f750fb915859470f6f1fe43f35cc48.zip
Import OpenSSL 1.1.1c.vendor/openssl/1.1.1c
Notes
Notes: svn path=/vendor-crypto/openssl/dist/; revision=348333 svn path=/vendor-crypto/openssl/1.1.1c/; revision=348334; tag=vendor/openssl/1.1.1c
Diffstat (limited to 'crypto/o_str.c')
-rw-r--r--crypto/o_str.c27
1 files changed, 23 insertions, 4 deletions
diff --git a/crypto/o_str.c b/crypto/o_str.c
index a8357691ad66..1dbd70d58c4d 100644
--- a/crypto/o_str.c
+++ b/crypto/o_str.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2003-2017 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2003-2019 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
@@ -223,7 +223,26 @@ int openssl_strerror_r(int errnum, char *buf, size_t buflen)
#if defined(_MSC_VER) && _MSC_VER>=1400
return !strerror_s(buf, buflen, errnum);
#elif defined(_GNU_SOURCE)
- return strerror_r(errnum, buf, buflen) != NULL;
+ char *err;
+
+ /*
+ * GNU strerror_r may not actually set buf.
+ * It can return a pointer to some (immutable) static string in which case
+ * buf is left unused.
+ */
+ err = strerror_r(errnum, buf, buflen);
+ if (err == NULL)
+ return 0;
+ /*
+ * If err is statically allocated, err != buf and we need to copy the data.
+ * If err points somewhere inside buf, OPENSSL_strlcpy can handle this,
+ * since src and dest are not annotated with __restrict and the function
+ * reads src byte for byte and writes to dest.
+ * If err == buf we do not have to copy anything.
+ */
+ if (err != buf)
+ OPENSSL_strlcpy(buf, err, buflen);
+ return 1;
#elif (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112L) || \
(defined(_XOPEN_SOURCE) && _XOPEN_SOURCE >= 600)
/*
@@ -234,6 +253,7 @@ int openssl_strerror_r(int errnum, char *buf, size_t buflen)
return !strerror_r(errnum, buf, buflen);
#else
char *err;
+
/* Fall back to non-thread safe strerror()...its all we can do */
if (buflen < 2)
return 0;
@@ -241,8 +261,7 @@ int openssl_strerror_r(int errnum, char *buf, size_t buflen)
/* Can this ever happen? */
if (err == NULL)
return 0;
- strncpy(buf, err, buflen - 1);
- buf[buflen - 1] = '\0';
+ OPENSSL_strlcpy(buf, err, buflen);
return 1;
#endif
}