Skip to content

Commit af155d9

Browse files
author
cameronrich
committed
Some fixes after going through the test harness
git-svn-id: svn://svn.code.sf.net/p/axtls/code/trunk@222 9a5d90b5-6617-0410-8a86-bb477d3ed2e3
1 parent ffa4da4 commit af155d9

File tree

3 files changed

+29
-24
lines changed

3 files changed

+29
-24
lines changed

crypto/crypto_misc.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,14 +349,19 @@ EXP_FUNC int STDCALL base64_decode(const char *in, int len,
349349
y = t = 0;
350350
}
351351

352-
if (z >= *outlen) /* check that we don't go past the output buffer */
352+
/* check that we don't go past the output buffer */
353+
if (outlen && z >= *outlen)
354+
{
355+
printf("Stuff %d, %d\n", z, *outlen);
353356
goto error;
357+
}
354358
}
355359

356360
if (y != 0)
357361
goto error;
358362

359363
*outlen = z;
364+
360365
ret = 0;
361366

362367
error:

ssl/asn1.c

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -291,34 +291,34 @@ static int asn1_get_printable_str(const uint8_t *buf, int *offset, char **str)
291291
int asn1_type = buf[*offset];
292292

293293
/* some certs have this awful crud in them for some reason */
294-
if (buf[asn1_type] != ASN1_PRINTABLE_STR &&
295-
buf[asn1_type] != ASN1_PRINTABLE_STR2 &&
296-
buf[asn1_type] != ASN1_TELETEX_STR &&
297-
buf[asn1_type] != ASN1_IA5_STR &&
298-
buf[asn1_type] != ASN1_UNICODE_STR)
294+
if (asn1_type != ASN1_PRINTABLE_STR &&
295+
asn1_type != ASN1_PRINTABLE_STR2 &&
296+
asn1_type != ASN1_TELETEX_STR &&
297+
asn1_type != ASN1_IA5_STR &&
298+
asn1_type != ASN1_UNICODE_STR)
299299
goto end_pnt_str;
300300

301-
(*offset)++;
302-
len = get_asn1_length(buf, offset);
301+
(*offset)++;
302+
len = get_asn1_length(buf, offset);
303303

304-
if (buf[asn1_type - 1] == ASN1_UNICODE_STR)
305-
{
306-
int i;
307-
*str = (char *)malloc(len/2+1); /* allow for null */
304+
if (asn1_type == ASN1_UNICODE_STR)
305+
{
306+
int i;
307+
*str = (char *)malloc(len/2+1); /* allow for null */
308308

309-
for (i = 0; i < len; i += 2)
310-
(*str)[i/2] = buf[*offset + i + 1];
309+
for (i = 0; i < len; i += 2)
310+
(*str)[i/2] = buf[*offset + i + 1];
311311

312-
(*str)[len/2] = 0; /* null terminate */
313-
}
314-
else
315-
{
316-
*str = (char *)malloc(len+1); /* allow for null */
317-
memcpy(*str, &buf[*offset], len);
318-
(*str)[len] = 0; /* null terminate */
319-
}
312+
(*str)[len/2] = 0; /* null terminate */
313+
}
314+
else
315+
{
316+
*str = (char *)malloc(len+1); /* allow for null */
317+
memcpy(*str, &buf[*offset], len);
318+
(*str)[len] = 0; /* null terminate */
319+
}
320320

321-
*offset += len;
321+
*offset += len;
322322

323323
end_pnt_str:
324324
return len;

ssl/loader.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,6 @@ static int pem_decrypt(const char *where, const char *end,
259259

260260
/* turn base64 into binary */
261261
pem_size = (int)(end-start);
262-
ssl_obj->len = sizeof(ssl_obj->buf);
263262
if (base64_decode(start, pem_size, ssl_obj->buf, &ssl_obj->len) != 0)
264263
goto error;
265264

@@ -315,6 +314,7 @@ static int new_pem_obj(SSL_CTX *ssl_ctx, int is_cacert, char *where,
315314

316315
/* 4/3 bigger than what we need but so what */
317316
ssl_obj->buf = (uint8_t *)calloc(1, pem_size);
317+
ssl_obj->len = pem_size;
318318

319319
if (i == IS_RSA_PRIVATE_KEY &&
320320
strstr(start, "Proc-Type:") &&

0 commit comments

Comments
 (0)