Skip to content

Commit

Permalink
8303617: update for deprecated sprintf for jdk.jdwp.agent
Browse files Browse the repository at this point in the history
Reviewed-by: cjplummer, sspitsyn
  • Loading branch information
XueleiFan committed Mar 8, 2023
1 parent ddcb369 commit d287a5e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
12 changes: 4 additions & 8 deletions src/jdk.jdwp.agent/share/native/libdt_socket/socketTransport.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 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 @@ -220,11 +220,7 @@ handshake(int fd, jlong timeout) {
if (strncmp(b, hello, received) != 0) {
char msg[80+2*16];
b[received] = '\0';
/*
* We should really use snprintf here but it's not available on Windows.
* We can't use jio_snprintf without linking the transport against the VM.
*/
sprintf(msg, "handshake failed - received >%s< - expected >%s<", b, hello);
snprintf(msg, sizeof(msg), "handshake failed - received >%s< - expected >%s<", b, hello);
setLastError(0, msg);
return JDWPTRANSPORT_ERROR_IO_ERROR;
}
Expand Down Expand Up @@ -690,7 +686,7 @@ static jdwpTransportError startListening(struct addrinfo *ai, int *socket, char*
}

portNum = getPort((struct sockaddr *)&addr);
sprintf(buf, "%d", portNum);
snprintf(buf, sizeof(buf), "%d", portNum);
*actualAddress = (*callback->alloc)((int)strlen(buf) + 1);
if (*actualAddress == NULL) {
RETURN_ERROR(JDWPTRANSPORT_ERROR_OUT_OF_MEMORY, "out of memory");
Expand Down Expand Up @@ -858,7 +854,7 @@ socketTransport_accept(jdwpTransportEnv* env, jlong acceptTimeout, jlong handsha
int err2 = getnameinfo((struct sockaddr *)&clientAddr, clientAddrLen,
addrStr, sizeof(addrStr), NULL, 0,
NI_NUMERICHOST);
sprintf(ebuf, "ERROR: Peer not allowed to connect: %s\n",
snprintf(ebuf, sizeof(ebuf), "ERROR: Peer not allowed to connect: %s\n",
(err2 != 0) ? "<bad address>" : addrStr);
dbgsysSocketClose(socketFD);
socketFD = -1;
Expand Down
2 changes: 1 addition & 1 deletion src/jdk.jdwp.agent/windows/native/libdt_socket/socket_md.c
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ dbgsysGetLastIOError(char *buf, jint size) {
if (i < table_size) {
strcpy(buf, winsock_errors[i].errString);
} else {
sprintf(buf, "winsock error %d", error);
snprintf(buf, size, "winsock error %d", error);
}
return 0;
}
Expand Down
4 changes: 2 additions & 2 deletions src/jdk.jdwp.agent/windows/native/libjdwp/linker_md.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 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 @@ -119,7 +119,7 @@ dbgsysBuildLibName(char *holder, int holderlen, const char *pname, const char *f
EXIT_ERROR(JVMTI_ERROR_INVALID_LOCATION, "One or more of the library paths supplied to jdwp, "
"likely by sun.boot.library.path, is too long.");
}
sprintf(holder, "%s.dll", fname);
snprintf(holder, holderlen, "%s.dll", fname);
} else {
dll_build_name(holder, holderlen, pname, fname);
}
Expand Down

1 comment on commit d287a5e

@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.