Skip to content

Commit 7c4d7cb

Browse files
committed
Fixes suggested by Matt Johnston
1 parent 9706aa6 commit 7c4d7cb

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/misc/ssh/ssh_decode_sequence_multi.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ int ssh_decode_sequence_multi(const unsigned char *in, unsigned long inlen, ...)
7474

7575
case LTC_SSHDATA_EOL:
7676
/* Should never get here */
77+
size = (unsigned long)-1;
7778
err = CRYPT_INVALID_ARG;
7879
goto error;
7980
}
@@ -114,11 +115,11 @@ int ssh_decode_sequence_multi(const unsigned char *in, unsigned long inlen, ...)
114115
case LTC_SSHDATA_NAMELIST:
115116
sdata = va_arg(args, char*);
116117
bufsize = va_arg(args, unsigned long);
118+
if (size >= bufsize) {
119+
err = CRYPT_BUFFER_OVERFLOW;
120+
goto error;
121+
}
117122
if (size > 0) {
118-
if (size >= bufsize) {
119-
err = CRYPT_BUFFER_OVERFLOW;
120-
goto error;
121-
}
122123
XSTRNCPY(sdata, (const char *)in, size);
123124
sdata[size] = '\0'; /* strncpy doesn't NUL-terminate */
124125
} else {
@@ -130,6 +131,10 @@ int ssh_decode_sequence_multi(const unsigned char *in, unsigned long inlen, ...)
130131
vdata = va_arg(args, void*);
131132
if (size == 0) {
132133
if ((err = mp_set(vdata, 0)) != CRYPT_OK) { goto error; }
134+
} else if ((in[0] & 0x80) != 0) {
135+
/* Negative number - not supported */
136+
err = CRYPT_INVALID_PACKET;
137+
goto error;
133138
} else {
134139
if ((err = mp_read_unsigned_bin(vdata, (unsigned char *)in, size)) != CRYPT_OK) { goto error; }
135140
}

0 commit comments

Comments
 (0)