src/solaris/native/sun/tools/attach/BsdVirtualMachine.c
Print this page
rev 9543 : 8038233: Fix unsafe strcpy in Java_sun_tools_attach_{Aix,Bsd,Linux}VirtualMachine_connect()
@@ -76,12 +76,14 @@
const char* p = GetStringPlatformChars(env, path, &isCopy);
if (p != NULL) {
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;
}