summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjsing <>2014-04-25 14:53:22 +0000
committerjsing <>2014-04-25 14:53:22 +0000
commit9e2c15719af6fc163b5e97a71322756690aa23cb (patch)
tree8194cc05b7da9fa51d02b66ec4de04fe48449691
parentb920e7e98a5d2b30203b95ec54add40c78f511ba (diff)
downloadopenbsd-9e2c15719af6fc163b5e97a71322756690aa23cb.tar.gz
openbsd-9e2c15719af6fc163b5e97a71322756690aa23cb.tar.bz2
openbsd-9e2c15719af6fc163b5e97a71322756690aa23cb.zip
KNF.
-rw-r--r--src/lib/libcrypto/txt_db/txt_db.c485
-rw-r--r--src/lib/libcrypto/txt_db/txt_db.h21
-rw-r--r--src/lib/libssl/src/crypto/txt_db/txt_db.c485
-rw-r--r--src/lib/libssl/src/crypto/txt_db/txt_db.h21
4 files changed, 502 insertions, 510 deletions
diff --git a/src/lib/libcrypto/txt_db/txt_db.c b/src/lib/libcrypto/txt_db/txt_db.c
index c1e7a79a1a..69fd2ba5bf 100644
--- a/src/lib/libcrypto/txt_db/txt_db.c
+++ b/src/lib/libcrypto/txt_db/txt_db.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,7 +49,7 @@
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
@@ -66,323 +66,320 @@
66#undef BUFSIZE 66#undef BUFSIZE
67#define BUFSIZE 512 67#define BUFSIZE 512
68 68
69const char TXT_DB_version[]="TXT_DB" OPENSSL_VERSION_PTEXT; 69const char TXT_DB_version[] = "TXT_DB" OPENSSL_VERSION_PTEXT;
70 70
71TXT_DB *TXT_DB_read(BIO *in, int num) 71TXT_DB *
72 { 72TXT_DB_read(BIO *in, int num)
73 TXT_DB *ret=NULL; 73{
74 int er=1; 74 TXT_DB *ret = NULL;
75 int esc=0; 75 int er = 1;
76 long ln=0; 76 int esc = 0;
77 int i,add,n; 77 long ln = 0;
78 int size=BUFSIZE; 78 int i, add, n;
79 int offset=0; 79 int size = BUFSIZE;
80 char *p,*f; 80 int offset = 0;
81 char *p, *f;
81 OPENSSL_STRING *pp; 82 OPENSSL_STRING *pp;
82 BUF_MEM *buf=NULL; 83 BUF_MEM *buf = NULL;
83 84
84 if ((buf=BUF_MEM_new()) == NULL) goto err; 85 if ((buf = BUF_MEM_new()) == NULL)
85 if (!BUF_MEM_grow(buf,size)) goto err; 86 goto err;
87 if (!BUF_MEM_grow(buf, size))
88 goto err;
86 89
87 if ((ret=malloc(sizeof(TXT_DB))) == NULL) 90 if ((ret = malloc(sizeof(TXT_DB))) == NULL)
88 goto err; 91 goto err;
89 ret->num_fields=num; 92 ret->num_fields = num;
90 ret->index=NULL; 93 ret->index = NULL;
91 ret->qual=NULL; 94 ret->qual = NULL;
92 if ((ret->data=sk_OPENSSL_PSTRING_new_null()) == NULL) 95 if ((ret->data = sk_OPENSSL_PSTRING_new_null()) == NULL)
93 goto err; 96 goto err;
94 if ((ret->index=malloc(sizeof(*ret->index)*num)) == NULL) 97 if ((ret->index = malloc(sizeof(*ret->index)*num)) == NULL)
95 goto err; 98 goto err;
96 if ((ret->qual=malloc(sizeof(*(ret->qual))*num)) == NULL) 99 if ((ret->qual = malloc(sizeof(*(ret->qual))*num)) == NULL)
97 goto err; 100 goto err;
98 for (i=0; i<num; i++) 101 for (i = 0; i < num; i++) {
99 { 102 ret->index[i] = NULL;
100 ret->index[i]=NULL; 103 ret->qual[i] = NULL;
101 ret->qual[i]=NULL; 104 }
102 }
103 105
104 add=(num+1)*sizeof(char *); 106 add = (num + 1)*sizeof(char *);
105 buf->data[size-1]='\0'; 107 buf->data[size-1] = '\0';
106 offset=0; 108 offset = 0;
107 for (;;) 109 for (;;) {
108 { 110 if (offset != 0) {
109 if (offset != 0) 111 size += BUFSIZE;
110 { 112 if (!BUF_MEM_grow_clean(buf, size))
111 size+=BUFSIZE; 113 goto err;
112 if (!BUF_MEM_grow_clean(buf,size)) goto err; 114 }
113 } 115 buf->data[offset] = '\0';
114 buf->data[offset]='\0'; 116 BIO_gets(in, &(buf->data[offset]), size - offset);
115 BIO_gets(in,&(buf->data[offset]),size-offset);
116 ln++; 117 ln++;
117 if (buf->data[offset] == '\0') break; 118 if (buf->data[offset] == '\0')
118 if ((offset == 0) && (buf->data[0] == '#')) continue; 119 break;
119 i=strlen(&(buf->data[offset])); 120 if ((offset == 0) && (buf->data[0] == '#'))
120 offset+=i; 121 continue;
122 i = strlen(&(buf->data[offset]));
123 offset += i;
121 if (buf->data[offset-1] != '\n') 124 if (buf->data[offset-1] != '\n')
122 continue; 125 continue;
123 else 126 else {
124 { 127 buf->data[offset-1] = '\0'; /* blat the '\n' */
125 buf->data[offset-1]='\0'; /* blat the '\n' */ 128 if (!(p = malloc(add + offset)))
126 if (!(p=malloc(add+offset))) goto err; 129 goto err;
127 offset=0; 130 offset = 0;
128 } 131 }
129 pp=(char **)p; 132 pp = (char **)p;
130 p+=add; 133 p += add;
131 n=0; 134 n = 0;
132 pp[n++]=p; 135 pp[n++] = p;
133 i=0; 136 i = 0;
134 f=buf->data; 137 f = buf->data;
135 138
136 esc=0; 139 esc = 0;
137 for (;;) 140 for (;;) {
138 { 141 if (*f == '\0')
139 if (*f == '\0') break; 142 break;
140 if (*f == '\t') 143 if (*f == '\t') {
141 {
142 if (esc) 144 if (esc)
143 p--; 145 p--;
144 else 146 else {
145 {
146 *(p++)='\0'; 147 *(p++)='\0';
147 f++; 148 f++;
148 if (n >= num) break; 149 if (n >= num)
149 pp[n++]=p; 150 break;
151 pp[n++] = p;
150 continue; 152 continue;
151 }
152 } 153 }
154 }
153 esc=(*f == '\\'); 155 esc=(*f == '\\');
154 *(p++)= *(f++); 156 *(p++)= *(f++);
155 } 157 }
156 *(p++)='\0'; 158 *(p++)='\0';
157 if ((n != num) || (*f != '\0')) 159 if ((n != num) || (*f != '\0')) {
158 {
159#if !defined(OPENSSL_NO_STDIO) && !defined(OPENSSL_SYS_WIN16) /* temporary fix :-( */ 160#if !defined(OPENSSL_NO_STDIO) && !defined(OPENSSL_SYS_WIN16) /* temporary fix :-( */
160 fprintf(stderr,"wrong number of fields on line %ld (looking for field %d, got %d, '%s' left)\n",ln,num,n,f); 161 fprintf(stderr, "wrong number of fields on line %ld (looking for field %d, got %d, '%s' left)\n",ln,num,n,f);
161#endif 162#endif
162 er=2; 163 er = 2;
163 goto err; 164 goto err;
164 } 165 }
165 pp[n]=p; 166 pp[n] = p;
166 if (!sk_OPENSSL_PSTRING_push(ret->data,pp)) 167 if (!sk_OPENSSL_PSTRING_push(ret->data, pp)) {
167 {
168#if !defined(OPENSSL_NO_STDIO) && !defined(OPENSSL_SYS_WIN16) /* temporary fix :-( */ 168#if !defined(OPENSSL_NO_STDIO) && !defined(OPENSSL_SYS_WIN16) /* temporary fix :-( */
169 fprintf(stderr,"failure in sk_push\n"); 169 fprintf(stderr, "failure in sk_push\n");
170#endif 170#endif
171 er=2; 171 er = 2;
172 goto err; 172 goto err;
173 }
174 } 173 }
175 er=0; 174 }
175 er = 0;
176
176err: 177err:
177 BUF_MEM_free(buf); 178 BUF_MEM_free(buf);
178 if (er) 179 if (er) {
179 {
180#if !defined(OPENSSL_NO_STDIO) && !defined(OPENSSL_SYS_WIN16) 180#if !defined(OPENSSL_NO_STDIO) && !defined(OPENSSL_SYS_WIN16)
181 if (er == 1) fprintf(stderr,"malloc failure\n"); 181 if (er == 1)
182 fprintf(stderr, "malloc failure\n");
182#endif 183#endif
183 if (ret != NULL) 184 if (ret != NULL) {
184 { 185 if (ret->data != NULL)
185 if (ret->data != NULL) sk_OPENSSL_PSTRING_free(ret->data); 186 sk_OPENSSL_PSTRING_free(ret->data);
186 if (ret->index != NULL) free(ret->index); 187 if (ret->index != NULL)
187 if (ret->qual != NULL) free(ret->qual); 188 free(ret->index);
188 if (ret != NULL) free(ret); 189 if (ret->qual != NULL)
189 } 190 free(ret->qual);
190 return(NULL); 191 if (ret != NULL)
192 free(ret);
191 } 193 }
192 else 194 return (NULL);
193 return(ret); 195 } else
194 } 196 return (ret);
197}
195 198
196OPENSSL_STRING *TXT_DB_get_by_index(TXT_DB *db, int idx, OPENSSL_STRING *value) 199OPENSSL_STRING *
197 { 200TXT_DB_get_by_index(TXT_DB *db, int idx, OPENSSL_STRING *value)
201{
198 OPENSSL_STRING *ret; 202 OPENSSL_STRING *ret;
199 LHASH_OF(OPENSSL_STRING) *lh; 203 LHASH_OF(OPENSSL_STRING) *lh;
200 204
201 if (idx >= db->num_fields) 205 if (idx >= db->num_fields) {
202 { 206 db->error = DB_ERROR_INDEX_OUT_OF_RANGE;
203 db->error=DB_ERROR_INDEX_OUT_OF_RANGE; 207 return (NULL);
204 return(NULL); 208 }
205 } 209 lh = db->index[idx];
206 lh=db->index[idx]; 210 if (lh == NULL) {
207 if (lh == NULL) 211 db->error = DB_ERROR_NO_INDEX;
208 { 212 return (NULL);
209 db->error=DB_ERROR_NO_INDEX;
210 return(NULL);
211 }
212 ret=lh_OPENSSL_STRING_retrieve(lh,value);
213 db->error=DB_ERROR_OK;
214 return(ret);
215 } 213 }
214 ret = lh_OPENSSL_STRING_retrieve(lh, value);
215 db->error = DB_ERROR_OK;
216 return (ret);
217}
216 218
217int TXT_DB_create_index(TXT_DB *db, int field, int (*qual)(OPENSSL_STRING *), 219int
218 LHASH_HASH_FN_TYPE hash, LHASH_COMP_FN_TYPE cmp) 220TXT_DB_create_index(TXT_DB *db, int field, int (*qual)(OPENSSL_STRING *),
219 { 221 LHASH_HASH_FN_TYPE hash, LHASH_COMP_FN_TYPE cmp)
222{
220 LHASH_OF(OPENSSL_STRING) *idx; 223 LHASH_OF(OPENSSL_STRING) *idx;
221 OPENSSL_STRING *r; 224 OPENSSL_STRING *r;
222 int i,n; 225 int i, n;
223 226
224 if (field >= db->num_fields) 227 if (field >= db->num_fields) {
225 { 228 db->error = DB_ERROR_INDEX_OUT_OF_RANGE;
226 db->error=DB_ERROR_INDEX_OUT_OF_RANGE; 229 return (0);
227 return(0); 230 }
228 }
229 /* FIXME: we lose type checking at this point */ 231 /* FIXME: we lose type checking at this point */
230 if ((idx=(LHASH_OF(OPENSSL_STRING) *)lh_new(hash,cmp)) == NULL) 232 if ((idx = (LHASH_OF(OPENSSL_STRING) *)lh_new(hash, cmp)) == NULL) {
231 { 233 db->error = DB_ERROR_MALLOC;
232 db->error=DB_ERROR_MALLOC; 234 return (0);
233 return(0); 235 }
234 } 236 n = sk_OPENSSL_PSTRING_num(db->data);
235 n=sk_OPENSSL_PSTRING_num(db->data); 237 for (i = 0; i < n; i++) {
236 for (i=0; i<n; i++) 238 r = sk_OPENSSL_PSTRING_value(db->data, i);
237 { 239 if ((qual != NULL) && (qual(r) == 0))
238 r=sk_OPENSSL_PSTRING_value(db->data,i); 240 continue;
239 if ((qual != NULL) && (qual(r) == 0)) continue; 241 if ((r = lh_OPENSSL_STRING_insert(idx, r)) != NULL) {
240 if ((r=lh_OPENSSL_STRING_insert(idx,r)) != NULL) 242 db->error = DB_ERROR_INDEX_CLASH;
241 { 243 db->arg1 = sk_OPENSSL_PSTRING_find(db->data, r);
242 db->error=DB_ERROR_INDEX_CLASH; 244 db->arg2 = i;
243 db->arg1=sk_OPENSSL_PSTRING_find(db->data,r);
244 db->arg2=i;
245 lh_OPENSSL_STRING_free(idx); 245 lh_OPENSSL_STRING_free(idx);
246 return(0); 246 return (0);
247 }
248 } 247 }
249 if (db->index[field] != NULL) lh_OPENSSL_STRING_free(db->index[field]);
250 db->index[field]=idx;
251 db->qual[field]=qual;
252 return(1);
253 } 248 }
249 if (db->index[field] != NULL)
250 lh_OPENSSL_STRING_free(db->index[field]);
251 db->index[field] = idx;
252 db->qual[field] = qual;
253 return (1);
254}
254 255
255long TXT_DB_write(BIO *out, TXT_DB *db) 256long
256 { 257TXT_DB_write(BIO *out, TXT_DB *db)
257 long i,j,n,nn,l,tot=0; 258{
258 char *p,**pp,*f; 259 long i, j,n, nn, l, tot = 0;
259 BUF_MEM *buf=NULL; 260 char *p, **pp, *f;
260 long ret= -1; 261 BUF_MEM *buf = NULL;
262 long ret = -1;
261 263
262 if ((buf=BUF_MEM_new()) == NULL) 264 if ((buf = BUF_MEM_new()) == NULL)
263 goto err; 265 goto err;
264 n=sk_OPENSSL_PSTRING_num(db->data); 266 n = sk_OPENSSL_PSTRING_num(db->data);
265 nn=db->num_fields; 267 nn = db->num_fields;
266 for (i=0; i<n; i++) 268 for (i = 0; i < n; i++) {
267 { 269 pp = sk_OPENSSL_PSTRING_value(db->data, i);
268 pp=sk_OPENSSL_PSTRING_value(db->data,i);
269 270
270 l=0; 271 l = 0;
271 for (j=0; j<nn; j++) 272 for (j = 0; j < nn; j++) {
272 {
273 if (pp[j] != NULL) 273 if (pp[j] != NULL)
274 l+=strlen(pp[j]); 274 l += strlen(pp[j]);
275 } 275 }
276 if (!BUF_MEM_grow_clean(buf,(int)(l*2+nn))) goto err; 276 if (!BUF_MEM_grow_clean(buf, (int)(l*2 + nn)))
277 goto err;
277 278
278 p=buf->data; 279 p = buf->data;
279 for (j=0; j<nn; j++) 280 for (j = 0; j < nn; j++) {
280 { 281 f = pp[j];
281 f=pp[j];
282 if (f != NULL) 282 if (f != NULL)
283 for (;;) 283 for (;;) {
284 { 284 if (*f == '\0')
285 if (*f == '\0') break; 285 break;
286 if (*f == '\t') *(p++)='\\'; 286 if (*f == '\t')
287 *(p++)= *(f++); 287 *(p++) = '\\';
288 } 288 *(p++) = *(f++);
289 *(p++)='\t'; 289 }
290 } 290 *(p++) = '\t';
291 p[-1]='\n';
292 j=p-buf->data;
293 if (BIO_write(out,buf->data,(int)j) != j)
294 goto err;
295 tot+=j;
296 } 291 }
297 ret=tot; 292 p[-1] = '\n';
298err: 293 j = p - buf->data;
299 if (buf != NULL) BUF_MEM_free(buf); 294 if (BIO_write(out, buf->data, (int)j) != j)
300 return(ret); 295 goto err;
296 tot += j;
301 } 297 }
298 ret = tot;
302 299
303int TXT_DB_insert(TXT_DB *db, OPENSSL_STRING *row) 300err:
304 { 301 if (buf != NULL)
302 BUF_MEM_free(buf);
303 return (ret);
304}
305
306int
307TXT_DB_insert(TXT_DB *db, OPENSSL_STRING *row)
308{
305 int i; 309 int i;
306 OPENSSL_STRING *r; 310 OPENSSL_STRING *r;
307 311
308 for (i=0; i<db->num_fields; i++) 312 for (i = 0; i < db->num_fields; i++) {
309 { 313 if (db->index[i] != NULL) {
310 if (db->index[i] != NULL) 314 if ((db->qual[i] != NULL) && (db->qual[i](row) == 0))
311 { 315 continue;
312 if ((db->qual[i] != NULL) && 316 r = lh_OPENSSL_STRING_retrieve(db->index[i], row);
313 (db->qual[i](row) == 0)) continue; 317 if (r != NULL) {
314 r=lh_OPENSSL_STRING_retrieve(db->index[i],row); 318 db->error = DB_ERROR_INDEX_CLASH;
315 if (r != NULL) 319 db->arg1 = i;
316 { 320 db->arg_row = r;
317 db->error=DB_ERROR_INDEX_CLASH;
318 db->arg1=i;
319 db->arg_row=r;
320 goto err; 321 goto err;
321 }
322 } 322 }
323 } 323 }
324 }
324 /* We have passed the index checks, now just append and insert */ 325 /* We have passed the index checks, now just append and insert */
325 if (!sk_OPENSSL_PSTRING_push(db->data,row)) 326 if (!sk_OPENSSL_PSTRING_push(db->data, row)) {
326 { 327 db->error = DB_ERROR_MALLOC;
327 db->error=DB_ERROR_MALLOC;
328 goto err; 328 goto err;
329 } 329 }
330 330
331 for (i=0; i<db->num_fields; i++) 331 for (i = 0; i < db->num_fields; i++) {
332 { 332 if (db->index[i] != NULL) {
333 if (db->index[i] != NULL) 333 if ((db->qual[i] != NULL) && (db->qual[i](row) == 0))
334 { 334 continue;
335 if ((db->qual[i] != NULL) && 335 (void)lh_OPENSSL_STRING_insert(db->index[i], row);
336 (db->qual[i](row) == 0)) continue;
337 (void)lh_OPENSSL_STRING_insert(db->index[i],row);
338 }
339 } 336 }
340 return(1);
341err:
342 return(0);
343 } 337 }
338 return (1);
339
340err:
341 return (0);
342}
344 343
345void TXT_DB_free(TXT_DB *db) 344void
346 { 345TXT_DB_free(TXT_DB *db)
347 int i,n; 346{
348 char **p,*max; 347 int i, n;
348 char **p, *max;
349 349
350 if(db == NULL) 350 if (db == NULL)
351 return; 351 return;
352 352
353 if (db->index != NULL) 353 if (db->index != NULL) {
354 { 354 for (i = db->num_fields - 1; i >= 0; i--)
355 for (i=db->num_fields-1; i>=0; i--) 355 if (db->index[i] != NULL)
356 if (db->index[i] != NULL) lh_OPENSSL_STRING_free(db->index[i]); 356 lh_OPENSSL_STRING_free(db->index[i]);
357 free(db->index); 357 free(db->index);
358 } 358 }
359 if (db->qual != NULL) 359 if (db->qual != NULL)
360 free(db->qual); 360 free(db->qual);
361 if (db->data != NULL) 361 if (db->data != NULL) {
362 { 362 for (i = sk_OPENSSL_PSTRING_num(db->data) - 1; i >= 0; i--) {
363 for (i=sk_OPENSSL_PSTRING_num(db->data)-1; i>=0; i--)
364 {
365 /* check if any 'fields' have been allocated 363 /* check if any 'fields' have been allocated
366 * from outside of the initial block */ 364 * from outside of the initial block */
367 p=sk_OPENSSL_PSTRING_value(db->data,i); 365 p = sk_OPENSSL_PSTRING_value(db->data, i);
368 max=p[db->num_fields]; /* last address */ 366 max = p[db->num_fields]; /* last address */
369 if (max == NULL) /* new row */ 367 if (max == NULL) /* new row */
370 { 368 {
371 for (n=0; n<db->num_fields; n++) 369 for (n = 0; n < db->num_fields; n++)
372 if (p[n] != NULL) free(p[n]); 370 if (p[n] != NULL)
373 } 371 free(p[n]);
374 else 372 } else {
375 { 373 for (n = 0; n < db->num_fields; n++) {
376 for (n=0; n<db->num_fields; n++) 374 if (((p[n] < (char *)p) ||
377 { 375 (p[n] > max)) &&
378 if (((p[n] < (char *)p) || (p[n] > max)) 376 (p[n] != NULL))
379 && (p[n] != NULL))
380 free(p[n]); 377 free(p[n]);
381 }
382 } 378 }
383 free(sk_OPENSSL_PSTRING_value(db->data,i));
384 } 379 }
385 sk_OPENSSL_PSTRING_free(db->data); 380 free(sk_OPENSSL_PSTRING_value(db->data, i));
386 } 381 }
387 free(db); 382 sk_OPENSSL_PSTRING_free(db->data);
388 } 383 }
384 free(db);
385}
diff --git a/src/lib/libcrypto/txt_db/txt_db.h b/src/lib/libcrypto/txt_db/txt_db.h
index 6abe435bc8..5155400e56 100644
--- a/src/lib/libcrypto/txt_db/txt_db.h
+++ b/src/lib/libcrypto/txt_db/txt_db.h
@@ -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,7 +49,7 @@
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
@@ -80,8 +80,7 @@ extern "C" {
80typedef OPENSSL_STRING *OPENSSL_PSTRING; 80typedef OPENSSL_STRING *OPENSSL_PSTRING;
81DECLARE_SPECIAL_STACK_OF(OPENSSL_PSTRING, OPENSSL_STRING) 81DECLARE_SPECIAL_STACK_OF(OPENSSL_PSTRING, OPENSSL_STRING)
82 82
83typedef struct txt_db_st 83typedef struct txt_db_st {
84 {
85 int num_fields; 84 int num_fields;
86 STACK_OF(OPENSSL_PSTRING) *data; 85 STACK_OF(OPENSSL_PSTRING) *data;
87 LHASH_OF(OPENSSL_STRING) **index; 86 LHASH_OF(OPENSSL_STRING) **index;
@@ -90,7 +89,7 @@ typedef struct txt_db_st
90 long arg1; 89 long arg1;
91 long arg2; 90 long arg2;
92 OPENSSL_STRING *arg_row; 91 OPENSSL_STRING *arg_row;
93 } TXT_DB; 92} TXT_DB;
94 93
95#ifndef OPENSSL_NO_BIO 94#ifndef OPENSSL_NO_BIO
96TXT_DB *TXT_DB_read(BIO *in, int num); 95TXT_DB *TXT_DB_read(BIO *in, int num);
@@ -99,8 +98,8 @@ long TXT_DB_write(BIO *out, TXT_DB *db);
99TXT_DB *TXT_DB_read(char *in, int num); 98TXT_DB *TXT_DB_read(char *in, int num);
100long TXT_DB_write(char *out, TXT_DB *db); 99long TXT_DB_write(char *out, TXT_DB *db);
101#endif 100#endif
102int TXT_DB_create_index(TXT_DB *db,int field,int (*qual)(OPENSSL_STRING *), 101int TXT_DB_create_index(TXT_DB *db, int field, int (*qual)(OPENSSL_STRING *),
103 LHASH_HASH_FN_TYPE hash, LHASH_COMP_FN_TYPE cmp); 102 LHASH_HASH_FN_TYPE hash, LHASH_COMP_FN_TYPE cmp);
104void TXT_DB_free(TXT_DB *db); 103void TXT_DB_free(TXT_DB *db);
105OPENSSL_STRING *TXT_DB_get_by_index(TXT_DB *db, int idx, OPENSSL_STRING *value); 104OPENSSL_STRING *TXT_DB_get_by_index(TXT_DB *db, int idx, OPENSSL_STRING *value);
106int TXT_DB_insert(TXT_DB *db, OPENSSL_STRING *value); 105int TXT_DB_insert(TXT_DB *db, OPENSSL_STRING *value);
diff --git a/src/lib/libssl/src/crypto/txt_db/txt_db.c b/src/lib/libssl/src/crypto/txt_db/txt_db.c
index c1e7a79a1a..69fd2ba5bf 100644
--- a/src/lib/libssl/src/crypto/txt_db/txt_db.c
+++ b/src/lib/libssl/src/crypto/txt_db/txt_db.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,7 +49,7 @@
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
@@ -66,323 +66,320 @@
66#undef BUFSIZE 66#undef BUFSIZE
67#define BUFSIZE 512 67#define BUFSIZE 512
68 68
69const char TXT_DB_version[]="TXT_DB" OPENSSL_VERSION_PTEXT; 69const char TXT_DB_version[] = "TXT_DB" OPENSSL_VERSION_PTEXT;
70 70
71TXT_DB *TXT_DB_read(BIO *in, int num) 71TXT_DB *
72 { 72TXT_DB_read(BIO *in, int num)
73 TXT_DB *ret=NULL; 73{
74 int er=1; 74 TXT_DB *ret = NULL;
75 int esc=0; 75 int er = 1;
76 long ln=0; 76 int esc = 0;
77 int i,add,n; 77 long ln = 0;
78 int size=BUFSIZE; 78 int i, add, n;
79 int offset=0; 79 int size = BUFSIZE;
80 char *p,*f; 80 int offset = 0;
81 char *p, *f;
81 OPENSSL_STRING *pp; 82 OPENSSL_STRING *pp;
82 BUF_MEM *buf=NULL; 83 BUF_MEM *buf = NULL;
83 84
84 if ((buf=BUF_MEM_new()) == NULL) goto err; 85 if ((buf = BUF_MEM_new()) == NULL)
85 if (!BUF_MEM_grow(buf,size)) goto err; 86 goto err;
87 if (!BUF_MEM_grow(buf, size))
88 goto err;
86 89
87 if ((ret=malloc(sizeof(TXT_DB))) == NULL) 90 if ((ret = malloc(sizeof(TXT_DB))) == NULL)
88 goto err; 91 goto err;
89 ret->num_fields=num; 92 ret->num_fields = num;
90 ret->index=NULL; 93 ret->index = NULL;
91 ret->qual=NULL; 94 ret->qual = NULL;
92 if ((ret->data=sk_OPENSSL_PSTRING_new_null()) == NULL) 95 if ((ret->data = sk_OPENSSL_PSTRING_new_null()) == NULL)
93 goto err; 96 goto err;
94 if ((ret->index=malloc(sizeof(*ret->index)*num)) == NULL) 97 if ((ret->index = malloc(sizeof(*ret->index)*num)) == NULL)
95 goto err; 98 goto err;
96 if ((ret->qual=malloc(sizeof(*(ret->qual))*num)) == NULL) 99 if ((ret->qual = malloc(sizeof(*(ret->qual))*num)) == NULL)
97 goto err; 100 goto err;
98 for (i=0; i<num; i++) 101 for (i = 0; i < num; i++) {
99 { 102 ret->index[i] = NULL;
100 ret->index[i]=NULL; 103 ret->qual[i] = NULL;
101 ret->qual[i]=NULL; 104 }
102 }
103 105
104 add=(num+1)*sizeof(char *); 106 add = (num + 1)*sizeof(char *);
105 buf->data[size-1]='\0'; 107 buf->data[size-1] = '\0';
106 offset=0; 108 offset = 0;
107 for (;;) 109 for (;;) {
108 { 110 if (offset != 0) {
109 if (offset != 0) 111 size += BUFSIZE;
110 { 112 if (!BUF_MEM_grow_clean(buf, size))
111 size+=BUFSIZE; 113 goto err;
112 if (!BUF_MEM_grow_clean(buf,size)) goto err; 114 }
113 } 115 buf->data[offset] = '\0';
114 buf->data[offset]='\0'; 116 BIO_gets(in, &(buf->data[offset]), size - offset);
115 BIO_gets(in,&(buf->data[offset]),size-offset);
116 ln++; 117 ln++;
117 if (buf->data[offset] == '\0') break; 118 if (buf->data[offset] == '\0')
118 if ((offset == 0) && (buf->data[0] == '#')) continue; 119 break;
119 i=strlen(&(buf->data[offset])); 120 if ((offset == 0) && (buf->data[0] == '#'))
120 offset+=i; 121 continue;
122 i = strlen(&(buf->data[offset]));
123 offset += i;
121 if (buf->data[offset-1] != '\n') 124 if (buf->data[offset-1] != '\n')
122 continue; 125 continue;
123 else 126 else {
124 { 127 buf->data[offset-1] = '\0'; /* blat the '\n' */
125 buf->data[offset-1]='\0'; /* blat the '\n' */ 128 if (!(p = malloc(add + offset)))
126 if (!(p=malloc(add+offset))) goto err; 129 goto err;
127 offset=0; 130 offset = 0;
128 } 131 }
129 pp=(char **)p; 132 pp = (char **)p;
130 p+=add; 133 p += add;
131 n=0; 134 n = 0;
132 pp[n++]=p; 135 pp[n++] = p;
133 i=0; 136 i = 0;
134 f=buf->data; 137 f = buf->data;
135 138
136 esc=0; 139 esc = 0;
137 for (;;) 140 for (;;) {
138 { 141 if (*f == '\0')
139 if (*f == '\0') break; 142 break;
140 if (*f == '\t') 143 if (*f == '\t') {
141 {
142 if (esc) 144 if (esc)
143 p--; 145 p--;
144 else 146 else {
145 {
146 *(p++)='\0'; 147 *(p++)='\0';
147 f++; 148 f++;
148 if (n >= num) break; 149 if (n >= num)
149 pp[n++]=p; 150 break;
151 pp[n++] = p;
150 continue; 152 continue;
151 }
152 } 153 }
154 }
153 esc=(*f == '\\'); 155 esc=(*f == '\\');
154 *(p++)= *(f++); 156 *(p++)= *(f++);
155 } 157 }
156 *(p++)='\0'; 158 *(p++)='\0';
157 if ((n != num) || (*f != '\0')) 159 if ((n != num) || (*f != '\0')) {
158 {
159#if !defined(OPENSSL_NO_STDIO) && !defined(OPENSSL_SYS_WIN16) /* temporary fix :-( */ 160#if !defined(OPENSSL_NO_STDIO) && !defined(OPENSSL_SYS_WIN16) /* temporary fix :-( */
160 fprintf(stderr,"wrong number of fields on line %ld (looking for field %d, got %d, '%s' left)\n",ln,num,n,f); 161 fprintf(stderr, "wrong number of fields on line %ld (looking for field %d, got %d, '%s' left)\n",ln,num,n,f);
161#endif 162#endif
162 er=2; 163 er = 2;
163 goto err; 164 goto err;
164 } 165 }
165 pp[n]=p; 166 pp[n] = p;
166 if (!sk_OPENSSL_PSTRING_push(ret->data,pp)) 167 if (!sk_OPENSSL_PSTRING_push(ret->data, pp)) {
167 {
168#if !defined(OPENSSL_NO_STDIO) && !defined(OPENSSL_SYS_WIN16) /* temporary fix :-( */ 168#if !defined(OPENSSL_NO_STDIO) && !defined(OPENSSL_SYS_WIN16) /* temporary fix :-( */
169 fprintf(stderr,"failure in sk_push\n"); 169 fprintf(stderr, "failure in sk_push\n");
170#endif 170#endif
171 er=2; 171 er = 2;
172 goto err; 172 goto err;
173 }
174 } 173 }
175 er=0; 174 }
175 er = 0;
176
176err: 177err:
177 BUF_MEM_free(buf); 178 BUF_MEM_free(buf);
178 if (er) 179 if (er) {
179 {
180#if !defined(OPENSSL_NO_STDIO) && !defined(OPENSSL_SYS_WIN16) 180#if !defined(OPENSSL_NO_STDIO) && !defined(OPENSSL_SYS_WIN16)
181 if (er == 1) fprintf(stderr,"malloc failure\n"); 181 if (er == 1)
182 fprintf(stderr, "malloc failure\n");
182#endif 183#endif
183 if (ret != NULL) 184 if (ret != NULL) {
184 { 185 if (ret->data != NULL)
185 if (ret->data != NULL) sk_OPENSSL_PSTRING_free(ret->data); 186 sk_OPENSSL_PSTRING_free(ret->data);
186 if (ret->index != NULL) free(ret->index); 187 if (ret->index != NULL)
187 if (ret->qual != NULL) free(ret->qual); 188 free(ret->index);
188 if (ret != NULL) free(ret); 189 if (ret->qual != NULL)
189 } 190 free(ret->qual);
190 return(NULL); 191 if (ret != NULL)
192 free(ret);
191 } 193 }
192 else 194 return (NULL);
193 return(ret); 195 } else
194 } 196 return (ret);
197}
195 198
196OPENSSL_STRING *TXT_DB_get_by_index(TXT_DB *db, int idx, OPENSSL_STRING *value) 199OPENSSL_STRING *
197 { 200TXT_DB_get_by_index(TXT_DB *db, int idx, OPENSSL_STRING *value)
201{
198 OPENSSL_STRING *ret; 202 OPENSSL_STRING *ret;
199 LHASH_OF(OPENSSL_STRING) *lh; 203 LHASH_OF(OPENSSL_STRING) *lh;
200 204
201 if (idx >= db->num_fields) 205 if (idx >= db->num_fields) {
202 { 206 db->error = DB_ERROR_INDEX_OUT_OF_RANGE;
203 db->error=DB_ERROR_INDEX_OUT_OF_RANGE; 207 return (NULL);
204 return(NULL); 208 }
205 } 209 lh = db->index[idx];
206 lh=db->index[idx]; 210 if (lh == NULL) {
207 if (lh == NULL) 211 db->error = DB_ERROR_NO_INDEX;
208 { 212 return (NULL);
209 db->error=DB_ERROR_NO_INDEX;
210 return(NULL);
211 }
212 ret=lh_OPENSSL_STRING_retrieve(lh,value);
213 db->error=DB_ERROR_OK;
214 return(ret);
215 } 213 }
214 ret = lh_OPENSSL_STRING_retrieve(lh, value);
215 db->error = DB_ERROR_OK;
216 return (ret);
217}
216 218
217int TXT_DB_create_index(TXT_DB *db, int field, int (*qual)(OPENSSL_STRING *), 219int
218 LHASH_HASH_FN_TYPE hash, LHASH_COMP_FN_TYPE cmp) 220TXT_DB_create_index(TXT_DB *db, int field, int (*qual)(OPENSSL_STRING *),
219 { 221 LHASH_HASH_FN_TYPE hash, LHASH_COMP_FN_TYPE cmp)
222{
220 LHASH_OF(OPENSSL_STRING) *idx; 223 LHASH_OF(OPENSSL_STRING) *idx;
221 OPENSSL_STRING *r; 224 OPENSSL_STRING *r;
222 int i,n; 225 int i, n;
223 226
224 if (field >= db->num_fields) 227 if (field >= db->num_fields) {
225 { 228 db->error = DB_ERROR_INDEX_OUT_OF_RANGE;
226 db->error=DB_ERROR_INDEX_OUT_OF_RANGE; 229 return (0);
227 return(0); 230 }
228 }
229 /* FIXME: we lose type checking at this point */ 231 /* FIXME: we lose type checking at this point */
230 if ((idx=(LHASH_OF(OPENSSL_STRING) *)lh_new(hash,cmp)) == NULL) 232 if ((idx = (LHASH_OF(OPENSSL_STRING) *)lh_new(hash, cmp)) == NULL) {
231 { 233 db->error = DB_ERROR_MALLOC;
232 db->error=DB_ERROR_MALLOC; 234 return (0);
233 return(0); 235 }
234 } 236 n = sk_OPENSSL_PSTRING_num(db->data);
235 n=sk_OPENSSL_PSTRING_num(db->data); 237 for (i = 0; i < n; i++) {
236 for (i=0; i<n; i++) 238 r = sk_OPENSSL_PSTRING_value(db->data, i);
237 { 239 if ((qual != NULL) && (qual(r) == 0))
238 r=sk_OPENSSL_PSTRING_value(db->data,i); 240 continue;
239 if ((qual != NULL) && (qual(r) == 0)) continue; 241 if ((r = lh_OPENSSL_STRING_insert(idx, r)) != NULL) {
240 if ((r=lh_OPENSSL_STRING_insert(idx,r)) != NULL) 242 db->error = DB_ERROR_INDEX_CLASH;
241 { 243 db->arg1 = sk_OPENSSL_PSTRING_find(db->data, r);
242 db->error=DB_ERROR_INDEX_CLASH; 244 db->arg2 = i;
243 db->arg1=sk_OPENSSL_PSTRING_find(db->data,r);
244 db->arg2=i;
245 lh_OPENSSL_STRING_free(idx); 245 lh_OPENSSL_STRING_free(idx);
246 return(0); 246 return (0);
247 }
248 } 247 }
249 if (db->index[field] != NULL) lh_OPENSSL_STRING_free(db->index[field]);
250 db->index[field]=idx;
251 db->qual[field]=qual;
252 return(1);
253 } 248 }
249 if (db->index[field] != NULL)
250 lh_OPENSSL_STRING_free(db->index[field]);
251 db->index[field] = idx;
252 db->qual[field] = qual;
253 return (1);
254}
254 255
255long TXT_DB_write(BIO *out, TXT_DB *db) 256long
256 { 257TXT_DB_write(BIO *out, TXT_DB *db)
257 long i,j,n,nn,l,tot=0; 258{
258 char *p,**pp,*f; 259 long i, j,n, nn, l, tot = 0;
259 BUF_MEM *buf=NULL; 260 char *p, **pp, *f;
260 long ret= -1; 261 BUF_MEM *buf = NULL;
262 long ret = -1;
261 263
262 if ((buf=BUF_MEM_new()) == NULL) 264 if ((buf = BUF_MEM_new()) == NULL)
263 goto err; 265 goto err;
264 n=sk_OPENSSL_PSTRING_num(db->data); 266 n = sk_OPENSSL_PSTRING_num(db->data);
265 nn=db->num_fields; 267 nn = db->num_fields;
266 for (i=0; i<n; i++) 268 for (i = 0; i < n; i++) {
267 { 269 pp = sk_OPENSSL_PSTRING_value(db->data, i);
268 pp=sk_OPENSSL_PSTRING_value(db->data,i);
269 270
270 l=0; 271 l = 0;
271 for (j=0; j<nn; j++) 272 for (j = 0; j < nn; j++) {
272 {
273 if (pp[j] != NULL) 273 if (pp[j] != NULL)
274 l+=strlen(pp[j]); 274 l += strlen(pp[j]);
275 } 275 }
276 if (!BUF_MEM_grow_clean(buf,(int)(l*2+nn))) goto err; 276 if (!BUF_MEM_grow_clean(buf, (int)(l*2 + nn)))
277 goto err;
277 278
278 p=buf->data; 279 p = buf->data;
279 for (j=0; j<nn; j++) 280 for (j = 0; j < nn; j++) {
280 { 281 f = pp[j];
281 f=pp[j];
282 if (f != NULL) 282 if (f != NULL)
283 for (;;) 283 for (;;) {
284 { 284 if (*f == '\0')
285 if (*f == '\0') break; 285 break;
286 if (*f == '\t') *(p++)='\\'; 286 if (*f == '\t')
287 *(p++)= *(f++); 287 *(p++) = '\\';
288 } 288 *(p++) = *(f++);
289 *(p++)='\t'; 289 }
290 } 290 *(p++) = '\t';
291 p[-1]='\n';
292 j=p-buf->data;
293 if (BIO_write(out,buf->data,(int)j) != j)
294 goto err;
295 tot+=j;
296 } 291 }
297 ret=tot; 292 p[-1] = '\n';
298err: 293 j = p - buf->data;
299 if (buf != NULL) BUF_MEM_free(buf); 294 if (BIO_write(out, buf->data, (int)j) != j)
300 return(ret); 295 goto err;
296 tot += j;
301 } 297 }
298 ret = tot;
302 299
303int TXT_DB_insert(TXT_DB *db, OPENSSL_STRING *row) 300err:
304 { 301 if (buf != NULL)
302 BUF_MEM_free(buf);
303 return (ret);
304}
305
306int
307TXT_DB_insert(TXT_DB *db, OPENSSL_STRING *row)
308{
305 int i; 309 int i;
306 OPENSSL_STRING *r; 310 OPENSSL_STRING *r;
307 311
308 for (i=0; i<db->num_fields; i++) 312 for (i = 0; i < db->num_fields; i++) {
309 { 313 if (db->index[i] != NULL) {
310 if (db->index[i] != NULL) 314 if ((db->qual[i] != NULL) && (db->qual[i](row) == 0))
311 { 315 continue;
312 if ((db->qual[i] != NULL) && 316 r = lh_OPENSSL_STRING_retrieve(db->index[i], row);
313 (db->qual[i](row) == 0)) continue; 317 if (r != NULL) {
314 r=lh_OPENSSL_STRING_retrieve(db->index[i],row); 318 db->error = DB_ERROR_INDEX_CLASH;
315 if (r != NULL) 319 db->arg1 = i;
316 { 320 db->arg_row = r;
317 db->error=DB_ERROR_INDEX_CLASH;
318 db->arg1=i;
319 db->arg_row=r;
320 goto err; 321 goto err;
321 }
322 } 322 }
323 } 323 }
324 }
324 /* We have passed the index checks, now just append and insert */ 325 /* We have passed the index checks, now just append and insert */
325 if (!sk_OPENSSL_PSTRING_push(db->data,row)) 326 if (!sk_OPENSSL_PSTRING_push(db->data, row)) {
326 { 327 db->error = DB_ERROR_MALLOC;
327 db->error=DB_ERROR_MALLOC;
328 goto err; 328 goto err;
329 } 329 }
330 330
331 for (i=0; i<db->num_fields; i++) 331 for (i = 0; i < db->num_fields; i++) {
332 { 332 if (db->index[i] != NULL) {
333 if (db->index[i] != NULL) 333 if ((db->qual[i] != NULL) && (db->qual[i](row) == 0))
334 { 334 continue;
335 if ((db->qual[i] != NULL) && 335 (void)lh_OPENSSL_STRING_insert(db->index[i], row);
336 (db->qual[i](row) == 0)) continue;
337 (void)lh_OPENSSL_STRING_insert(db->index[i],row);
338 }
339 } 336 }
340 return(1);
341err:
342 return(0);
343 } 337 }
338 return (1);
339
340err:
341 return (0);
342}
344 343
345void TXT_DB_free(TXT_DB *db) 344void
346 { 345TXT_DB_free(TXT_DB *db)
347 int i,n; 346{
348 char **p,*max; 347 int i, n;
348 char **p, *max;
349 349
350 if(db == NULL) 350 if (db == NULL)
351 return; 351 return;
352 352
353 if (db->index != NULL) 353 if (db->index != NULL) {
354 { 354 for (i = db->num_fields - 1; i >= 0; i--)
355 for (i=db->num_fields-1; i>=0; i--) 355 if (db->index[i] != NULL)
356 if (db->index[i] != NULL) lh_OPENSSL_STRING_free(db->index[i]); 356 lh_OPENSSL_STRING_free(db->index[i]);
357 free(db->index); 357 free(db->index);
358 } 358 }
359 if (db->qual != NULL) 359 if (db->qual != NULL)
360 free(db->qual); 360 free(db->qual);
361 if (db->data != NULL) 361 if (db->data != NULL) {
362 { 362 for (i = sk_OPENSSL_PSTRING_num(db->data) - 1; i >= 0; i--) {
363 for (i=sk_OPENSSL_PSTRING_num(db->data)-1; i>=0; i--)
364 {
365 /* check if any 'fields' have been allocated 363 /* check if any 'fields' have been allocated
366 * from outside of the initial block */ 364 * from outside of the initial block */
367 p=sk_OPENSSL_PSTRING_value(db->data,i); 365 p = sk_OPENSSL_PSTRING_value(db->data, i);
368 max=p[db->num_fields]; /* last address */ 366 max = p[db->num_fields]; /* last address */
369 if (max == NULL) /* new row */ 367 if (max == NULL) /* new row */
370 { 368 {
371 for (n=0; n<db->num_fields; n++) 369 for (n = 0; n < db->num_fields; n++)
372 if (p[n] != NULL) free(p[n]); 370 if (p[n] != NULL)
373 } 371 free(p[n]);
374 else 372 } else {
375 { 373 for (n = 0; n < db->num_fields; n++) {
376 for (n=0; n<db->num_fields; n++) 374 if (((p[n] < (char *)p) ||
377 { 375 (p[n] > max)) &&
378 if (((p[n] < (char *)p) || (p[n] > max)) 376 (p[n] != NULL))
379 && (p[n] != NULL))
380 free(p[n]); 377 free(p[n]);
381 }
382 } 378 }
383 free(sk_OPENSSL_PSTRING_value(db->data,i));
384 } 379 }
385 sk_OPENSSL_PSTRING_free(db->data); 380 free(sk_OPENSSL_PSTRING_value(db->data, i));
386 } 381 }
387 free(db); 382 sk_OPENSSL_PSTRING_free(db->data);
388 } 383 }
384 free(db);
385}
diff --git a/src/lib/libssl/src/crypto/txt_db/txt_db.h b/src/lib/libssl/src/crypto/txt_db/txt_db.h
index 6abe435bc8..5155400e56 100644
--- a/src/lib/libssl/src/crypto/txt_db/txt_db.h
+++ b/src/lib/libssl/src/crypto/txt_db/txt_db.h
@@ -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,7 +49,7 @@
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
@@ -80,8 +80,7 @@ extern "C" {
80typedef OPENSSL_STRING *OPENSSL_PSTRING; 80typedef OPENSSL_STRING *OPENSSL_PSTRING;
81DECLARE_SPECIAL_STACK_OF(OPENSSL_PSTRING, OPENSSL_STRING) 81DECLARE_SPECIAL_STACK_OF(OPENSSL_PSTRING, OPENSSL_STRING)
82 82
83typedef struct txt_db_st 83typedef struct txt_db_st {
84 {
85 int num_fields; 84 int num_fields;
86 STACK_OF(OPENSSL_PSTRING) *data; 85 STACK_OF(OPENSSL_PSTRING) *data;
87 LHASH_OF(OPENSSL_STRING) **index; 86 LHASH_OF(OPENSSL_STRING) **index;
@@ -90,7 +89,7 @@ typedef struct txt_db_st
90 long arg1; 89 long arg1;
91 long arg2; 90 long arg2;
92 OPENSSL_STRING *arg_row; 91 OPENSSL_STRING *arg_row;
93 } TXT_DB; 92} TXT_DB;
94 93
95#ifndef OPENSSL_NO_BIO 94#ifndef OPENSSL_NO_BIO
96TXT_DB *TXT_DB_read(BIO *in, int num); 95TXT_DB *TXT_DB_read(BIO *in, int num);
@@ -99,8 +98,8 @@ long TXT_DB_write(BIO *out, TXT_DB *db);
99TXT_DB *TXT_DB_read(char *in, int num); 98TXT_DB *TXT_DB_read(char *in, int num);
100long TXT_DB_write(char *out, TXT_DB *db); 99long TXT_DB_write(char *out, TXT_DB *db);
101#endif 100#endif
102int TXT_DB_create_index(TXT_DB *db,int field,int (*qual)(OPENSSL_STRING *), 101int TXT_DB_create_index(TXT_DB *db, int field, int (*qual)(OPENSSL_STRING *),
103 LHASH_HASH_FN_TYPE hash, LHASH_COMP_FN_TYPE cmp); 102 LHASH_HASH_FN_TYPE hash, LHASH_COMP_FN_TYPE cmp);
104void TXT_DB_free(TXT_DB *db); 103void TXT_DB_free(TXT_DB *db);
105OPENSSL_STRING *TXT_DB_get_by_index(TXT_DB *db, int idx, OPENSSL_STRING *value); 104OPENSSL_STRING *TXT_DB_get_by_index(TXT_DB *db, int idx, OPENSSL_STRING *value);
106int TXT_DB_insert(TXT_DB *db, OPENSSL_STRING *value); 105int TXT_DB_insert(TXT_DB *db, OPENSSL_STRING *value);