@@ -2157,12 +2157,10 @@ _ssl__SSLSocket_group_impl(PySSLSocket *self)
21572157 if (self -> ssl == NULL ) {
21582158 Py_RETURN_NONE ;
21592159 }
2160-
21612160 group_name = SSL_get0_group_name (self -> ssl );
21622161 if (group_name == NULL ) {
21632162 Py_RETURN_NONE ;
21642163 }
2165-
21662164 return PyUnicode_DecodeFSDefault (group_name );
21672165#else
21682166 PyErr_SetString (PyExc_NotImplementedError ,
@@ -3467,18 +3465,13 @@ _ssl__SSLContext_get_groups_impl(PySSLContext *self, int include_aliases)
34673465 size_t i , num ;
34683466 PyObject * item , * result = NULL ;
34693467
3468+ // This "groups" object is dynamically allocated, but the strings inside
3469+ // it are internal constants which shouldn't ever be modified or freed.
34703470 if ((groups = sk_OPENSSL_CSTRING_new_null ()) == NULL ) {
34713471 _setSSLError (get_state_ctx (self ), "Can't allocate stack" , 0 , __FILE__ , __LINE__ );
3472- goto error ;
3472+ goto error ;
34733473 }
34743474
3475- /*
3476- * Note: The "groups" stack is dynamically allocated, but the strings
3477- * returned in the stack are references to internal constants which
3478- * should NOT be modified or freed. They should also be plain ASCII,
3479- * so there should be no decoding issue when converting to Unicode.
3480- */
3481-
34823475 if (!SSL_CTX_get0_implemented_groups (self -> ctx , include_aliases , groups )) {
34833476 _setSSLError (get_state_ctx (self ), "Can't get groups" , 0 , __FILE__ , __LINE__ );
34843477 goto error ;
@@ -3492,11 +3485,14 @@ _ssl__SSLContext_get_groups_impl(PySSLContext *self, int include_aliases)
34923485 }
34933486
34943487 for (i = 0 ; i < num ; ++ i ) {
3488+ // There's no allocation here, so group won't ever be NULL.
34953489 group = sk_OPENSSL_CSTRING_value (groups , i );
3496- assert (group != NULL );
3490+ assert (group != NULL );
34973491
3492+ // Group names are plain ASCII, so there's no chance of a decoding
3493+ // error here. However, an allocation failure could occur when
3494+ // constructing the Unicode version of the names.
34983495 item = PyUnicode_DecodeFSDefault (group );
3499-
35003496 if (item == NULL ) {
35013497 _setSSLError (get_state_ctx (self ), "Can't allocate group name" , 0 , __FILE__ , __LINE__ );
35023498 goto error ;
0 commit comments