[CRIU] [PATCH] tty: Fix copying of termios character map

Cyrill Gorcunov gorcunov at openvz.org
Tue Oct 2 12:04:39 EDT 2012


The system termios structure and our PB
equivalent defined quite different, while
first defined as plain array we use dynamically
allocated memory. Thus the use of min() macro
is incorrect here and always produce the size of
pointer.

Fix it using the size of array from the system
provided structure. The BUILD_BUG_ON will prevent
from accidental changes.

Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 tty.c |   13 +++++++++++--
 1 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/tty.c b/tty.c
index 9ee9521..083a711 100644
--- a/tty.c
+++ b/tty.c
@@ -123,9 +123,10 @@ int prepare_shared_tty(void)
 
 #define termios_copy(d, s)				\
 	do {						\
+		struct termios __t;			\
+							\
 		memcpy((d)->c_cc, (s)->c_cc,		\
-		       min(sizeof((s)->c_cc),		\
-			   sizeof((d)->c_cc)));		\
+		       sizeof(__t.c_cc));		\
 							\
 		ASSIGN_MEMBER((d),(s), c_iflag);	\
 		ASSIGN_MEMBER((d),(s), c_oflag);	\
@@ -992,6 +993,14 @@ static int dump_pty_info(int lfd, u32 id, const struct fd_parms *p, int major, i
 
 	int ret = -1, sid, pgrp;
 
+	/*
+	 * Make sure the structures the system provides us
+	 * correlates well with protobuf templates.
+	 */
+	BUILD_BUG_ON(sizeof(t.c_cc) < TERMIOS_NCC);
+	BUILD_BUG_ON(sizeof(termios.c_cc) != sizeof(void *));
+	BUILD_BUG_ON((sizeof(termios.c_cc) * TERMIOS_NCC) < sizeof(t.c_cc));
+
 	if (tty_get_sid_pgrp(lfd, &sid, &pgrp, &hangup))
 		return -1;
 
-- 
1.7.7.6



More information about the CRIU mailing list