@@ -1441,23 +1441,24 @@ static int do_read(struct conn *conn, struct buffer *buf)
14411441
14421442static int sftp_read (struct conn * conn , uint8_t * type , struct buffer * buf )
14431443{
1444- int res ;
1444+ int res = -1 ;
14451445 struct buffer buf2 ;
14461446 uint32_t len ;
14471447 buf_init (& buf2 , 5 );
1448- res = do_read (conn , & buf2 );
1449- if (res != -1 ) {
1450- if (buf_get_uint32 (& buf2 , & len ) == -1 )
1451- return -1 ;
1452- if (len > MAX_REPLY_LEN ) {
1453- fprintf (stderr , "reply len too large: %u\n" , len );
1454- return -1 ;
1455- }
1456- if (buf_get_uint8 (& buf2 , type ) == -1 )
1457- return -1 ;
1458- buf_init (buf , len - 1 );
1459- res = do_read (conn , buf );
1448+ if (do_read (conn , & buf2 ) == -1 )
1449+ goto out ;
1450+ if (buf_get_uint32 (& buf2 , & len ) == -1 )
1451+ goto out ;
1452+ if (len < 1 || len > MAX_REPLY_LEN ) {
1453+ fprintf (stderr , "bad reply len: %u\n" , len );
1454+ goto out ;
14601455 }
1456+ if (buf_get_uint8 (& buf2 , type ) == -1 )
1457+ goto out ;
1458+ buf_init (buf , len - 1 );
1459+ res = do_read (conn , buf );
1460+
1461+ out :
14611462 buf_free (& buf2 );
14621463 return res ;
14631464}
@@ -1530,10 +1531,14 @@ static int process_one_request(struct conn *conn)
15301531
15311532 buf_init (& buf , 0 );
15321533 res = sftp_read (conn , & type , & buf );
1533- if (res == -1 )
1534+ if (res == -1 ) {
1535+ buf_free (& buf );
15341536 return -1 ;
1535- if (buf_get_uint32 (& buf , & id ) == -1 )
1537+ }
1538+ if (buf_get_uint32 (& buf , & id ) == -1 ) {
1539+ buf_free (& buf );
15361540 return -1 ;
1541+ }
15371542
15381543 pthread_mutex_lock (& sshfs .lock );
15391544 req = (struct request * )
0 commit comments