[CRIU] Re: [PATCH] tty: Fix copying of termios character map
Cyrill Gorcunov
gorcunov at openvz.org
Tue Oct 2 12:07:52 EDT 2012
On Tue, Oct 02, 2012 at 08:05:41PM +0400, Cyrill Gorcunov wrote:
> On Tue, Oct 02, 2012 at 08:04:39PM +0400, Cyrill Gorcunov wrote:
> > 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>
>
> Wait a second please, I've done typo there. Update is coming.
Here is updated.
-------------- next part --------------
>From a680d5672ac599cfa5b8b452a4bf9bc64ef0efcb Mon Sep 17 00:00:00 2001
From: Cyrill Gorcunov <gorcunov at openvz.org>
Date: Mon, 1 Oct 2012 21:10:55 +0400
Subject: [PATCH] tty: Fix copying of termios character map
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 0749e40..277bb15 100644
--- a/tty.c
+++ b/tty.c
@@ -122,9 +122,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); \
@@ -927,6 +928,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(ARRAY_SIZE(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