diff --git a/src/jdk.jdi/share/native/libdt_shmem/SharedMemoryTransport.c b/src/jdk.jdi/share/native/libdt_shmem/SharedMemoryTransport.c index 05e34233aff..89f6c5562ba 100644 --- a/src/jdk.jdi/share/native/libdt_shmem/SharedMemoryTransport.c +++ b/src/jdk.jdi/share/native/libdt_shmem/SharedMemoryTransport.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2004, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 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 @@ -64,9 +64,9 @@ throwShmemException(JNIEnv *env, char *message, jint errorCode) char buf[255]; if (shmemBase_getlasterror(msg, sizeof(msg)) == SYS_OK) { - sprintf(buf, "%s: %s\n", message, msg); + snprintf(buf, sizeof(buf), "%s: %s\n", message, msg); } else { - sprintf(buf, "%s, error code = %d", message, errorCode); + snprintf(buf, sizeof(buf), "%s, error code = %d", message, errorCode); } throwException(env, "java/io/IOException", buf); } diff --git a/src/jdk.jdi/share/native/libdt_shmem/shmemBase.c b/src/jdk.jdi/share/native/libdt_shmem/shmemBase.c index 77266af3627..2277dca8381 100644 --- a/src/jdk.jdi/share/native/libdt_shmem/shmemBase.c +++ b/src/jdk.jdi/share/native/libdt_shmem/shmemBase.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2020, 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 @@ -227,7 +227,7 @@ createWithGeneratedName(char *prefix, char *nameBuffer, CreateFunc func, void *a strcpy(nameBuffer, prefix); if (i > 0) { char buf[10]; - sprintf(buf, ".%d", i+1); + snprintf(buf, sizeof(buf), ".%d", i+1); strcat(nameBuffer, buf); } error = func(nameBuffer, arg); @@ -406,14 +406,14 @@ createStream(char *name, Stream *stream) jint error; char objectName[MAX_IPC_NAME]; - sprintf(objectName, "%s.mutex", name); + snprintf(objectName, sizeof(objectName), "%s.mutex", name); error = createWithGeneratedName(objectName, stream->shared->mutexName, createMutex, &stream->mutex); if (error != SYS_OK) { return error; } - sprintf(objectName, "%s.hasData", name); + snprintf(objectName, sizeof(objectName), "%s.hasData", name); error = createWithGeneratedName(objectName, stream->shared->hasDataEventName, createEvent, &stream->hasData); if (error != SYS_OK) { @@ -421,7 +421,7 @@ createStream(char *name, Stream *stream) return error; } - sprintf(objectName, "%s.hasSpace", name); + snprintf(objectName, sizeof(objectName), "%s.hasSpace", name); error = createWithGeneratedName(objectName, stream->shared->hasSpaceEventName, createEvent, &stream->hasSpace); if (error != SYS_OK) { @@ -541,7 +541,7 @@ openConnection(SharedMemoryTransport *transport, jlong otherPID, return SYS_NOMEM; } - sprintf(connection->name, "%s.%" PRId64, transport->name, sysProcessGetID()); + snprintf(connection->name, sizeof(connection->name), "%s.%" PRId64, transport->name, sysProcessGetID()); error = sysSharedMemOpen(connection->name, &connection->sharedMemory, &connection->shared); if (error != SYS_OK) { @@ -605,7 +605,7 @@ createConnection(SharedMemoryTransport *transport, jlong otherPID, return SYS_NOMEM; } - sprintf(connection->name, "%s.%" PRId64, transport->name, otherPID); + snprintf(connection->name, sizeof(connection->name), "%s.%" PRId64, transport->name, otherPID); error = sysSharedMemCreate(connection->name, sizeof(SharedMemory), &connection->sharedMemory, &connection->shared); if (error != SYS_OK) { @@ -700,7 +700,7 @@ openTransport(const char *address, SharedMemoryTransport **transportPtr) if (strlen(address) >= MAX_IPC_PREFIX) { char buf[128]; - sprintf(buf, "Error: address strings longer than %d characters are invalid\n", MAX_IPC_PREFIX); + snprintf(buf, sizeof(buf), "Error: address strings longer than %d characters are invalid\n", MAX_IPC_PREFIX); setLastErrorMsg(buf); closeTransport(transport); return SYS_ERR; @@ -764,7 +764,7 @@ createTransport(const char *address, SharedMemoryTransport **transportPtr) } else { if (strlen(address) >= MAX_IPC_PREFIX) { char buf[128]; - sprintf(buf, "Error: address strings longer than %d characters are invalid\n", MAX_IPC_PREFIX); + snprintf(buf, sizeof(buf), "Error: address strings longer than %d characters are invalid\n", MAX_IPC_PREFIX); setLastErrorMsg(buf); closeTransport(transport); return SYS_ERR; @@ -782,7 +782,7 @@ createTransport(const char *address, SharedMemoryTransport **transportPtr) memset(transport->shared, 0, sizeof(SharedListener)); transport->shared->acceptingPID = sysProcessGetID(); - sprintf(objectName, "%s.mutex", transport->name); + snprintf(objectName, sizeof(objectName), "%s.mutex", transport->name); error = createWithGeneratedName(objectName, transport->shared->mutexName, createMutex, &transport->mutex); if (error != SYS_OK) { @@ -790,7 +790,7 @@ createTransport(const char *address, SharedMemoryTransport **transportPtr) return error; } - sprintf(objectName, "%s.accept", transport->name); + snprintf(objectName, sizeof(objectName), "%s.accept", transport->name); error = createWithGeneratedName(objectName, transport->shared->acceptEventName, createEvent, &transport->acceptEvent); if (error != SYS_OK) { @@ -798,7 +798,7 @@ createTransport(const char *address, SharedMemoryTransport **transportPtr) return error; } - sprintf(objectName, "%s.attach", transport->name); + snprintf(objectName, sizeof(objectName), "%s.attach", transport->name); error = createWithGeneratedName(objectName, transport->shared->attachEventName, createEvent, &transport->attachEvent); if (error != SYS_OK) { @@ -1169,7 +1169,7 @@ exitTransportWithError(char *message, char *fileName, jint error; char buffer[500]; - sprintf(buffer, "Shared Memory Transport \"%s\" (%s), line %d: %s\n", + snprintf(buffer, sizeof(buffer), "Shared Memory Transport \"%s\" (%s), line %d: %s\n", fileName, date, lineNumber, message); error = (*jvm)->GetEnv(jvm, (void **)&env, JNI_VERSION_1_2); if (error != JNI_OK) {