diff options
Diffstat (limited to 'src/lib/libcrypto/buffer')
-rw-r--r-- | src/lib/libcrypto/buffer/Makefile.ssl | 2 | ||||
-rw-r--r-- | src/lib/libcrypto/buffer/buffer.c | 57 | ||||
-rw-r--r-- | src/lib/libcrypto/buffer/buffer.h | 9 |
3 files changed, 67 insertions, 1 deletions
diff --git a/src/lib/libcrypto/buffer/Makefile.ssl b/src/lib/libcrypto/buffer/Makefile.ssl index 240a6b9a89..b131ca3078 100644 --- a/src/lib/libcrypto/buffer/Makefile.ssl +++ b/src/lib/libcrypto/buffer/Makefile.ssl | |||
@@ -68,7 +68,7 @@ lint: | |||
68 | lint -DLINT $(INCLUDES) $(SRC)>fluff | 68 | lint -DLINT $(INCLUDES) $(SRC)>fluff |
69 | 69 | ||
70 | depend: | 70 | depend: |
71 | $(MAKEDEPEND) $(CFLAG) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC) | 71 | $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC) |
72 | 72 | ||
73 | dclean: | 73 | dclean: |
74 | $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | 74 | $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new |
diff --git a/src/lib/libcrypto/buffer/buffer.c b/src/lib/libcrypto/buffer/buffer.c index 9299baba9e..d96487e7db 100644 --- a/src/lib/libcrypto/buffer/buffer.c +++ b/src/lib/libcrypto/buffer/buffer.c | |||
@@ -125,6 +125,43 @@ int BUF_MEM_grow(BUF_MEM *str, int len) | |||
125 | return(len); | 125 | return(len); |
126 | } | 126 | } |
127 | 127 | ||
128 | int BUF_MEM_grow_clean(BUF_MEM *str, int len) | ||
129 | { | ||
130 | char *ret; | ||
131 | unsigned int n; | ||
132 | |||
133 | if (str->length >= len) | ||
134 | { | ||
135 | memset(&str->data[len],0,str->length-len); | ||
136 | str->length=len; | ||
137 | return(len); | ||
138 | } | ||
139 | if (str->max >= len) | ||
140 | { | ||
141 | memset(&str->data[str->length],0,len-str->length); | ||
142 | str->length=len; | ||
143 | return(len); | ||
144 | } | ||
145 | n=(len+3)/3*4; | ||
146 | if (str->data == NULL) | ||
147 | ret=OPENSSL_malloc(n); | ||
148 | else | ||
149 | ret=OPENSSL_realloc_clean(str->data,str->max,n); | ||
150 | if (ret == NULL) | ||
151 | { | ||
152 | BUFerr(BUF_F_BUF_MEM_GROW,ERR_R_MALLOC_FAILURE); | ||
153 | len=0; | ||
154 | } | ||
155 | else | ||
156 | { | ||
157 | str->data=ret; | ||
158 | str->max=n; | ||
159 | memset(&str->data[str->length],0,len-str->length); | ||
160 | str->length=len; | ||
161 | } | ||
162 | return(len); | ||
163 | } | ||
164 | |||
128 | char *BUF_strdup(const char *str) | 165 | char *BUF_strdup(const char *str) |
129 | { | 166 | { |
130 | char *ret; | 167 | char *ret; |
@@ -143,3 +180,23 @@ char *BUF_strdup(const char *str) | |||
143 | return(ret); | 180 | return(ret); |
144 | } | 181 | } |
145 | 182 | ||
183 | size_t BUF_strlcpy(char *dst, const char *src, size_t size) | ||
184 | { | ||
185 | size_t l = 0; | ||
186 | for(; size > 1 && *src; size--) | ||
187 | { | ||
188 | *dst++ = *src++; | ||
189 | l++; | ||
190 | } | ||
191 | if (size) | ||
192 | *dst = '\0'; | ||
193 | return l + strlen(src); | ||
194 | } | ||
195 | |||
196 | size_t BUF_strlcat(char *dst, const char *src, size_t size) | ||
197 | { | ||
198 | size_t l = 0; | ||
199 | for(; size > 0 && *dst; size--, dst++) | ||
200 | l++; | ||
201 | return l + BUF_strlcpy(dst, src, size); | ||
202 | } | ||
diff --git a/src/lib/libcrypto/buffer/buffer.h b/src/lib/libcrypto/buffer/buffer.h index 11e2d0359a..465dc34f3f 100644 --- a/src/lib/libcrypto/buffer/buffer.h +++ b/src/lib/libcrypto/buffer/buffer.h | |||
@@ -63,6 +63,9 @@ | |||
63 | extern "C" { | 63 | extern "C" { |
64 | #endif | 64 | #endif |
65 | 65 | ||
66 | #include <stddef.h> | ||
67 | #include <sys/types.h> | ||
68 | |||
66 | typedef struct buf_mem_st | 69 | typedef struct buf_mem_st |
67 | { | 70 | { |
68 | int length; /* current number of bytes */ | 71 | int length; /* current number of bytes */ |
@@ -73,8 +76,14 @@ typedef struct buf_mem_st | |||
73 | BUF_MEM *BUF_MEM_new(void); | 76 | BUF_MEM *BUF_MEM_new(void); |
74 | void BUF_MEM_free(BUF_MEM *a); | 77 | void BUF_MEM_free(BUF_MEM *a); |
75 | int BUF_MEM_grow(BUF_MEM *str, int len); | 78 | int BUF_MEM_grow(BUF_MEM *str, int len); |
79 | int BUF_MEM_grow_clean(BUF_MEM *str, int len); | ||
76 | char * BUF_strdup(const char *str); | 80 | char * BUF_strdup(const char *str); |
77 | 81 | ||
82 | /* safe string functions */ | ||
83 | size_t BUF_strlcpy(char *dst,const char *src,size_t siz); | ||
84 | size_t BUF_strlcat(char *dst,const char *src,size_t siz); | ||
85 | |||
86 | |||
78 | /* BEGIN ERROR CODES */ | 87 | /* BEGIN ERROR CODES */ |
79 | /* The following lines are auto generated by the script mkerr.pl. Any changes | 88 | /* The following lines are auto generated by the script mkerr.pl. Any changes |
80 | * made after this point may be overwritten when the script is next run. | 89 | * made after this point may be overwritten when the script is next run. |