| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent b2b0a33 commit 9df8c74
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,4 @@ | |||
| 1 | + Fix a crash on DEBUG builds when the HACL* routine used by | ||
| 2 | + :meth:`hmac.HMAC.update` fails. This only happens for messages larger | ||
| 3 | + than 4 GiB once the maximum input length of the underlying hash function | ||
| 4 | + is exceeded. Patch by Bénédikt Tran. | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -451,18 +451,18 @@ _hacl_hmac_state_free(HACL_HMAC_state *state) | |||
| 451 | 451 | * | |
| 452 | 452 | * On DEBUG builds, the update() call is verified. | |
| 453 | 453 | * | |
| 454 | - * Return 0 on success; otherwise, set an exception and return -1 on failure. | ||
| 454 | + * Return the HACL* exit code. No exception is set, so that this | ||
| 455 | + * can be called without an attached thread state or with a lock held. | ||
| 455 | 456 | */ | |
| 456 | - static int | ||
| 457 | + static hacl_errno_t | ||
| 457 | 458 | _hacl_hmac_state_update_once(HACL_HMAC_state *state, | |
| 458 | 459 | uint8_t *buf, uint32_t len) | |
| 459 | 460 | { | |
| 460 | 461 | #ifndef NDEBUG | |
| 461 | - hacl_errno_t code = Hacl_Streaming_HMAC_update(state, buf, len); | ||
| 462 | - return _hacl_convert_errno(code); | ||
| 462 | + return Hacl_Streaming_HMAC_update(state, buf, len); | ||
| 463 | 463 | #else | |
| 464 | 464 | (void)Hacl_Streaming_HMAC_update(state, buf, len); | |
| 465 | - return 0; | ||
| 465 | + return Hacl_Streaming_Types_Success; | ||
| 466 | 466 | #endif | |
| 467 | 467 | } | |
| 468 | 468 | ||
@@ -471,17 +471,20 @@ _hacl_hmac_state_update_once(HACL_HMAC_state *state, | |||
| 471 | 471 | * | |
| 472 | 472 | * On DEBUG builds, each update() call is verified. | |
| 473 | 473 | * | |
| 474 | - * Return 0 on success; otherwise, set an exception and return -1 on failure. | ||
| 474 | + * Return the HACL* exit code. No exception is set, so that this | ||
| 475 | + * can be called without an attached thread state or with a lock held. | ||
| 476 | + * Use _hacl_convert_errno() afterwards to set an appropriate exception. | ||
| 475 | 477 | */ | |
| 476 | - static int | ||
| 478 | + static hacl_errno_t | ||
| 477 | 479 | _hacl_hmac_state_update(HACL_HMAC_state *state, uint8_t *buf, Py_ssize_t len) | |
| 478 | 480 | { | |
| 479 | 481 | assert(len >= 0); | |
| 480 | 482 | #ifdef Py_HMAC_SSIZE_LARGER_THAN_UINT32 | |
| 481 | 483 | while (len > UINT32_MAX_AS_SSIZE_T) { | |
| 482 | - if (_hacl_hmac_state_update_once(state, buf, UINT32_MAX) < 0) { | ||
| 483 | - assert(PyErr_Occurred()); | ||
| 484 | - return -1; | ||
| 484 | + hacl_errno_t code = _hacl_hmac_state_update_once(state, buf, | ||
| 485 | + UINT32_MAX); | ||
| 486 | + if (code != Hacl_Streaming_Types_Success) { | ||
| 487 | + return code; | ||
| 485 | 488 | } | |
| 486 | 489 | buf += UINT32_MAX; | |
| 487 | 490 | len -= UINT32_MAX; | |
@@ -786,18 +789,16 @@ _hmac_new_impl(PyObject *module, PyObject *keyobj, PyObject *msgobj, | |||
| 786 | 789 | GET_BUFFER_VIEW_OR_ERROR(msgobj, &msg, goto error); | |
| 787 | 790 | /* Do not use self->mutex here as this is the constructor | |
| 788 | 791 | * where it is not yet possible to have concurrent access. */ | |
| 792 | + hacl_errno_t code; | ||
| 789 | 793 | HASHLIB_EXTERNAL_INSTRUCTIONS_UNLOCKED( | |
| 790 | 794 | msg.len, | |
| 791 | - rc = _hacl_hmac_state_update(self->state, msg.buf, msg.len) | ||
| 795 | + code = _hacl_hmac_state_update(self->state, msg.buf, msg.len) | ||
| 792 | 796 | ); | |
| 793 | 797 | PyBuffer_Release(&msg); | |
| 794 | - #ifndef NDEBUG | ||
| 798 | + rc = _hacl_convert_errno(code); | ||
| 795 | 799 | if (rc < 0) { | |
| 796 | 800 | goto error; | |
| 797 | 801 | } | |
| 798 | - #else | ||
| 799 | - (void)rc; | ||
| 800 | - #endif | ||
| 801 | 802 | } | |
| 802 | 803 | assert(rc == 0); | |
| 803 | 804 | return (PyObject *)self; | |
@@ -889,15 +890,15 @@ static PyObject * | |||
| 889 | 890 | _hmac_HMAC_update_impl(HMACObject *self, PyObject *msgobj) | |
| 890 | 891 | /*[clinic end generated code: output=962134ada5e55985 input=7c0ea830efb03367]*/ | |
| 891 | 892 | { | |
| 892 | - int rc = 0; | ||
| 893 | + hacl_errno_t code; | ||
| 893 | 894 | Py_buffer msg; | |
| 894 | 895 | GET_BUFFER_VIEW_OR_ERROUT(msgobj, &msg); | |
| 895 | 896 | HASHLIB_EXTERNAL_INSTRUCTIONS_LOCKED( | |
| 896 | 897 | self, msg.len, | |
| 897 | - rc = _hacl_hmac_state_update(self->state, msg.buf, msg.len) | ||
| 898 | + code = _hacl_hmac_state_update(self->state, msg.buf, msg.len) | ||
| 898 | 899 | ); | |
| 899 | 900 | PyBuffer_Release(&msg); | |
| 900 | - return rc < 0 ? NULL : Py_None; | ||
| 901 | + return _hacl_convert_errno(code) < 0 ? NULL : Py_None; | ||
| 901 | 902 | } | |
| 902 | 903 | ||
| 903 | 904 | /* | |
| Back | FazBrowse Home | New Git URL |
0 commit comments