USe PyObject_SetString() instead of PyObject_SetObject() in newSSLObject().

This commit is contained in:
Jeremy Hylton 2001-10-10 22:33:32 +00:00
parent 2771b5b52b
commit b0b0bd6cc6

View File

@ -2498,11 +2498,11 @@ static SSLObject *
newSSLObject(PySocketSockObject *Sock, char *key_file, char *cert_file) newSSLObject(PySocketSockObject *Sock, char *key_file, char *cert_file)
{ {
SSLObject *self; SSLObject *self;
PyObject *error = NULL; char *errstr = NULL;
self = PyObject_New(SSLObject, &SSL_Type); /* Create new object */ self = PyObject_New(SSLObject, &SSL_Type); /* Create new object */
if (self == NULL){ if (self == NULL){
error = PyString_FromString("newSSLObject error"); errstr = "newSSLObject error";
goto fail; goto fail;
} }
memset(self->server, '\0', sizeof(char) * 256); memset(self->server, '\0', sizeof(char) * 256);
@ -2514,28 +2514,25 @@ newSSLObject(PySocketSockObject *Sock, char *key_file, char *cert_file)
self->ctx = SSL_CTX_new(SSLv23_method()); /* Set up context */ self->ctx = SSL_CTX_new(SSLv23_method()); /* Set up context */
if (self->ctx == NULL) { if (self->ctx == NULL) {
error = PyString_FromString("SSL_CTX_new error"); errstr = "SSL_CTX_new error";
goto fail; goto fail;
} }
if ((key_file && !cert_file) || (!key_file && cert_file)) { if ((key_file && !cert_file) || (!key_file && cert_file)) {
error = PyString_FromString( errstr = "Both the key & certificate files must be specified";
"Both the key & certificate files must be specified");
goto fail; goto fail;
} }
if (key_file && cert_file) { if (key_file && cert_file) {
if (SSL_CTX_use_PrivateKey_file(self->ctx, key_file, if (SSL_CTX_use_PrivateKey_file(self->ctx, key_file,
SSL_FILETYPE_PEM) < 1) { SSL_FILETYPE_PEM) < 1) {
error = PyString_FromString( errstr = "SSL_CTX_use_PrivateKey_file error";
"SSL_CTX_use_PrivateKey_file error");
goto fail; goto fail;
} }
if (SSL_CTX_use_certificate_chain_file(self->ctx, if (SSL_CTX_use_certificate_chain_file(self->ctx,
cert_file) < 1) { cert_file) < 1) {
error = PyString_FromString( errstr = "SSL_CTX_use_certificate_chain_file error";
"SSL_CTX_use_certificate_chain_file error");
goto fail; goto fail;
} }
} }
@ -2549,7 +2546,7 @@ newSSLObject(PySocketSockObject *Sock, char *key_file, char *cert_file)
/* Actually negotiate SSL connection */ /* Actually negotiate SSL connection */
/* XXX If SSL_connect() returns 0, it's also a failure. */ /* XXX If SSL_connect() returns 0, it's also a failure. */
if ((SSL_connect(self->ssl)) == -1) { if ((SSL_connect(self->ssl)) == -1) {
error = PyString_FromString("SSL_connect error"); errstr = "SSL_connect error";
goto fail; goto fail;
} }
self->ssl->debug = 1; self->ssl->debug = 1;
@ -2564,10 +2561,8 @@ newSSLObject(PySocketSockObject *Sock, char *key_file, char *cert_file)
Py_INCREF(self->Socket); Py_INCREF(self->Socket);
return self; return self;
fail: fail:
if (error) { if (errstr)
PyErr_SetObject(SSLErrorObject, error); PyErr_SetString(SSLErrorObject, errstr);
Py_DECREF(error);
}
Py_DECREF(self); Py_DECREF(self);
return NULL; return NULL;
} }