mirror of
				https://github.com/SSLMate/certspotter.git
				synced 2025-07-03 10:47:17 +02:00 
			
		
		
		
	Use io.ReadFull instead of raw Read
An io.Reader does not guarantee that it can read all bytes possible to fill the input buffer. Thus, we should use io.ReadFull here instead. Cherry-picked from ddfd4a2b2d89e20f0a7c63c88420aaa419d4d95c of https://github.com/google/certificate-transparency
This commit is contained in:
		
							parent
							
								
									c36452f67a
								
							
						
					
					
						commit
						4104152de6
					
				@ -80,13 +80,12 @@ func readVarBytes(r io.Reader, numLenBytes int) ([]byte, error) {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	data := make([]byte, l)
 | 
			
		||||
	n, err := r.Read(data)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
	if n, err := io.ReadFull(r, data);  err != nil {
 | 
			
		||||
		if err == io.EOF || err == io.ErrUnexpectedEOF {
 | 
			
		||||
			return nil, fmt.Errorf("short read: expected %d but got %d", l, n)
 | 
			
		||||
		}
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	if n != int(l) {
 | 
			
		||||
		return nil, fmt.Errorf("short read: expected %d but got %d", l, n)
 | 
			
		||||
	}
 | 
			
		||||
	return data, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user