Skip to content

Commit 4254483

Browse files
Alan HuangAlan Huang
Alan Huang
authored and
Alan Huang
committed
bpo-34001: add checks for protocol boundary ranges
Under LibreSSL, bounds cannot be set such that minimum_version > maximum_version. This commit codifies that behavior, and introduces a new error message to indicate the issue.
1 parent 087570a commit 4254483

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

Modules/_ssl.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3383,6 +3383,8 @@ set_verify_flags(PySSLContext *self, PyObject *arg, void *c)
33833383
static int
33843384
set_min_max_proto_version(PySSLContext *self, PyObject *arg, int what)
33853385
{
3386+
long min;
3387+
long max;
33863388
long v;
33873389
int result;
33883390

@@ -3408,6 +3410,7 @@ set_min_max_proto_version(PySSLContext *self, PyObject *arg, int what)
34083410
}
34093411

34103412
if (what == 0) {
3413+
/* set_minimum_version */
34113414
switch(v) {
34123415
case PY_PROTO_MINIMUM_SUPPORTED:
34133416
v = 0;
@@ -3419,9 +3422,20 @@ set_min_max_proto_version(PySSLContext *self, PyObject *arg, int what)
34193422
default:
34203423
break;
34213424
}
3425+
max = SSL_CTX_get_max_proto_version(self->ctx);
3426+
if(v > PY_PROTO_MAXIMUM_AVAILABLE ||
3427+
(max != 0 && v > max)) {
3428+
PyErr_SetString(
3429+
PyExc_ValueError,
3430+
"SSLContext.minimum_version cannot be greater than "
3431+
"SSLContext.maximum_version."
3432+
);
3433+
return -1;
3434+
}
34223435
result = SSL_CTX_set_min_proto_version(self->ctx, v);
34233436
}
34243437
else {
3438+
/* set_maximum_version */
34253439
switch(v) {
34263440
case PY_PROTO_MAXIMUM_SUPPORTED:
34273441
v = 0;
@@ -3433,6 +3447,16 @@ set_min_max_proto_version(PySSLContext *self, PyObject *arg, int what)
34333447
default:
34343448
break;
34353449
}
3450+
min = SSL_CTX_get_min_proto_version(self->ctx);
3451+
if(v != 0 && (v < PY_PROTO_MINIMUM_AVAILABLE ||
3452+
(min != 0 && v < min))) {
3453+
PyErr_SetString(
3454+
PyExc_ValueError,
3455+
"SSLContext.minimum_version cannot be greater than "
3456+
"SSLContext.maximum_version."
3457+
);
3458+
return -1;
3459+
}
34363460
result = SSL_CTX_set_max_proto_version(self->ctx, v);
34373461
}
34383462
if (result == 0) {

0 commit comments

Comments
 (0)