X-Git-Url: https://git.openssl.org/gitweb/?a=blobdiff_plain;f=crypto%2Fo_str.c;h=a8357691ad66e9b668e28acad5f3b45eddab8fb8;hb=b998745a4596c05f673ed8acdcaedcb4c5e208ad;hp=b0e7524820ce4af5555f101ab7c5b00416482cf4;hpb=efdb2d6c797112e58e304d3e5300f169dbb16e95;p=openssl.git diff --git a/crypto/o_str.c b/crypto/o_str.c index b0e7524820..a8357691ad 100644 --- a/crypto/o_str.c +++ b/crypto/o_str.c @@ -1,5 +1,5 @@ /* - * Copyright 2003-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2003-2017 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 @@ -7,56 +7,12 @@ * https://www.openssl.org/source/license.html */ -#include +#include "e_os.h" #include -#include #include #include "internal/cryptlib.h" #include "internal/o_str.h" -#if !defined(OPENSSL_IMPLEMENTS_strncasecmp) && \ - !defined(OPENSSL_SYS_WIN32) && !defined(OPENSSL_SYS_WINCE) && \ - !defined(NETWARE_CLIB) -# include -#endif - -int OPENSSL_strncasecmp(const char *str1, const char *str2, size_t n) -{ -#if defined(OPENSSL_IMPLEMENTS_strncasecmp) - while (*str1 && *str2 && n) { - int res = toupper(*str1) - toupper(*str2); - if (res) - return res < 0 ? -1 : 1; - str1++; - str2++; - n--; - } - if (n == 0) - return 0; - if (*str1) - return 1; - if (*str2) - return -1; - return 0; -#else - /* - * Recursion hazard warning! Whenever strncasecmp is #defined as - * OPENSSL_strncasecmp, OPENSSL_IMPLEMENTS_strncasecmp must be defined as - * well. - */ - return strncasecmp(str1, str2, n); -#endif -} - -int OPENSSL_strcasecmp(const char *str1, const char *str2) -{ -#if defined(OPENSSL_IMPLEMENTS_strncasecmp) - return OPENSSL_strncasecmp(str1, str2, (size_t)-1); -#else - return strcasecmp(str1, str2); -#endif -} - int OPENSSL_memcmp(const void *v1, const void *v2, size_t n) { const unsigned char *c1 = v1, *c2 = v2; @@ -71,14 +27,12 @@ int OPENSSL_memcmp(const void *v1, const void *v2, size_t n) char *CRYPTO_strdup(const char *str, const char* file, int line) { char *ret; - size_t size; if (str == NULL) return NULL; - size = strlen(str) + 1; - ret = CRYPTO_malloc(size, file, line); + ret = CRYPTO_malloc(strlen(str) + 1, file, line); if (ret != NULL) - memcpy(ret, str, size); + strcpy(ret, str); return ret; } @@ -236,12 +190,17 @@ unsigned char *OPENSSL_hexstr2buf(const char *str, long *len) */ char *OPENSSL_buf2hexstr(const unsigned char *buffer, long len) { - const static char hexdig[] = "0123456789ABCDEF"; + static const char hexdig[] = "0123456789ABCDEF"; char *tmp, *q; 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; } @@ -265,7 +224,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