Commit 6a5ac971 authored by Cyrill Gorcunov's avatar Cyrill Gorcunov Committed by Pavel Emelyanov

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: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 8a4ec72b
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment