summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/asn1/f_string.c
diff options
context:
space:
mode:
authortedu <>2014-04-18 00:58:49 +0000
committertedu <>2014-04-18 00:58:49 +0000
commita1df5b66c7ad477a535e56a504d8da47e1998cfa (patch)
treeb216ca6fba673789f2c494699c4cf41d23337bfa /src/lib/libcrypto/asn1/f_string.c
parent07f5c09b19f56c323fa22ebd5efb5a4df9f5dc4d (diff)
downloadopenbsd-a1df5b66c7ad477a535e56a504d8da47e1998cfa.tar.gz
openbsd-a1df5b66c7ad477a535e56a504d8da47e1998cfa.tar.bz2
openbsd-a1df5b66c7ad477a535e56a504d8da47e1998cfa.zip
lob a few more knf grenades in here to soften things up.
Diffstat (limited to 'src/lib/libcrypto/asn1/f_string.c')
-rw-r--r--src/lib/libcrypto/asn1/f_string.c46
1 files changed, 15 insertions, 31 deletions
diff --git a/src/lib/libcrypto/asn1/f_string.c b/src/lib/libcrypto/asn1/f_string.c
index 7a59fa9f4f..87d7aaa0dd 100644
--- a/src/lib/libcrypto/asn1/f_string.c
+++ b/src/lib/libcrypto/asn1/f_string.c
@@ -69,17 +69,12 @@ int i2a_ASN1_STRING(BIO *bp, ASN1_STRING *a, int type)
69 69
70 if (a == NULL) return(0); 70 if (a == NULL) return(0);
71 71
72 if (a->length == 0) 72 if (a->length == 0) {
73 {
74 if (BIO_write(bp,"0",1) != 1) goto err; 73 if (BIO_write(bp,"0",1) != 1) goto err;
75 n=1; 74 n=1;
76 } 75 } else {
77 else 76 for (i=0; i<a->length; i++) {
78 { 77 if ((i != 0) && (i%35 == 0)) {
79 for (i=0; i<a->length; i++)
80 {
81 if ((i != 0) && (i%35 == 0))
82 {
83 if (BIO_write(bp,"\\\n",2) != 2) goto err; 78 if (BIO_write(bp,"\\\n",2) != 2) goto err;
84 n+=2; 79 n+=2;
85 } 80 }
@@ -103,10 +98,8 @@ int a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size)
103 int num=0,slen=0,first=1; 98 int num=0,slen=0,first=1;
104 99
105 bufsize=BIO_gets(bp,buf,size); 100 bufsize=BIO_gets(bp,buf,size);
106 for (;;) 101 for (;;) {
107 { 102 if (bufsize < 1) {
108 if (bufsize < 1)
109 {
110 if (first) 103 if (first)
111 break; 104 break;
112 else 105 else
@@ -121,12 +114,10 @@ int a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size)
121 if (i == 0) goto err_sl; 114 if (i == 0) goto err_sl;
122 again=(buf[i-1] == '\\'); 115 again=(buf[i-1] == '\\');
123 116
124 for (j=i-1; j>0; j--) 117 for (j=i-1; j>0; j--) {
125 {
126 if (!( ((buf[j] >= '0') && (buf[j] <= '9')) || 118 if (!( ((buf[j] >= '0') && (buf[j] <= '9')) ||
127 ((buf[j] >= 'a') && (buf[j] <= 'f')) || 119 ((buf[j] >= 'a') && (buf[j] <= 'f')) ||
128 ((buf[j] >= 'A') && (buf[j] <= 'F')))) 120 ((buf[j] >= 'A') && (buf[j] <= 'F')))) {
129 {
130 i=j; 121 i=j;
131 break; 122 break;
132 } 123 }
@@ -140,22 +131,19 @@ int a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size)
140 131
141 k=0; 132 k=0;
142 i-=again; 133 i-=again;
143 if (i%2 != 0) 134 if (i%2 != 0) {
144 {
145 ASN1err(ASN1_F_A2I_ASN1_STRING,ASN1_R_ODD_NUMBER_OF_CHARS); 135 ASN1err(ASN1_F_A2I_ASN1_STRING,ASN1_R_ODD_NUMBER_OF_CHARS);
146 goto err; 136 goto err;
147 } 137 }
148 i/=2; 138 i/=2;
149 if (num+i > slen) 139 if (num+i > slen) {
150 {
151 if (s == NULL) 140 if (s == NULL)
152 sp=(unsigned char *)malloc( 141 sp=(unsigned char *)malloc(
153 (unsigned int)num+i*2); 142 (unsigned int)num+i*2);
154 else 143 else
155 sp=(unsigned char *)realloc(s, 144 sp=(unsigned char *)realloc(s,
156 (unsigned int)num+i*2); 145 (unsigned int)num+i*2);
157 if (sp == NULL) 146 if (sp == NULL) {
158 {
159 ASN1err(ASN1_F_A2I_ASN1_STRING,ERR_R_MALLOC_FAILURE); 147 ASN1err(ASN1_F_A2I_ASN1_STRING,ERR_R_MALLOC_FAILURE);
160 if (s != NULL) free(s); 148 if (s != NULL) free(s);
161 goto err; 149 goto err;
@@ -163,10 +151,8 @@ int a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size)
163 s=sp; 151 s=sp;
164 slen=num+i*2; 152 slen=num+i*2;
165 } 153 }
166 for (j=0; j<i; j++,k+=2) 154 for (j=0; j<i; j++,k+=2) {
167 { 155 for (n=0; n<2; n++) {
168 for (n=0; n<2; n++)
169 {
170 m=bufp[k+n]; 156 m=bufp[k+n];
171 if ((m >= '0') && (m <= '9')) 157 if ((m >= '0') && (m <= '9'))
172 m-='0'; 158 m-='0';
@@ -174,8 +160,7 @@ int a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size)
174 m=m-'a'+10; 160 m=m-'a'+10;
175 else if ((m >= 'A') && (m <= 'F')) 161 else if ((m >= 'A') && (m <= 'F'))
176 m=m-'A'+10; 162 m=m-'A'+10;
177 else 163 else {
178 {
179 ASN1err(ASN1_F_A2I_ASN1_STRING,ASN1_R_NON_HEX_CHARACTERS); 164 ASN1err(ASN1_F_A2I_ASN1_STRING,ASN1_R_NON_HEX_CHARACTERS);
180 goto err; 165 goto err;
181 } 166 }
@@ -193,8 +178,7 @@ int a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size)
193 bs->data=s; 178 bs->data=s;
194 ret=1; 179 ret=1;
195err: 180err:
196 if (0) 181 if (0) {
197 {
198err_sl: 182err_sl:
199 ASN1err(ASN1_F_A2I_ASN1_STRING,ASN1_R_SHORT_LINE); 183 ASN1err(ASN1_F_A2I_ASN1_STRING,ASN1_R_SHORT_LINE);
200 } 184 }