diff --git a/src/java.base/unix/native/libnet/PlainDatagramSocketImpl.c b/src/java.base/unix/native/libnet/PlainDatagramSocketImpl.c index b75b18b1f0..f1ea49683e 100644 --- a/src/java.base/unix/native/libnet/PlainDatagramSocketImpl.c +++ b/src/java.base/unix/native/libnet/PlainDatagramSocketImpl.c @@ -22,6 +22,11 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ +/* + * =========================================================================== + * (c) Copyright IBM Corp. 2024, 2024 All Rights Reserved + * =========================================================================== + */ #include #include #include @@ -1579,7 +1584,7 @@ jobject getMulticastInterface(JNIEnv *env, jobject this, int fd, jint opt) { index); if (ni == NULL) { char errmsg[255]; - sprintf(errmsg, + snprintf(errmsg, sizeof(errmsg), "IPV6_MULTICAST_IF returned index to unrecognized interface: %d", index); JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", errmsg); diff --git a/src/java.base/windows/native/libnet/NetworkInterface_winXP.c b/src/java.base/windows/native/libnet/NetworkInterface_winXP.c index 85b052b5f5..545cab02c6 100644 --- a/src/java.base/windows/native/libnet/NetworkInterface_winXP.c +++ b/src/java.base/windows/native/libnet/NetworkInterface_winXP.c @@ -22,6 +22,11 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ +/* + * =========================================================================== + * (c) Copyright IBM Corp. 2024, 2024 All Rights Reserved + * =========================================================================== + */ #include "net_util.h" #include "NetworkInterface.h" @@ -347,10 +352,10 @@ int getAllInterfacesAndAddresses (JNIEnv *env, netif **netifPP) goto err; } if (ptr->IfType == IF_TYPE_TUNNEL) { - sprintf (newname, "tun%d", tun); + snprintf (newname, sizeof(newname), "tun%d", tun); tun ++; } else { - sprintf (newname, "net%d", net); + snprintf (newname, sizeof(newname), "net%d", net); net ++; } nif->name = malloc (strlen(newname)+1); diff --git a/src/java.base/windows/native/libnet/TwoStacksPlainDatagramSocketImpl.c b/src/java.base/windows/native/libnet/TwoStacksPlainDatagramSocketImpl.c index ae7d585b81..fdb1ed49e3 100644 --- a/src/java.base/windows/native/libnet/TwoStacksPlainDatagramSocketImpl.c +++ b/src/java.base/windows/native/libnet/TwoStacksPlainDatagramSocketImpl.c @@ -22,6 +22,11 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ +/* + * =========================================================================== + * (c) Copyright IBM Corp. 2024, 2024 All Rights Reserved + * =========================================================================== + */ #include #include "net_util.h" @@ -1864,7 +1869,7 @@ jobject getMulticastInterface(JNIEnv *env, jobject this, int fd, int fd1, jint o index); if (ni == NULL) { char errmsg[255]; - sprintf(errmsg, + snprintf(errmsg, sizeof(errmsg), "IPV6_MULTICAST_IF returned index to unrecognized interface: %d", index); JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", errmsg); @@ -1983,7 +1988,7 @@ Java_java_net_TwoStacksPlainDatagramSocketImpl_socketGetOption int size = 0; char errmsg[255 + 31]; getErrorString(errno, tmpbuf, sizeof(tmpbuf)); - sprintf(errmsg, "error getting socket option: %s", tmpbuf); + snprintf(errmsg, sizeof(errmsg), "error getting socket option: %s", tmpbuf); JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", errmsg); return NULL; }