Add support to test_ssl_new for testing with DTLS over SCTP
[openssl.git] / crypto / o_str.c
index 29c324f4746de061a9d6b702f7130fbee479827a..d8516c27bbbede979a5d428fca1ec8be63765ed6 100644 (file)
@@ -198,7 +198,12 @@ char *OPENSSL_buf2hexstr(const unsigned char *buffer, long len)
     const unsigned char *p;
     int i;
 
-    if ((tmp = OPENSSL_malloc(len * 3 + 1)) == NULL) {
+    if (len == 0)
+    {
+        return OPENSSL_zalloc(1);
+    }
+
+    if ((tmp = OPENSSL_malloc(len * 3)) == NULL) {
         CRYPTOerr(CRYPTO_F_OPENSSL_BUF2HEXSTR, ERR_R_MALLOC_FAILURE);
         return NULL;
     }
@@ -222,7 +227,8 @@ int openssl_strerror_r(int errnum, char *buf, size_t buflen)
     return !strerror_s(buf, buflen, errnum);
 #elif defined(_GNU_SOURCE)
     return strerror_r(errnum, buf, buflen) != NULL;
-#elif (_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600)
+#elif (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112L) || \
+      (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE >= 600)
     /*
      * We can use "real" strerror_r. The OpenSSL version differs in that it
      * gives 1 on success and 0 on failure for consistency with other OpenSSL