(hx509_parse_name): don't abort on error, rather return error
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@17293 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
@@ -349,25 +349,33 @@ hx509_parse_name(const char *str, hx509_name *name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
q = strchr(p, '=');
|
q = strchr(p, '=');
|
||||||
if (q == NULL)
|
if (q == NULL) {
|
||||||
_hx509_abort("missing = in %s", p);
|
/* _hx509_abort("missing = in %s", p); */
|
||||||
if (q == p)
|
goto out;
|
||||||
_hx509_abort("missing name before = in %s", p);
|
}
|
||||||
|
if (q == p) {
|
||||||
|
/* _hx509_abort("missing name before = in %s", p); */
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
if ((q - p) > len)
|
if ((q - p) > len) {
|
||||||
_hx509_abort(" = after , in %s", p);
|
/* _hx509_abort(" = after , in %s", p); */
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
oid = stringtooid(p, q - p);
|
oid = stringtooid(p, q - p);
|
||||||
if (oid == NULL) {
|
if (oid == NULL) {
|
||||||
_hx509_abort("unknown type: %.*s", (int)(q - p), p);
|
/* _hx509_abort("unknown type: %.*s", (int)(q - p), p); */
|
||||||
exit(1);
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
ptr = realloc(n->der_name.u.rdnSequence.val,
|
ptr = realloc(n->der_name.u.rdnSequence.val,
|
||||||
sizeof(n->der_name.u.rdnSequence.val[0]) *
|
sizeof(n->der_name.u.rdnSequence.val[0]) *
|
||||||
(n->der_name.u.rdnSequence.len + 1));
|
(n->der_name.u.rdnSequence.len + 1));
|
||||||
if (ptr == NULL)
|
if (ptr == NULL) {
|
||||||
_hx509_abort("realloc");
|
/* _hx509_abort("realloc"); */
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
n->der_name.u.rdnSequence.val = ptr;
|
n->der_name.u.rdnSequence.val = ptr;
|
||||||
|
|
||||||
memmove(&n->der_name.u.rdnSequence.val[1],
|
memmove(&n->der_name.u.rdnSequence.val[1],
|
||||||
@@ -378,27 +386,27 @@ hx509_parse_name(const char *str, hx509_name *name)
|
|||||||
rdn = &n->der_name.u.rdnSequence.val[0];
|
rdn = &n->der_name.u.rdnSequence.val[0];
|
||||||
|
|
||||||
rdn->val = malloc(sizeof(rdn->val[0]));
|
rdn->val = malloc(sizeof(rdn->val[0]));
|
||||||
if (rdn->val == NULL)
|
if (rdn->val == NULL) {
|
||||||
_hx509_abort("foo");
|
/* _hx509_abort("malloc"); */
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
rdn->len = 1;
|
rdn->len = 1;
|
||||||
|
|
||||||
|
|
||||||
if (copy_oid(oid, &rdn->val[0].type) != 0)
|
if (copy_oid(oid, &rdn->val[0].type) != 0) {
|
||||||
_hx509_abort("copy_oid");
|
/* _hx509_abort("copy_oid"); */
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
size_t strlen = len - (q - p) - 1;
|
size_t strlen = len - (q - p) - 1;
|
||||||
const char *str = p + (q - p) + 1;
|
const char *str = p + (q - p) + 1;
|
||||||
#if 0
|
|
||||||
printf("%s == %.*s\n",
|
|
||||||
oidtostring(oid),
|
|
||||||
(int)strlen,
|
|
||||||
str);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
r = malloc(strlen + 1);
|
r = malloc(strlen + 1);
|
||||||
if (r == NULL)
|
if (r == NULL) {
|
||||||
_hx509_abort("malloc");
|
/* _hx509_abort("malloc"); */
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
memcpy(r, str, strlen);
|
memcpy(r, str, strlen);
|
||||||
r[strlen] = '\0';
|
r[strlen] = '\0';
|
||||||
|
|
||||||
@@ -413,6 +421,9 @@ hx509_parse_name(const char *str, hx509_name *name)
|
|||||||
*name = n;
|
*name = n;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
out:
|
||||||
|
hx509_name_free(&n);
|
||||||
|
return HX509_NAME_MALFORMATED;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
Reference in New Issue
Block a user