@@ -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