# HG changeset patch # User simonis # Date 1395940987 -3600 # Node ID b8e3e39834cc6471a9c3322da5f54129554d523d # Parent cea254e9725029a2ec8039e7b80f322bc18f4e1f 8038233: Fix unsafe strcpy in Java_sun_tools_attach_{Aix,Bsd,Linux}VirtualMachine_connect() diff --git a/src/aix/native/sun/tools/attach/AixVirtualMachine.c b/src/aix/native/sun/tools/attach/AixVirtualMachine.c --- a/src/aix/native/sun/tools/attach/AixVirtualMachine.c +++ b/src/aix/native/sun/tools/attach/AixVirtualMachine.c @@ -1,6 +1,6 @@ /* - * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved. - * Copyright 2013 SAP AG. All rights reserved. + * Copyright (c) 2008, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright 2014 SAP AG. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -92,10 +92,10 @@ struct sockaddr_un addr; int err = 0; - /* added missing structure initialization */ - memset(&addr,0, sizeof(addr)); + memset(&addr, 0, sizeof(addr)); addr.sun_family = AF_UNIX; - strcpy(addr.sun_path, p); + /* strncpy is safe because addr.sun_path was zero-initialized before. */ + strncpy(addr.sun_path, p, sizeof(addr.sun_path) - 1); /* We must call bind with the actual socketaddr length. This is obligatory for AS400. */ if (connect(fd, (struct sockaddr*)&addr, SUN_LEN(&addr)) == -1) { err = errno; diff --git a/src/solaris/native/sun/tools/attach/BsdVirtualMachine.c b/src/solaris/native/sun/tools/attach/BsdVirtualMachine.c --- a/src/solaris/native/sun/tools/attach/BsdVirtualMachine.c +++ b/src/solaris/native/sun/tools/attach/BsdVirtualMachine.c @@ -78,8 +78,10 @@ struct sockaddr_un addr; int err = 0; + memset(&addr, 0, sizeof(addr)); addr.sun_family = AF_UNIX; - strcpy(addr.sun_path, p); + /* strncpy is safe because addr.sun_path was zero-initialized before. */ + strncpy(addr.sun_path, p, sizeof(addr.sun_path) - 1); if (connect(fd, (struct sockaddr*)&addr, sizeof(addr)) == -1) { err = errno; diff --git a/src/solaris/native/sun/tools/attach/LinuxVirtualMachine.c b/src/solaris/native/sun/tools/attach/LinuxVirtualMachine.c --- a/src/solaris/native/sun/tools/attach/LinuxVirtualMachine.c +++ b/src/solaris/native/sun/tools/attach/LinuxVirtualMachine.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -156,8 +156,10 @@ struct sockaddr_un addr; int err = 0; + memset(&addr, 0, sizeof(addr)); addr.sun_family = AF_UNIX; - strcpy(addr.sun_path, p); + /* strncpy is safe because addr.sun_path was zero-initialized before. */ + strncpy(addr.sun_path, p, sizeof(addr.sun_path) - 1); if (connect(fd, (struct sockaddr*)&addr, sizeof(addr)) == -1) { err = errno;