fixes response overwrite bug
This fixes a bug in truncated response payload handling. Payloads requiring more than one call to `Read()` were overwiting the previous Read()'s buffer contents. Because we know the response payload size, we can simply call `io.ReadAll()` rather than looping over calls to `Read()`.
This commit is contained in:
		
							
								
								
									
										6
									
								
								rpc.go
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								rpc.go
									
									
									
									
									
								
							| @@ -195,16 +195,12 @@ func (l *Libvirt) listen() { | ||||
| 		// payload: packet length minus what was previously read | ||||
| 		size := int(length) - (constants.PacketLengthSize + constants.HeaderSize) | ||||
| 		buf := make([]byte, size) | ||||
| 		for n := 0; n < size; { | ||||
| 			nn, err := l.r.Read(buf) | ||||
| 		_, err = io.ReadFull(l.r, buf) | ||||
| 		if err != nil { | ||||
| 			// invalid packet | ||||
| 			continue | ||||
| 		} | ||||
|  | ||||
| 			n += nn | ||||
| 		} | ||||
|  | ||||
| 		// route response to caller | ||||
| 		l.route(h, buf) | ||||
| 	} | ||||
|   | ||||
		Reference in New Issue
	
	Block a user