summaryrefslogtreecommitdiff
path: root/lib/libcrypto/pkcs12/p12_utl.c
diff options
context:
space:
mode:
authorBob Beck <beck@cvs.openbsd.org>2001-06-22 00:03:45 +0000
committerBob Beck <beck@cvs.openbsd.org>2001-06-22 00:03:45 +0000
commit642a4bcb90082ea29d17ec26cf3bf24f137f6d78 (patch)
tree7bfd115a4edcd10efea47366faf8014148d5dbf2 /lib/libcrypto/pkcs12/p12_utl.c
parenta53ec830979e8b3c974a48b5486fe532177cde14 (diff)
openssl-engine-0.9.6a merge
Diffstat (limited to 'lib/libcrypto/pkcs12/p12_utl.c')
-rw-r--r--lib/libcrypto/pkcs12/p12_utl.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/lib/libcrypto/pkcs12/p12_utl.c b/lib/libcrypto/pkcs12/p12_utl.c
index 17f41b45496..2f1d1e534fc 100644
--- a/lib/libcrypto/pkcs12/p12_utl.c
+++ b/lib/libcrypto/pkcs12/p12_utl.c
@@ -62,30 +62,34 @@
/* Cheap and nasty Unicode stuff */
-unsigned char *asc2uni (const char *asc, unsigned char **uni, int *unilen)
+unsigned char *asc2uni(const char *asc, int asclen, unsigned char **uni, int *unilen)
{
int ulen, i;
unsigned char *unitmp;
- ulen = strlen(asc)*2 + 2;
- if (!(unitmp = OPENSSL_malloc (ulen))) return NULL;
- for (i = 0; i < ulen; i+=2) {
+ if (asclen == -1) asclen = strlen(asc);
+ ulen = asclen*2 + 2;
+ if (!(unitmp = OPENSSL_malloc(ulen))) return NULL;
+ for (i = 0; i < ulen - 2; i+=2) {
unitmp[i] = 0;
unitmp[i + 1] = asc[i>>1];
}
+ /* Make result double null terminated */
+ unitmp[ulen - 2] = 0;
+ unitmp[ulen - 1] = 0;
if (unilen) *unilen = ulen;
if (uni) *uni = unitmp;
return unitmp;
}
-char *uni2asc (unsigned char *uni, int unilen)
+char *uni2asc(unsigned char *uni, int unilen)
{
int asclen, i;
char *asctmp;
asclen = unilen / 2;
/* If no terminating zero allow for one */
- if (uni[unilen - 1]) asclen++;
+ if (!unilen || uni[unilen - 1]) asclen++;
uni++;
- if (!(asctmp = OPENSSL_malloc (asclen))) return NULL;
+ if (!(asctmp = OPENSSL_malloc(asclen))) return NULL;
for (i = 0; i < unilen; i+=2) asctmp[i>>1] = uni[i];
asctmp[asclen - 1] = 0;
return asctmp;