Skip to content

Commit 7cb841d

Browse files
committed
Fix integer overflow vulnerability in pkcs1_decode.c (#883)
This commit fixes an integer overflow vulnerability in the pkcs1_decode function. Previously, the code was incrementing the position value returned by safe_search before checking if it was SIZE_T_MAX (error condition). This could lead to an overflow when adding 10 to SIZE_T_MAX, causing the subsequent error check to fail. The fix ensures we check for the error condition before performing the addition, preventing the potential overflow vulnerability. Fixes #883
1 parent 2c3a890 commit 7cb841d

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/pkcs1_decode.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,11 +252,12 @@ EXPORT_SYM int pkcs1_decode(const uint8_t *em, size_t len_em_output,
252252
* It can be len_em_output when the 0 is not present.
253253
* It can SIZE_T_MAX in case of other errors.
254254
*/
255-
pos = safe_search(em + 10, 0, len_em_output - 10) + 10;
255+
pos = safe_search(em + 10, 0, len_em_output - 10);
256256
if (pos == SIZE_T_MAX) {
257257
result = -1;
258258
goto end;
259259
}
260+
pos += 10;
260261

261262
/*
262263
* selector is 0 if:

0 commit comments

Comments
 (0)