Skip to content

Commit d1ac928

Browse files
committed
add some sanity checks
1 parent da41c7a commit d1ac928

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

src/pk/ecc/ecc_sign_hash_internal.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ int ecc_sign_hash_internal(const unsigned char *in, unsigned long inlen,
4848
if ((err = mp_read_unsigned_bin(e, (unsigned char *)in, pbytes)) != CRYPT_OK) { goto errnokey; }
4949
}
5050
else {
51+
if (pbytes >= MAXBLOCKSIZE) {
52+
err = CRYPT_BUFFER_OVERFLOW;
53+
goto error;
54+
}
5155
shift_right = 8 - pbits % 8;
5256
for (i=0, ch=0; i<pbytes; i++) {
5357
buf[i] = ch;

src/pk/ecc/ecc_verify_hash_internal.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ int ecc_verify_hash_internal(void *r, void *s,
6969
if ((err = mp_read_unsigned_bin(e, (unsigned char *)hash, pbytes)) != CRYPT_OK) { goto error; }
7070
}
7171
else {
72+
if (pbytes >= MAXBLOCKSIZE) {
73+
err = CRYPT_BUFFER_OVERFLOW;
74+
goto error;
75+
}
7276
shift_right = 8 - pbits % 8;
7377
for (i=0, ch=0; i<pbytes; i++) {
7478
buf[i] = ch;

src/pk/ecc/ecc_verify_hash_rfc5656.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ int ecc_verify_hash_rfc5656(const unsigned char *sig, unsigned long siglen,
4949
LTC_SSHDATA_MPINT, s,
5050
LTC_SSHDATA_EOL, NULL)) != CRYPT_OK) goto error;
5151

52+
if (slen != siglen) {
53+
err = CRYPT_INVALID_PACKET;
54+
goto error;
55+
}
56+
5257
/* Check curve matches identifier string */
5358
if ((err = ecc_ssh_ecdsa_encode_name(name2, &name2len, key)) != CRYPT_OK) goto error;
5459
if (XSTRCMP(name,name2) != 0) {

0 commit comments

Comments
 (0)