Skip to content

Commit

Permalink
net: Fix references to out-of-scope variables in put_cmsg_compat()
Browse files Browse the repository at this point in the history
In net/compat.c::put_cmsg_compat() we may assign 'data' the address of
either the 'ctv' or 'cts' local variables inside the 'if
(!COMPAT_USE_64BIT_TIME)' branch.

Those variables go out of scope at the end of the 'if' statement, so
when we use 'data' further down in 'copy_to_user(CMSG_COMPAT_DATA(cm),
data, cmlen - sizeof(struct compat_cmsghdr))' there's no telling what
it may be refering to - not good.

Fix the problem by simply giving 'ctv' and 'cts' function scope.

Signed-off-by: Jesper Juhl <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
jjuhl authored and davem330 committed Jul 23, 2012
1 parent 5e9965c commit 8188104
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions net/compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
{
struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
struct compat_cmsghdr cmhdr;
struct compat_timeval ctv;
struct compat_timespec cts[3];
int cmlen;

if (cm == NULL || kmsg->msg_controllen < sizeof(*cm)) {
Expand All @@ -229,8 +231,6 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
}

if (!COMPAT_USE_64BIT_TIME) {
struct compat_timeval ctv;
struct compat_timespec cts[3];
if (level == SOL_SOCKET && type == SCM_TIMESTAMP) {
struct timeval *tv = (struct timeval *)data;
ctv.tv_sec = tv->tv_sec;
Expand Down

0 comments on commit 8188104

Please sign in to comment.