Просмотр исходного кода

coroipcs: Ensure rb data are not overwritten

With introduce of rb alignment (55600762), it's not enough to subtract
one from number of free bytes, but also alignment must be taken to
account. Easiest solution is to subtract 9 bytes.

Signed-off-by: Jan Friesse <jfriesse@redhat.com>
Reviewed-by: Steven Dake <sdake@redhat.com>
Jan Friesse 13 лет назад
Родитель
Сommit
c7e686181b
1 измененных файлов с 10 добавлено и 2 удалено
  1. 10 2
      exec/coroipcs.c

+ 10 - 2
exec/coroipcs.c

@@ -1225,8 +1225,16 @@ static int shared_mem_dispatch_bytes_left (const struct conn_info *conn_info)
 	} else {
 		bytes_left = n_read - n_write;
 	}
-	if (bytes_left > 0) {
-		bytes_left--;
+
+	/*
+	 * Pointers in ring buffer are 64-bit alignment (in memcpy_dwrap)
+	 * To ensure we will not overwrite previous data,
+	 * 9 bytes (64-bit + 1 byte) are subtracted from bytes_left
+	 */
+	if (bytes_left < 9) {
+		bytes_left = 0;
+	} else {
+		bytes_left = bytes_left - 9;
 	}
 
 	return (bytes_left);