diff options
Diffstat (limited to '')
| -rw-r--r-- | src/lib/libcrypto/buffer/buf_err.c | 12 | ||||
| -rw-r--r-- | src/lib/libcrypto/buffer/buffer.c | 31 | ||||
| -rw-r--r-- | src/lib/libcrypto/buffer/buffer.h | 17 |
3 files changed, 46 insertions, 14 deletions
diff --git a/src/lib/libcrypto/buffer/buf_err.c b/src/lib/libcrypto/buffer/buf_err.c index 1fc32a6861..3e25bbe879 100644 --- a/src/lib/libcrypto/buffer/buf_err.c +++ b/src/lib/libcrypto/buffer/buf_err.c | |||
| @@ -70,9 +70,12 @@ | |||
| 70 | 70 | ||
| 71 | static ERR_STRING_DATA BUF_str_functs[]= | 71 | static ERR_STRING_DATA BUF_str_functs[]= |
| 72 | { | 72 | { |
| 73 | {ERR_FUNC(BUF_F_BUF_MEMDUP), "BUF_memdup"}, | ||
| 73 | {ERR_FUNC(BUF_F_BUF_MEM_GROW), "BUF_MEM_grow"}, | 74 | {ERR_FUNC(BUF_F_BUF_MEM_GROW), "BUF_MEM_grow"}, |
| 75 | {ERR_FUNC(BUF_F_BUF_MEM_GROW_CLEAN), "BUF_MEM_grow_clean"}, | ||
| 74 | {ERR_FUNC(BUF_F_BUF_MEM_NEW), "BUF_MEM_new"}, | 76 | {ERR_FUNC(BUF_F_BUF_MEM_NEW), "BUF_MEM_new"}, |
| 75 | {ERR_FUNC(BUF_F_BUF_STRDUP), "BUF_strdup"}, | 77 | {ERR_FUNC(BUF_F_BUF_STRDUP), "BUF_strdup"}, |
| 78 | {ERR_FUNC(BUF_F_BUF_STRNDUP), "BUF_strndup"}, | ||
| 76 | {0,NULL} | 79 | {0,NULL} |
| 77 | }; | 80 | }; |
| 78 | 81 | ||
| @@ -85,15 +88,12 @@ static ERR_STRING_DATA BUF_str_reasons[]= | |||
| 85 | 88 | ||
| 86 | void ERR_load_BUF_strings(void) | 89 | void ERR_load_BUF_strings(void) |
| 87 | { | 90 | { |
| 88 | static int init=1; | 91 | #ifndef OPENSSL_NO_ERR |
| 89 | 92 | ||
| 90 | if (init) | 93 | if (ERR_func_error_string(BUF_str_functs[0].error) == NULL) |
| 91 | { | 94 | { |
| 92 | init=0; | ||
| 93 | #ifndef OPENSSL_NO_ERR | ||
| 94 | ERR_load_strings(0,BUF_str_functs); | 95 | ERR_load_strings(0,BUF_str_functs); |
| 95 | ERR_load_strings(0,BUF_str_reasons); | 96 | ERR_load_strings(0,BUF_str_reasons); |
| 96 | #endif | ||
| 97 | |||
| 98 | } | 97 | } |
| 98 | #endif | ||
| 99 | } | 99 | } |
diff --git a/src/lib/libcrypto/buffer/buffer.c b/src/lib/libcrypto/buffer/buffer.c index d96487e7db..3bf03c7eff 100644 --- a/src/lib/libcrypto/buffer/buffer.c +++ b/src/lib/libcrypto/buffer/buffer.c | |||
| @@ -149,7 +149,7 @@ int BUF_MEM_grow_clean(BUF_MEM *str, int len) | |||
| 149 | ret=OPENSSL_realloc_clean(str->data,str->max,n); | 149 | ret=OPENSSL_realloc_clean(str->data,str->max,n); |
| 150 | if (ret == NULL) | 150 | if (ret == NULL) |
| 151 | { | 151 | { |
| 152 | BUFerr(BUF_F_BUF_MEM_GROW,ERR_R_MALLOC_FAILURE); | 152 | BUFerr(BUF_F_BUF_MEM_GROW_CLEAN,ERR_R_MALLOC_FAILURE); |
| 153 | len=0; | 153 | len=0; |
| 154 | } | 154 | } |
| 155 | else | 155 | else |
| @@ -164,22 +164,41 @@ int BUF_MEM_grow_clean(BUF_MEM *str, int len) | |||
| 164 | 164 | ||
| 165 | char *BUF_strdup(const char *str) | 165 | char *BUF_strdup(const char *str) |
| 166 | { | 166 | { |
| 167 | if (str == NULL) return(NULL); | ||
| 168 | return BUF_strndup(str, strlen(str)); | ||
| 169 | } | ||
| 170 | |||
| 171 | char *BUF_strndup(const char *str, size_t siz) | ||
| 172 | { | ||
| 167 | char *ret; | 173 | char *ret; |
| 168 | int n; | ||
| 169 | 174 | ||
| 170 | if (str == NULL) return(NULL); | 175 | if (str == NULL) return(NULL); |
| 171 | 176 | ||
| 172 | n=strlen(str); | 177 | ret=OPENSSL_malloc(siz+1); |
| 173 | ret=OPENSSL_malloc(n+1); | ||
| 174 | if (ret == NULL) | 178 | if (ret == NULL) |
| 175 | { | 179 | { |
| 176 | BUFerr(BUF_F_BUF_STRDUP,ERR_R_MALLOC_FAILURE); | 180 | BUFerr(BUF_F_BUF_STRNDUP,ERR_R_MALLOC_FAILURE); |
| 177 | return(NULL); | 181 | return(NULL); |
| 178 | } | 182 | } |
| 179 | memcpy(ret,str,n+1); | 183 | BUF_strlcpy(ret,str,siz+1); |
| 180 | return(ret); | 184 | return(ret); |
| 181 | } | 185 | } |
| 182 | 186 | ||
| 187 | void *BUF_memdup(const void *data, size_t siz) | ||
| 188 | { | ||
| 189 | void *ret; | ||
| 190 | |||
| 191 | if (data == NULL) return(NULL); | ||
| 192 | |||
| 193 | ret=OPENSSL_malloc(siz); | ||
| 194 | if (ret == NULL) | ||
| 195 | { | ||
| 196 | BUFerr(BUF_F_BUF_MEMDUP,ERR_R_MALLOC_FAILURE); | ||
| 197 | return(NULL); | ||
| 198 | } | ||
| 199 | return memcpy(ret, data, siz); | ||
| 200 | } | ||
| 201 | |||
| 183 | size_t BUF_strlcpy(char *dst, const char *src, size_t size) | 202 | size_t BUF_strlcpy(char *dst, const char *src, size_t size) |
| 184 | { | 203 | { |
| 185 | size_t l = 0; | 204 | size_t l = 0; |
diff --git a/src/lib/libcrypto/buffer/buffer.h b/src/lib/libcrypto/buffer/buffer.h index 465dc34f3f..1db9607450 100644 --- a/src/lib/libcrypto/buffer/buffer.h +++ b/src/lib/libcrypto/buffer/buffer.h | |||
| @@ -59,25 +59,35 @@ | |||
| 59 | #ifndef HEADER_BUFFER_H | 59 | #ifndef HEADER_BUFFER_H |
| 60 | #define HEADER_BUFFER_H | 60 | #define HEADER_BUFFER_H |
| 61 | 61 | ||
| 62 | #include <openssl/ossl_typ.h> | ||
| 63 | |||
| 62 | #ifdef __cplusplus | 64 | #ifdef __cplusplus |
| 63 | extern "C" { | 65 | extern "C" { |
| 64 | #endif | 66 | #endif |
| 65 | 67 | ||
| 66 | #include <stddef.h> | 68 | #include <stddef.h> |
| 69 | |||
| 70 | #if !defined(NO_SYS_TYPES_H) | ||
| 67 | #include <sys/types.h> | 71 | #include <sys/types.h> |
| 72 | #endif | ||
| 73 | |||
| 74 | /* Already declared in ossl_typ.h */ | ||
| 75 | /* typedef struct buf_mem_st BUF_MEM; */ | ||
| 68 | 76 | ||
| 69 | typedef struct buf_mem_st | 77 | struct buf_mem_st |
| 70 | { | 78 | { |
| 71 | int length; /* current number of bytes */ | 79 | int length; /* current number of bytes */ |
| 72 | char *data; | 80 | char *data; |
| 73 | int max; /* size of buffer */ | 81 | int max; /* size of buffer */ |
| 74 | } BUF_MEM; | 82 | }; |
| 75 | 83 | ||
| 76 | BUF_MEM *BUF_MEM_new(void); | 84 | BUF_MEM *BUF_MEM_new(void); |
| 77 | void BUF_MEM_free(BUF_MEM *a); | 85 | void BUF_MEM_free(BUF_MEM *a); |
| 78 | int BUF_MEM_grow(BUF_MEM *str, int len); | 86 | int BUF_MEM_grow(BUF_MEM *str, int len); |
| 79 | int BUF_MEM_grow_clean(BUF_MEM *str, int len); | 87 | int BUF_MEM_grow_clean(BUF_MEM *str, int len); |
| 80 | char * BUF_strdup(const char *str); | 88 | char * BUF_strdup(const char *str); |
| 89 | char * BUF_strndup(const char *str, size_t siz); | ||
| 90 | void * BUF_memdup(const void *data, size_t siz); | ||
| 81 | 91 | ||
| 82 | /* safe string functions */ | 92 | /* safe string functions */ |
| 83 | size_t BUF_strlcpy(char *dst,const char *src,size_t siz); | 93 | size_t BUF_strlcpy(char *dst,const char *src,size_t siz); |
| @@ -93,9 +103,12 @@ void ERR_load_BUF_strings(void); | |||
| 93 | /* Error codes for the BUF functions. */ | 103 | /* Error codes for the BUF functions. */ |
| 94 | 104 | ||
| 95 | /* Function codes. */ | 105 | /* Function codes. */ |
| 106 | #define BUF_F_BUF_MEMDUP 103 | ||
| 96 | #define BUF_F_BUF_MEM_GROW 100 | 107 | #define BUF_F_BUF_MEM_GROW 100 |
| 108 | #define BUF_F_BUF_MEM_GROW_CLEAN 105 | ||
| 97 | #define BUF_F_BUF_MEM_NEW 101 | 109 | #define BUF_F_BUF_MEM_NEW 101 |
| 98 | #define BUF_F_BUF_STRDUP 102 | 110 | #define BUF_F_BUF_STRDUP 102 |
| 111 | #define BUF_F_BUF_STRNDUP 104 | ||
| 99 | 112 | ||
| 100 | /* Reason codes. */ | 113 | /* Reason codes. */ |
| 101 | 114 | ||
