mirror of
				https://github.com/go-delve/delve.git
				synced 2025-11-04 06:32:16 +08:00 
			
		
		
		
	proc/variables: mark malformed maps as unreadable instead of panicking (#703)
Under currently undetermined circumstances we encounter a map type that has a malformed buckets, oldbuckets or overflow field. Check the type of buckets, oldbuckets and overflow before using them. Fixes #685
This commit is contained in:
		
				
					committed by
					
						
						Derek Parker
					
				
			
			
				
	
			
			
			
						parent
						
							e77595ce31
						
					
				
				
					commit
					3658d1e17c
				
			@ -1319,9 +1319,18 @@ func (v *Variable) mapIterator() *mapIterator {
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if it.buckets.Kind != reflect.Struct || it.oldbuckets.Kind != reflect.Struct {
 | 
			
		||||
		v.Unreadable = mapBucketsNotStructErr
 | 
			
		||||
		return nil
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return it
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
var mapBucketContentsNotArrayErr = errors.New("malformed map type: keys, values or tophash of a bucket is not an array")
 | 
			
		||||
var mapBucketContentsInconsistentLenErr = errors.New("malformed map type: inconsistent array length in bucket")
 | 
			
		||||
var mapBucketsNotStructErr = errors.New("malformed map type: buckets, oldbuckets or overflow field not a struct")
 | 
			
		||||
 | 
			
		||||
func (it *mapIterator) nextBucket() bool {
 | 
			
		||||
	if it.overflow != nil && it.overflow.Addr > 0 {
 | 
			
		||||
		it.b = it.overflow
 | 
			
		||||
@ -1410,12 +1419,17 @@ func (it *mapIterator) nextBucket() bool {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if it.tophashes.Kind != reflect.Array || it.keys.Kind != reflect.Array || it.values.Kind != reflect.Array {
 | 
			
		||||
		it.v.Unreadable = fmt.Errorf("malformed map type: keys, values or tophash of a bucket is not an array")
 | 
			
		||||
		it.v.Unreadable = mapBucketContentsNotArrayErr
 | 
			
		||||
		return false
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if it.tophashes.Len != it.keys.Len || it.tophashes.Len != it.values.Len {
 | 
			
		||||
		it.v.Unreadable = fmt.Errorf("malformed map type: inconsistent array length in bucket")
 | 
			
		||||
		it.v.Unreadable = mapBucketContentsInconsistentLenErr
 | 
			
		||||
		return false
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if it.overflow.Kind != reflect.Struct {
 | 
			
		||||
		it.v.Unreadable = mapBucketsNotStructErr
 | 
			
		||||
		return false
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user