hx509: Fix name expansion bug

This commit is contained in:
Nicolas Williams
2021-12-04 16:18:17 -06:00
parent e23bc7d53d
commit ea61f68d55

View File

@@ -937,9 +937,6 @@ hx509_name_expand(hx509_context context,
return ENOMEM; return ENOMEM;
} }
} }
free(s);
sval = NULL;
s = NULL;
while (p != NULL) { while (p != NULL) {
/* expand variables */ /* expand variables */
@@ -948,6 +945,7 @@ hx509_name_expand(hx509_context context,
if (p2 == NULL) { if (p2 == NULL) {
hx509_set_error_string(context, 0, EINVAL, "missing }"); hx509_set_error_string(context, 0, EINVAL, "missing }");
rk_strpoolfree(strpool); rk_strpoolfree(strpool);
free(s);
return EINVAL; return EINVAL;
} }
p += 2; p += 2;
@@ -957,11 +955,13 @@ hx509_name_expand(hx509_context context,
"variable %.*s missing", "variable %.*s missing",
(int)(p2 - p), p); (int)(p2 - p), p);
rk_strpoolfree(strpool); rk_strpoolfree(strpool);
free(s);
return EINVAL; return EINVAL;
} }
strpool = rk_strpoolprintf(strpool, "%s", value); strpool = rk_strpoolprintf(strpool, "%s", value);
if (strpool == NULL) { if (strpool == NULL) {
hx509_set_error_string(context, 0, ENOMEM, "out of memory"); hx509_set_error_string(context, 0, ENOMEM, "out of memory");
free(s);
return ENOMEM; return ENOMEM;
} }
p2++; p2++;
@@ -974,9 +974,14 @@ hx509_name_expand(hx509_context context,
strpool = rk_strpoolprintf(strpool, "%s", p2); strpool = rk_strpoolprintf(strpool, "%s", p2);
if (strpool == NULL) { if (strpool == NULL) {
hx509_set_error_string(context, 0, ENOMEM, "out of memory"); hx509_set_error_string(context, 0, ENOMEM, "out of memory");
free(s);
return ENOMEM; return ENOMEM;
} }
} }
free(s);
s = NULL;
if (strpool) { if (strpool) {
size_t max_bytes; size_t max_bytes;