@@ -96,7 +96,7 @@ newEVPobject(void)
96
96
return retval ;
97
97
}
98
98
99
- static void
99
+ static int
100
100
EVP_hash (EVPobject * self , const void * vp , Py_ssize_t len )
101
101
{
102
102
unsigned int process ;
@@ -108,11 +108,12 @@ EVP_hash(EVPobject *self, const void *vp, Py_ssize_t len)
108
108
process = Py_SAFE_DOWNCAST (len , Py_ssize_t , unsigned int );
109
109
if (!EVP_DigestUpdate (self -> ctx , (const void * )cp , process )) {
110
110
_setException (PyExc_ValueError );
111
- break ;
111
+ return -1 ;
112
112
}
113
113
len -= process ;
114
114
cp += process ;
115
115
}
116
+ return 0 ;
116
117
}
117
118
118
119
/* Internal methods for a hash object */
@@ -243,6 +244,7 @@ static PyObject *
243
244
EVP_update (EVPobject * self , PyObject * obj )
244
245
/*[clinic end generated code: output=ec1d55ed2432e966 input=9b30ec848f015501]*/
245
246
{
247
+ int result ;
246
248
Py_buffer view ;
247
249
248
250
GET_BUFFER_VIEW_OR_ERROUT (obj , & view );
@@ -255,14 +257,17 @@ EVP_update(EVPobject *self, PyObject *obj)
255
257
if (self -> lock != NULL ) {
256
258
Py_BEGIN_ALLOW_THREADS
257
259
PyThread_acquire_lock (self -> lock , 1 );
258
- EVP_hash (self , view .buf , view .len );
260
+ result = EVP_hash (self , view .buf , view .len );
259
261
PyThread_release_lock (self -> lock );
260
262
Py_END_ALLOW_THREADS
261
263
} else {
262
- EVP_hash (self , view .buf , view .len );
264
+ result = EVP_hash (self , view .buf , view .len );
263
265
}
264
266
265
267
PyBuffer_Release (& view );
268
+
269
+ if (result == -1 )
270
+ return NULL ;
266
271
Py_RETURN_NONE ;
267
272
}
268
273
@@ -396,6 +401,7 @@ static PyObject *
396
401
EVPnew (const EVP_MD * digest ,
397
402
const unsigned char * cp , Py_ssize_t len )
398
403
{
404
+ int result = 0 ;
399
405
EVPobject * self ;
400
406
401
407
if (!digest ) {
@@ -415,10 +421,14 @@ EVPnew(const EVP_MD *digest,
415
421
if (cp && len ) {
416
422
if (len >= HASHLIB_GIL_MINSIZE ) {
417
423
Py_BEGIN_ALLOW_THREADS
418
- EVP_hash (self , cp , len );
424
+ result = EVP_hash (self , cp , len );
419
425
Py_END_ALLOW_THREADS
420
426
} else {
421
- EVP_hash (self , cp , len );
427
+ result = EVP_hash (self , cp , len );
428
+ }
429
+ if (result == -1 ) {
430
+ Py_DECREF (self );
431
+ return NULL ;
422
432
}
423
433
}
424
434
0 commit comments