8303527: update for deprecated sprintf for jdk.hotspot.agent

Reviewed-by: cjplummer
This commit is contained in:
Xue-Lei Andrew Fan 2023-03-03 18:11:48 +00:00
parent 40c5edfcc4
commit a50dc67a4f
2 changed files with 6 additions and 5 deletions
src/jdk.hotspot.agent
linux/native/libsaproc
windows/native/libsaproc

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 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
@ -231,7 +231,7 @@ static bool process_doesnt_exist(pid_t pid) {
FILE *fp = NULL;
const char state_string[] = "State:";
sprintf(fname, "/proc/%d/status", pid);
snprintf(fname, sizeof(fname), "/proc/%d/status", pid);
fp = fopen(fname, "r");
if (fp == NULL) {
print_debug("can't open /proc/%d/status file\n", pid);
@ -350,7 +350,7 @@ static bool read_lib_info(struct ps_prochandle* ph) {
char buf[PATH_MAX];
FILE *fp = NULL;
sprintf(fname, "/proc/%d/maps", ph->pid);
snprintf(fname, sizeof(fname), "/proc/%d/maps", ph->pid);
fp = fopen(fname, "r");
if (fp == NULL) {
print_debug("can't open /proc/%d/maps file\n", ph->pid);

@ -185,11 +185,12 @@ static void throwNewDebuggerException(JNIEnv* env, const char* errMsg) {
do { \
const HRESULT hr = (v); \
if (hr != S_OK) { \
AutoArrayPtr<char> errmsg(new char[strlen(str) + 32]); \
size_t errmsg_size = strlen(str) + 32; \
AutoArrayPtr<char> errmsg(new char[errmsg_size]); \
if (errmsg == nullptr) { \
THROW_NEW_DEBUGGER_EXCEPTION_(str, retValue); \
} else { \
sprintf(errmsg, "%s (hr: 0x%08X)", str, hr); \
snprintf(errmsg, errmsg_size, "%s (hr: 0x%08X)", str, hr); \
THROW_NEW_DEBUGGER_EXCEPTION_(errmsg, retValue); \
} \
} \