Make SRP_CTX.info ownership and lifetime be the same as SRP_CTX.login.
Ownership and lifetime rules of SRP_CTX.info are confusing and different
from those of SRP_CTX.login, making it difficult to use correctly.
This makes the ownership and lifetime be the same as those of SRP_CTX.login,
thet is a copy is made when setting it and is freed when SRP_CTX is freed.
Reviewed-by: Rich Salz <rsalz@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/3467)
(cherry picked from commit e655f5494100d93307726b23f4718ead0cadc0c3)
Diego Santa Cruz authored 7 years ago
Matt Caswell committed 6 years ago
3383 | 3383 |
case SSL_CTRL_SET_TLS_EXT_SRP_PASSWORD:
|
3384 | 3384 |
ctx->srp_ctx.SRP_give_srp_client_pwd_callback =
|
3385 | 3385 |
srp_password_from_info_cb;
|
3386 | |
ctx->srp_ctx.info = parg;
|
|
3386 |
if (ctx->srp_ctx.info != NULL)
|
|
3387 |
OPENSSL_free(ctx->srp_ctx.info);
|
|
3388 |
if ((ctx->srp_ctx.info = BUF_strdup((char *)parg)) == NULL) {
|
|
3389 |
SSLerr(SSL_F_SSL3_CTX_CTRL, ERR_R_INTERNAL_ERROR);
|
|
3390 |
return 0;
|
|
3391 |
}
|
3387 | 3392 |
break;
|
3388 | 3393 |
case SSL_CTRL_SET_SRP_ARG:
|
3389 | 3394 |
ctx->srp_ctx.srp_Mask |= SSL_kSRP;
|
19 | 19 |
if (ctx == NULL)
|
20 | 20 |
return 0;
|
21 | 21 |
OPENSSL_free(ctx->srp_ctx.login);
|
|
22 |
OPENSSL_free(ctx->srp_ctx.info);
|
22 | 23 |
BN_free(ctx->srp_ctx.N);
|
23 | 24 |
BN_free(ctx->srp_ctx.g);
|
24 | 25 |
BN_free(ctx->srp_ctx.s);
|
|
51 | 52 |
if (s == NULL)
|
52 | 53 |
return 0;
|
53 | 54 |
OPENSSL_free(s->srp_ctx.login);
|
|
55 |
OPENSSL_free(s->srp_ctx.info);
|
54 | 56 |
BN_free(s->srp_ctx.N);
|
55 | 57 |
BN_free(s->srp_ctx.g);
|
56 | 58 |
BN_free(s->srp_ctx.s);
|
|
104 | 106 |
s->srp_ctx.b = NULL;
|
105 | 107 |
s->srp_ctx.v = NULL;
|
106 | 108 |
s->srp_ctx.login = NULL;
|
107 | |
s->srp_ctx.info = ctx->srp_ctx.info;
|
|
109 |
s->srp_ctx.info = NULL;
|
108 | 110 |
s->srp_ctx.strength = ctx->srp_ctx.strength;
|
109 | 111 |
|
110 | 112 |
if (((ctx->srp_ctx.N != NULL) &&
|
|
131 | 133 |
SSLerr(SSL_F_SSL_SRP_CTX_INIT, ERR_R_INTERNAL_ERROR);
|
132 | 134 |
goto err;
|
133 | 135 |
}
|
|
136 |
if ((ctx->srp_ctx.info != NULL) &&
|
|
137 |
((s->srp_ctx.info = BUF_strdup(ctx->srp_ctx.info)) == NULL)) {
|
|
138 |
SSLerr(SSL_F_SSL_SRP_CTX_INIT, ERR_R_INTERNAL_ERROR);
|
|
139 |
goto err;
|
|
140 |
}
|
134 | 141 |
s->srp_ctx.srp_Mask = ctx->srp_ctx.srp_Mask;
|
135 | 142 |
|
136 | 143 |
return (1);
|
137 | 144 |
err:
|
138 | 145 |
OPENSSL_free(s->srp_ctx.login);
|
|
146 |
OPENSSL_free(s->srp_ctx.info);
|
139 | 147 |
BN_free(s->srp_ctx.N);
|
140 | 148 |
BN_free(s->srp_ctx.g);
|
141 | 149 |
BN_free(s->srp_ctx.s);
|
|
271 | 279 |
} else
|
272 | 280 |
s->srp_ctx.v = BN_dup(v);
|
273 | 281 |
}
|
274 | |
s->srp_ctx.info = info;
|
|
282 |
if (info != NULL) {
|
|
283 |
if (s->srp_ctx.info)
|
|
284 |
OPENSSL_free(s->srp_ctx.info);
|
|
285 |
if ((s->srp_ctx.info = BUF_strdup(info)) == NULL)
|
|
286 |
return -1;
|
|
287 |
}
|
275 | 288 |
|
276 | 289 |
if (!(s->srp_ctx.N) ||
|
277 | 290 |
!(s->srp_ctx.g) || !(s->srp_ctx.s) || !(s->srp_ctx.v))
|