Skip to content

Commit

Permalink
8308801: update for deprecated sprintf for libnet in java.base
Browse files Browse the repository at this point in the history
Backport-of: c72b5474255d56f704930509525de69711dd9bfb
  • Loading branch information
gdams committed Jul 6, 2024
1 parent f019a81 commit 6d2c7a7
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/java.base/unix/native/libnet/NetworkInterface.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2023, 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
Expand Down Expand Up @@ -1271,7 +1271,7 @@ static netif *enumIPv6Interfaces(JNIEnv *env, int sock, netif *ifs) {
char addr6[40];
struct sockaddr_in6 addr;

sprintf(addr6, "%s:%s:%s:%s:%s:%s:%s:%s",
snprintf(addr6, sizeof(addr6), "%s:%s:%s:%s:%s:%s:%s:%s",
addr6p[0], addr6p[1], addr6p[2], addr6p[3],
addr6p[4], addr6p[5], addr6p[6], addr6p[7]);

Expand Down
4 changes: 2 additions & 2 deletions src/java.base/unix/native/libnet/net_util_md.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2023, 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
Expand Down Expand Up @@ -221,7 +221,7 @@ void NET_ThrowUnknownHostExceptionWithGaiError(JNIEnv *env,
buf = (char *) malloc(size);
if (buf) {
jstring s;
sprintf(buf, format, hostname, error_string);
snprintf(buf, size, format, hostname, error_string);
s = JNU_NewStringPlatform(env, buf);
if (s != NULL) {
jobject x = JNU_NewObjectByName(env,
Expand Down
4 changes: 2 additions & 2 deletions src/java.base/windows/native/libnet/net_util_md.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2023, 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
Expand Down Expand Up @@ -189,7 +189,7 @@ NET_ThrowNew(JNIEnv *env, int errorNum, char *msg)
if (excP == NULL) {
excP = "SocketException";
}
sprintf(exc, "%s%s", JNU_JAVANETPKG, excP);
snprintf(exc, sizeof(exc), "%s%s", JNU_JAVANETPKG, excP);
JNU_ThrowByName(env, exc, fullMsg);
}

Expand Down

1 comment on commit 6d2c7a7

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.