diff options
Diffstat (limited to 'src/lib/libcrypto/buffer/buf_str.c')
| -rw-r--r-- | src/lib/libcrypto/buffer/buf_str.c | 111 |
1 files changed, 54 insertions, 57 deletions
diff --git a/src/lib/libcrypto/buffer/buf_str.c b/src/lib/libcrypto/buffer/buf_str.c index ab5535f476..c884d20c66 100644 --- a/src/lib/libcrypto/buffer/buf_str.c +++ b/src/lib/libcrypto/buffer/buf_str.c | |||
| @@ -5,21 +5,21 @@ | |||
| 5 | * This package is an SSL implementation written | 5 | * This package is an SSL implementation written |
| 6 | * by Eric Young (eay@cryptsoft.com). | 6 | * by Eric Young (eay@cryptsoft.com). |
| 7 | * The implementation was written so as to conform with Netscapes SSL. | 7 | * The implementation was written so as to conform with Netscapes SSL. |
| 8 | * | 8 | * |
| 9 | * This library is free for commercial and non-commercial use as long as | 9 | * This library is free for commercial and non-commercial use as long as |
| 10 | * the following conditions are aheared to. The following conditions | 10 | * the following conditions are aheared to. The following conditions |
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | 11 | * apply to all code found in this distribution, be it the RC4, RSA, |
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation |
| 13 | * included with this distribution is covered by the same copyright terms | 13 | * included with this distribution is covered by the same copyright terms |
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). |
| 15 | * | 15 | * |
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | 16 | * Copyright remains Eric Young's, and as such any Copyright notices in |
| 17 | * the code are not to be removed. | 17 | * the code are not to be removed. |
| 18 | * If this package is used in a product, Eric Young should be given attribution | 18 | * If this package is used in a product, Eric Young should be given attribution |
| 19 | * as the author of the parts of the library used. | 19 | * as the author of the parts of the library used. |
| 20 | * This can be in the form of a textual message at program startup or | 20 | * This can be in the form of a textual message at program startup or |
| 21 | * in documentation (online or textual) provided with the package. | 21 | * in documentation (online or textual) provided with the package. |
| 22 | * | 22 | * |
| 23 | * Redistribution and use in source and binary forms, with or without | 23 | * Redistribution and use in source and binary forms, with or without |
| 24 | * modification, are permitted provided that the following conditions | 24 | * modification, are permitted provided that the following conditions |
| 25 | * are met: | 25 | * are met: |
| @@ -34,10 +34,10 @@ | |||
| 34 | * Eric Young (eay@cryptsoft.com)" | 34 | * Eric Young (eay@cryptsoft.com)" |
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | 35 | * The word 'cryptographic' can be left out if the rouines from the library |
| 36 | * being used are not cryptographic related :-). | 36 | * being used are not cryptographic related :-). |
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | 37 | * 4. If you include any Windows specific code (or a derivative thereof) from |
| 38 | * the apps directory (application code) you must include an acknowledgement: | 38 | * the apps directory (application code) you must include an acknowledgement: |
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" |
| 40 | * | 40 | * |
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND |
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| @@ -49,71 +49,68 @@ | |||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 51 | * SUCH DAMAGE. | 51 | * SUCH DAMAGE. |
| 52 | * | 52 | * |
| 53 | * The licence and distribution terms for any publically available version or | 53 | * The licence and distribution terms for any publically available version or |
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be |
| 55 | * copied and put under another distribution licence | 55 | * copied and put under another distribution licence |
| 56 | * [including the GNU Public Licence.] | 56 | * [including the GNU Public Licence.] |
| 57 | */ | 57 | */ |
| 58 | 58 | ||
| 59 | #include <stdlib.h> | ||
| 59 | #include <stdio.h> | 60 | #include <stdio.h> |
| 61 | #include <string.h> | ||
| 60 | #include "cryptlib.h" | 62 | #include "cryptlib.h" |
| 61 | #include <openssl/buffer.h> | 63 | #include <openssl/buffer.h> |
| 62 | 64 | ||
| 63 | char *BUF_strdup(const char *str) | 65 | /* |
| 64 | { | 66 | * XXX these functions accept a NULL arg and return NULL |
| 65 | if (str == NULL) return(NULL); | 67 | * when the standard ones do not. we should at an appropriate |
| 66 | return BUF_strndup(str, strlen(str)); | 68 | * time change these to find the bad callers |
| 67 | } | 69 | */ |
| 68 | |||
| 69 | char *BUF_strndup(const char *str, size_t siz) | ||
| 70 | { | ||
| 71 | char *ret; | ||
| 72 | |||
| 73 | if (str == NULL) return(NULL); | ||
| 74 | 70 | ||
| 75 | ret=malloc(siz+1); | 71 | char * |
| 76 | if (ret == NULL) | 72 | BUF_strdup(const char *str) |
| 77 | { | 73 | { |
| 78 | BUFerr(BUF_F_BUF_STRNDUP,ERR_R_MALLOC_FAILURE); | 74 | char *ret = NULL; |
| 79 | return(NULL); | 75 | if (str != NULL) { |
| 80 | } | 76 | if (!(ret = strdup(str))) |
| 81 | BUF_strlcpy(ret,str,siz+1); | 77 | BUFerr(BUF_F_BUF_STRDUP,ERR_R_MALLOC_FAILURE); |
| 82 | return(ret); | ||
| 83 | } | 78 | } |
| 79 | return ret; | ||
| 80 | } | ||
| 84 | 81 | ||
| 85 | void *BUF_memdup(const void *data, size_t siz) | 82 | char * |
| 86 | { | 83 | BUF_strndup(const char *str, size_t siz) |
| 87 | void *ret; | 84 | { |
| 88 | 85 | char *ret = NULL; | |
| 89 | if (data == NULL) return(NULL); | 86 | if (str != NULL) { |
| 90 | 87 | if (!(ret = strndup(str, siz))) | |
| 91 | ret=malloc(siz); | 88 | BUFerr(BUF_F_BUF_STRNDUP,ERR_R_MALLOC_FAILURE); |
| 92 | if (ret == NULL) | ||
| 93 | { | ||
| 94 | BUFerr(BUF_F_BUF_MEMDUP,ERR_R_MALLOC_FAILURE); | ||
| 95 | return(NULL); | ||
| 96 | } | ||
| 97 | return memcpy(ret, data, siz); | ||
| 98 | } | ||
| 99 | |||
| 100 | size_t BUF_strlcpy(char *dst, const char *src, size_t size) | ||
| 101 | { | ||
| 102 | size_t l = 0; | ||
| 103 | for(; size > 1 && *src; size--) | ||
| 104 | { | ||
| 105 | *dst++ = *src++; | ||
| 106 | l++; | ||
| 107 | } | ||
| 108 | if (size) | ||
| 109 | *dst = '\0'; | ||
| 110 | return l + strlen(src); | ||
| 111 | } | 89 | } |
| 90 | return ret; | ||
| 91 | } | ||
| 112 | 92 | ||
| 113 | size_t BUF_strlcat(char *dst, const char *src, size_t size) | 93 | void * |
| 114 | { | 94 | BUF_memdup(const void *data, size_t siz) |
| 115 | size_t l = 0; | 95 | { |
| 116 | for(; size > 0 && *dst; size--, dst++) | 96 | void *ret = NULL; |
| 117 | l++; | 97 | if (data != NULL) { |
| 118 | return l + BUF_strlcpy(dst, src, size); | 98 | if (!(ret = malloc(siz))) |
| 99 | BUFerr(BUF_F_BUF_MEMDUP,ERR_R_MALLOC_FAILURE); | ||
| 100 | else | ||
| 101 | (void) memcpy(ret, data, siz); | ||
| 119 | } | 102 | } |
| 103 | return ret; | ||
| 104 | } | ||
| 105 | |||
| 106 | size_t | ||
| 107 | BUF_strlcpy(char *dst, const char *src, size_t size) | ||
| 108 | { | ||
| 109 | return strlcpy(dst, src, size); | ||
| 110 | } | ||
| 111 | |||
| 112 | size_t | ||
| 113 | BUF_strlcat(char *dst, const char *src, size_t size) | ||
| 114 | { | ||
| 115 | return strlcat(dst, src, size); | ||
| 116 | } | ||
