diff --git a/cli/fossilize_disasm.cpp b/cli/fossilize_disasm.cpp index cf4383a9..f29e1bac 100644 --- a/cli/fossilize_disasm.cpp +++ b/cli/fossilize_disasm.cpp @@ -876,7 +876,7 @@ static void print_help() static string uint64_string(uint64_t value) { char str[17]; // 16 digits + null - sprintf(str, "%016" PRIx64, value); + snprintf(str, sizeof(str), "%016" PRIx64, value); return string(str); } diff --git a/cli/fossilize_replay.cpp b/cli/fossilize_replay.cpp index 012128ef..73f1a300 100644 --- a/cli/fossilize_replay.cpp +++ b/cli/fossilize_replay.cpp @@ -1692,7 +1692,7 @@ struct ThreadedReplayer : StateCreatorInterface auto &props = device->get_module_identifier_properties(); char uuid_string[2 * VK_UUID_SIZE + 1]; for (unsigned i = 0; i < VK_UUID_SIZE; i++) - sprintf(uuid_string + 2 * i, "%02x", props.shaderModuleIdentifierAlgorithmUUID[i]); + snprintf(uuid_string + 2 * i, 2 * VK_UUID_SIZE + 1 - 2 * i, "%02x", props.shaderModuleIdentifierAlgorithmUUID[i]); report_module_uuid(uuid_string); diff --git a/cli/fossilize_replay_linux.hpp b/cli/fossilize_replay_linux.hpp index f01ef3ef..163e7421 100644 --- a/cli/fossilize_replay_linux.hpp +++ b/cli/fossilize_replay_linux.hpp @@ -202,7 +202,7 @@ void ProcessProgress::parse(const char *cmd) if (Global::control_block && graphics_progress > 0 && graphics_pipeline != 0) { char buffer[ControlBlockMessageSize]; - sprintf(buffer, "GRAPHICS %d %" PRIx64 "\n", graphics_progress - 1, graphics_pipeline); + snprintf(buffer, ControlBlockMessageSize, "GRAPHICS %d %" PRIx64 "\n", graphics_progress - 1, graphics_pipeline); futex_wrapper_lock(&Global::control_block->futex_lock); shared_control_block_write(Global::control_block, buffer, sizeof(buffer)); futex_wrapper_unlock(&Global::control_block->futex_lock); @@ -220,7 +220,7 @@ void ProcessProgress::parse(const char *cmd) if (Global::control_block && raytracing_progress > 0 && raytracing_pipeline != 0) { char buffer[ControlBlockMessageSize]; - sprintf(buffer, "RAYTRACE %d %" PRIx64 "\n", raytracing_progress - 1, raytracing_pipeline); + snprintf(buffer, ControlBlockMessageSize, "RAYTRACE %d %" PRIx64 "\n", raytracing_progress - 1, raytracing_pipeline); futex_wrapper_lock(&Global::control_block->futex_lock); shared_control_block_write(Global::control_block, buffer, sizeof(buffer)); futex_wrapper_unlock(&Global::control_block->futex_lock); @@ -238,7 +238,7 @@ void ProcessProgress::parse(const char *cmd) if (Global::control_block && compute_progress > 0 && compute_pipeline) { char buffer[ControlBlockMessageSize]; - sprintf(buffer, "COMPUTE %d %" PRIx64 "\n", compute_progress - 1, compute_pipeline); + snprintf(buffer, ControlBlockMessageSize, "COMPUTE %d %" PRIx64 "\n", compute_progress - 1, compute_pipeline); futex_wrapper_lock(&Global::control_block->futex_lock); shared_control_block_write(Global::control_block, buffer, sizeof(buffer)); futex_wrapper_unlock(&Global::control_block->futex_lock); @@ -417,7 +417,7 @@ static void send_faulty_modules_and_close(int fd) for (auto &m : Global::faulty_spirv_modules) { char buffer[18]; - sprintf(buffer, "%" PRIx64 "\n", m); + snprintf(buffer, sizeof(buffer), "%" PRIx64 "\n", m); write_all(fd, buffer); } @@ -1426,19 +1426,19 @@ static void validation_error_cb(ThreadedReplayer *replayer) if (per_thread.current_graphics_pipeline) { - sprintf(buffer, "GRAPHICS_VERR %" PRIx64 "\n", per_thread.current_graphics_pipeline); + snprintf(buffer, sizeof(buffer), "GRAPHICS_VERR %" PRIx64 "\n", per_thread.current_graphics_pipeline); write_all(crash_fd, buffer); } if (per_thread.current_compute_pipeline) { - sprintf(buffer, "COMPUTE_VERR %" PRIx64 "\n", per_thread.current_compute_pipeline); + snprintf(buffer, sizeof(buffer), "COMPUTE_VERR %" PRIx64 "\n", per_thread.current_compute_pipeline); write_all(crash_fd, buffer); } if (per_thread.current_raytracing_pipeline) { - sprintf(buffer, "RAYTRACE_VERR %" PRIx64 "\n", per_thread.current_raytracing_pipeline); + snprintf(buffer, sizeof(buffer), "RAYTRACE_VERR %" PRIx64 "\n", per_thread.current_raytracing_pipeline); write_all(crash_fd, buffer); } } @@ -1448,7 +1448,7 @@ static void report_module_uuid(const char (&path)[2 * VK_UUID_SIZE + 1]) if (crash_fd >= 0) { char buffer[64]; - sprintf(buffer, "MODULE_UUID %s\n", path); + snprintf(buffer, sizeof(buffer), "MODULE_UUID %s\n", path); if (!write_all(crash_fd, buffer)) _exit(2); } @@ -1462,7 +1462,7 @@ static void crash_handler(ThreadedReplayer &replayer, ThreadedReplayer::PerThrea // This allows a new process to ignore these modules. for (unsigned i = 0; i < per_thread.num_failed_module_hashes; i++) { - sprintf(buffer, "MODULE %" PRIx64 "\n", per_thread.failed_module_hashes[i]); + snprintf(buffer, sizeof(buffer), "MODULE %" PRIx64 "\n", per_thread.failed_module_hashes[i]); if (!write_all(crash_fd, buffer)) _exit(2); } @@ -1475,18 +1475,18 @@ static void crash_handler(ThreadedReplayer &replayer, ThreadedReplayer::PerThrea per_thread.current_raytracing_pipeline) { // Report where we stopped, so we can continue. - sprintf(buffer, "GRAPHICS %d %" PRIx64 "\n", per_thread.current_graphics_index, - per_thread.current_graphics_pipeline); + snprintf(buffer, sizeof(buffer), "GRAPHICS %d %" PRIx64 "\n", per_thread.current_graphics_index, + per_thread.current_graphics_pipeline); if (!write_all(crash_fd, buffer)) _exit(2); - sprintf(buffer, "COMPUTE %d %" PRIx64 "\n", per_thread.current_compute_index, - per_thread.current_compute_pipeline); + snprintf(buffer, sizeof(buffer), "COMPUTE %d %" PRIx64 "\n", per_thread.current_compute_index, + per_thread.current_compute_pipeline); if (!write_all(crash_fd, buffer)) _exit(2); - sprintf(buffer, "RAYTRACE %d %" PRIx64 "\n", per_thread.current_raytracing_index, - per_thread.current_raytracing_pipeline); + snprintf(buffer, sizeof(buffer), "RAYTRACE %d %" PRIx64 "\n", per_thread.current_raytracing_index, + per_thread.current_raytracing_pipeline); if (!write_all(crash_fd, buffer)) _exit(2); } @@ -1707,7 +1707,7 @@ static int run_slave_process(const VulkanDevice::Options &opts, { futex_wrapper_lock(&Global::control_block->futex_lock); char msg[ControlBlockMessageSize] = {}; - sprintf(msg, "SLAVE_FINISHED\n"); + snprintf(msg, ControlBlockMessageSize, "SLAVE_FINISHED\n"); shared_control_block_write(Global::control_block, msg, sizeof(msg)); futex_wrapper_unlock(&Global::control_block->futex_lock); } @@ -1719,7 +1719,7 @@ static int run_slave_process(const VulkanDevice::Options &opts, static void log_process_memory() { char path[1024]; - sprintf(path, "/proc/%d/status", getpid()); + snprintf(path, sizeof(path), "/proc/%d/status", getpid()); FILE *file = fopen(path, "r"); if (!file) { diff --git a/cli/fossilize_replay_windows.hpp b/cli/fossilize_replay_windows.hpp index 3746f546..88734ea4 100644 --- a/cli/fossilize_replay_windows.hpp +++ b/cli/fossilize_replay_windows.hpp @@ -164,7 +164,7 @@ void ProcessProgress::parse(const char *cmd) if (Global::control_block && graphics_progress > 0 && graphics_pipeline != 0) { char buffer[ControlBlockMessageSize]; - sprintf(buffer, "GRAPHICS %d %" PRIx64 "\n", graphics_progress - 1, graphics_pipeline); + snprintf(buffer, ControlBlockMessageSize, "GRAPHICS %d %" PRIx64 "\n", graphics_progress - 1, graphics_pipeline); if (WaitForSingleObject(Global::shared_mutex, INFINITE) == WAIT_OBJECT_0) { @@ -185,7 +185,7 @@ void ProcessProgress::parse(const char *cmd) if (Global::control_block && raytracing_progress > 0 && raytracing_pipeline != 0) { char buffer[ControlBlockMessageSize]; - sprintf(buffer, "RAYTRACE %d %" PRIx64 "\n", raytracing_progress - 1, raytracing_pipeline); + snprintf(buffer, ControlBlockMessageSize, "RAYTRACE %d %" PRIx64 "\n", raytracing_progress - 1, raytracing_pipeline); if (WaitForSingleObject(Global::shared_mutex, INFINITE) == WAIT_OBJECT_0) { @@ -206,7 +206,7 @@ void ProcessProgress::parse(const char *cmd) if (Global::control_block && compute_progress > 0 && compute_pipeline) { char buffer[ControlBlockMessageSize]; - sprintf(buffer, "COMPUTE %d %" PRIx64 "\n", compute_progress - 1, compute_pipeline); + snprintf(buffer, ControlBlockMessageSize, "COMPUTE %d %" PRIx64 "\n", compute_progress - 1, compute_pipeline); if (WaitForSingleObject(Global::shared_mutex, INFINITE) == WAIT_OBJECT_0) { @@ -351,7 +351,7 @@ static void send_faulty_modules_and_close(HANDLE file) for (auto &m : Global::faulty_spirv_modules) { char buffer[18]; - sprintf(buffer, "%" PRIx64 "\n", m); + snprintf(buffer, sizeof(buffer), "%" PRIx64 "\n", m); write_all(file, buffer); } @@ -368,7 +368,7 @@ static bool CreateCustomPipe(HANDLE *read_pipe, HANDLE *write_pipe, LPSECURITY_A // This is so that we can safely read one message at a time with ReadFile rather than rely on fgets to delimit each message for us. static unsigned pipe_serial; char pipe_name_buffer[MAX_PATH]; - sprintf(pipe_name_buffer, "\\\\.\\Pipe\\Fossilize.%08lx.%08x", GetCurrentProcessId(), pipe_serial++); + snprintf(pipe_name_buffer, sizeof(pipe_name_buffer), "\\\\.\\Pipe\\Fossilize.%08lx.%08x", GetCurrentProcessId(), pipe_serial++); *read_pipe = CreateNamedPipeA(pipe_name_buffer, PIPE_ACCESS_INBOUND | (overlapped_read ? FILE_FLAG_OVERLAPPED : 0), PIPE_TYPE_MESSAGE | PIPE_WAIT | PIPE_READMODE_MESSAGE, 1, 4096, 4096, 10000, attrs); @@ -1045,19 +1045,19 @@ static void validation_error_cb(ThreadedReplayer *replayer) if (per_thread.current_graphics_pipeline) { - sprintf(buffer, "GRAPHICS_VERR %" PRIx64 "\n", per_thread.current_graphics_pipeline); + snprintf(buffer, sizeof(buffer), "GRAPHICS_VERR %" PRIx64 "\n", per_thread.current_graphics_pipeline); write_all(crash_handle, buffer); } if (per_thread.current_compute_pipeline) { - sprintf(buffer, "COMPUTE_VERR %" PRIx64 "\n", per_thread.current_compute_pipeline); + snprintf(buffer, sizeof(buffer), "COMPUTE_VERR %" PRIx64 "\n", per_thread.current_compute_pipeline); write_all(crash_handle, buffer); } if (per_thread.current_raytracing_pipeline) { - sprintf(buffer, "RAYTRACE_VERR %" PRIx64 "\n", per_thread.current_raytracing_pipeline); + snprintf(buffer, sizeof(buffer), "RAYTRACE_VERR %" PRIx64 "\n", per_thread.current_raytracing_pipeline); write_all(crash_handle, buffer); } } @@ -1067,7 +1067,7 @@ static void report_module_uuid(const char (&path)[2 * VK_UUID_SIZE + 1]) if (crash_handle) { char buffer[64]; - sprintf(buffer, "MODULE_UUID %s\n", path); + snprintf(buffer, sizeof(buffer), "MODULE_UUID %s\n", path); if (!write_all(crash_handle, buffer)) ExitProcess(2); } @@ -1081,7 +1081,7 @@ static void crash_handler(ThreadedReplayer &replayer, ThreadedReplayer::PerThrea // This allows a new process to ignore these modules. for (unsigned i = 0; i < per_thread.num_failed_module_hashes; i++) { - sprintf(buffer, "MODULE %" PRIx64 "\n", per_thread.failed_module_hashes[i]); + snprintf(buffer, sizeof(buffer), "MODULE %" PRIx64 "\n", per_thread.failed_module_hashes[i]); if (!write_all(crash_handle, buffer)) ExitProcess(2); } @@ -1094,17 +1094,17 @@ static void crash_handler(ThreadedReplayer &replayer, ThreadedReplayer::PerThrea per_thread.current_raytracing_pipeline) { // Report where we stopped, so we can continue. - sprintf(buffer, "GRAPHICS %d %" PRIx64 "\n", per_thread.current_graphics_index, + snprintf(buffer, sizeof(buffer), "GRAPHICS %d %" PRIx64 "\n", per_thread.current_graphics_index, per_thread.current_graphics_pipeline); if (!write_all(crash_handle, buffer)) ExitProcess(2); - sprintf(buffer, "COMPUTE %d %" PRIx64 "\n", per_thread.current_compute_index, + snprintf(buffer, sizeof(buffer), "COMPUTE %d %" PRIx64 "\n", per_thread.current_compute_index, per_thread.current_compute_pipeline); if (!write_all(crash_handle, buffer)) ExitProcess(2); - sprintf(buffer, "RAYTRACE %d %" PRIx64 "\n", per_thread.current_raytracing_index, + snprintf(buffer, sizeof(buffer), "RAYTRACE %d %" PRIx64 "\n", per_thread.current_raytracing_index, per_thread.current_raytracing_pipeline); if (!write_all(crash_handle, buffer)) ExitProcess(2); @@ -1325,7 +1325,7 @@ static int run_slave_process(const VulkanDevice::Options &opts, if (WaitForSingleObject(Global::shared_mutex, INFINITE) == WAIT_OBJECT_0) { char msg[ControlBlockMessageSize] = {}; - sprintf(msg, "SLAVE_FINISHED\n"); + snprintf(msg, ControlBlockMessageSize, "SLAVE_FINISHED\n"); shared_control_block_write(Global::control_block, msg, sizeof(msg)); ReleaseMutex(Global::shared_mutex); } diff --git a/fossilize.cpp b/fossilize.cpp index b05f9c3f..086d0914 100644 --- a/fossilize.cpp +++ b/fossilize.cpp @@ -111,7 +111,7 @@ template static Value uint64_string(uint64_t value, Allocator &alloc) { char str[17]; // 16 digits + null - sprintf(str, "%016" PRIx64, value); + snprintf(str, sizeof(str), "%016" PRIx64, value); return Value(str, alloc); } diff --git a/fossilize_db.cpp b/fossilize_db.cpp index 283313bd..098626e0 100644 --- a/fossilize_db.cpp +++ b/fossilize_db.cpp @@ -594,7 +594,7 @@ struct DumbDirectoryDatabase : DatabaseInterface return false; char filename[25]; // 2 digits + "." + 16 digits + ".json" + null - sprintf(filename, "%02x.%016" PRIx64 ".json", static_cast(tag), hash); + snprintf(filename, sizeof(filename), "%02x.%016" PRIx64 ".json", static_cast(tag), hash); auto path = Path::join(base_directory, filename); FILE *file = fopen(path.c_str(), "rb"); @@ -646,7 +646,7 @@ struct DumbDirectoryDatabase : DatabaseInterface return true; char filename[25]; // 2 digits + "." + 16 digits + ".json" + null - sprintf(filename, "%02x.%016" PRIx64 ".json", static_cast(tag), hash); + snprintf(filename, sizeof(filename), "%02x.%016" PRIx64 ".json", static_cast(tag), hash); auto path = Path::join(base_directory, filename); FILE *file = fopen(path.c_str(), "wb"); @@ -862,8 +862,8 @@ struct ZipDatabase : DatabaseInterface return true; char str[FOSSILIZE_BLOB_HASH_LENGTH + 1]; // 40 digits + null - sprintf(str, "%0*x", FOSSILIZE_BLOB_HASH_LENGTH - 16, tag); - sprintf(str + FOSSILIZE_BLOB_HASH_LENGTH - 16, "%016" PRIx64, hash); + snprintf(str, FOSSILIZE_BLOB_HASH_LENGTH + 1, "%0*x", FOSSILIZE_BLOB_HASH_LENGTH - 16, tag); + snprintf(str + FOSSILIZE_BLOB_HASH_LENGTH - 16, 17, "%016" PRIx64, hash); unsigned mz_flags; if ((flags & PAYLOAD_WRITE_COMPRESS_BIT) != 0) @@ -1353,8 +1353,8 @@ struct StreamArchive : DatabaseInterface return true; char str[FOSSILIZE_BLOB_HASH_LENGTH + 1]; // 40 digits + null - sprintf(str, "%0*x", FOSSILIZE_BLOB_HASH_LENGTH - 16, tag); - sprintf(str + FOSSILIZE_BLOB_HASH_LENGTH - 16, "%016" PRIx64, hash); + snprintf(str, FOSSILIZE_BLOB_HASH_LENGTH + 1, "%0*x", FOSSILIZE_BLOB_HASH_LENGTH - 16, tag); + snprintf(str + FOSSILIZE_BLOB_HASH_LENGTH - 16, 17, "%016" PRIx64, hash); if (fwrite(str, 1, FOSSILIZE_BLOB_HASH_LENGTH, file) != FOSSILIZE_BLOB_HASH_LENGTH) return false; diff --git a/fossilize_external_replayer_linux.hpp b/fossilize_external_replayer_linux.hpp index 3a7dbd0b..35f6bf2f 100644 --- a/fossilize_external_replayer_linux.hpp +++ b/fossilize_external_replayer_linux.hpp @@ -593,7 +593,7 @@ bool ExternalReplayer::Impl::get_raytracing_failed_validation(size_t *count, Has void ExternalReplayer::Impl::start_replayer_process(const ExternalReplayer::Options &options, int ctl_fd) { char fd_name[16], control_fd_name[16]; - sprintf(fd_name, "%d", fd); + snprintf(fd_name, sizeof(fd_name), "%d", fd); char num_thread_holder[16]; std::string self_path; @@ -627,7 +627,7 @@ void ExternalReplayer::Impl::start_replayer_process(const ExternalReplayer::Opti if (ctl_fd >= 0) { argv.push_back("--control-fd"); - sprintf(control_fd_name, "%d", ctl_fd); + snprintf(control_fd_name, sizeof(control_fd_name), "%d", ctl_fd); argv.push_back(control_fd_name); } @@ -637,7 +637,7 @@ void ExternalReplayer::Impl::start_replayer_process(const ExternalReplayer::Opti if (options.num_threads) { argv.push_back("--num-threads"); - sprintf(num_thread_holder, "%u", options.num_threads); + snprintf(num_thread_holder, sizeof(num_thread_holder), "%u", options.num_threads); argv.push_back(num_thread_holder); } @@ -671,7 +671,7 @@ void ExternalReplayer::Impl::start_replayer_process(const ExternalReplayer::Opti argv.push_back("--on-disk-replay-whitelist"); argv.push_back(options.on_disk_replay_whitelist); - sprintf(whitelist_hex, "%x", options.on_disk_replay_whitelist_mask); + snprintf(whitelist_hex, sizeof(whitelist_hex), "%x", options.on_disk_replay_whitelist_mask); argv.push_back("--on-disk-replay-whitelist-mask"); argv.push_back(whitelist_hex); } @@ -701,7 +701,7 @@ void ExternalReplayer::Impl::start_replayer_process(const ExternalReplayer::Opti argv.push_back("--device-index"); char index_name[16]; - sprintf(index_name, "%u", options.device_index); + snprintf(index_name, sizeof(index_name), "%u", options.device_index); argv.push_back(index_name); char graphics_range_start[16], graphics_range_end[16]; @@ -711,20 +711,20 @@ void ExternalReplayer::Impl::start_replayer_process(const ExternalReplayer::Opti if (options.use_pipeline_range) { argv.push_back("--graphics-pipeline-range"); - sprintf(graphics_range_start, "%u", options.start_graphics_index); - sprintf(graphics_range_end, "%u", options.end_graphics_index); + snprintf(graphics_range_start, sizeof(graphics_range_start), "%u", options.start_graphics_index); + snprintf(graphics_range_end, sizeof(graphics_range_end), "%u", options.end_graphics_index); argv.push_back(graphics_range_start); argv.push_back(graphics_range_end); argv.push_back("--compute-pipeline-range"); - sprintf(compute_range_start, "%u", options.start_compute_index); - sprintf(compute_range_end, "%u", options.end_compute_index); + snprintf(compute_range_start, sizeof(compute_range_start), "%u", options.start_compute_index); + snprintf(compute_range_end, sizeof(compute_range_end), "%u", options.end_compute_index); argv.push_back(compute_range_start); argv.push_back(compute_range_end); argv.push_back("--raytracing-pipeline-range"); - sprintf(raytracing_range_start, "%u", options.start_raytracing_index); - sprintf(raytracing_range_end, "%u", options.end_raytracing_index); + snprintf(raytracing_range_start, sizeof(raytracing_range_start), "%u", options.start_raytracing_index); + snprintf(raytracing_range_end, sizeof(raytracing_range_end), "%u", options.end_raytracing_index); argv.push_back(raytracing_range_start); argv.push_back(raytracing_range_end); } @@ -739,7 +739,7 @@ void ExternalReplayer::Impl::start_replayer_process(const ExternalReplayer::Opti if (options.timeout_seconds) { argv.push_back("--timeout-seconds"); - sprintf(timeout, "%u", options.timeout_seconds); + snprintf(timeout, sizeof(timeout), "%u", options.timeout_seconds); argv.push_back(timeout); } @@ -748,7 +748,7 @@ void ExternalReplayer::Impl::start_replayer_process(const ExternalReplayer::Opti for (unsigned i = 0; i < options.num_implicit_whitelist_indices; i++) { argv.push_back("--implicit-whitelist"); - sprintf(implicit_indices[i].data(), "%u", options.implicit_whitelist_indices[i]); + snprintf(implicit_indices[i].data(), implicit_indices[i].size(), "%u", options.implicit_whitelist_indices[i]); argv.push_back(implicit_indices[i].data()); } @@ -884,7 +884,7 @@ static bool create_low_priority_autogroup() bool ExternalReplayer::Impl::start(const ExternalReplayer::Options &options) { char shm_name[256]; - sprintf(shm_name, "/fossilize-external-%d-%d", getpid(), shm_index.fetch_add(1, std::memory_order_relaxed)); + snprintf(shm_name, sizeof(shm_name), "/fossilize-external-%d-%d", getpid(), shm_index.fetch_add(1, std::memory_order_relaxed)); fd = shm_open(shm_name, O_RDWR | O_CREAT | O_EXCL, 0600); if (fd < 0) { diff --git a/fossilize_external_replayer_windows.hpp b/fossilize_external_replayer_windows.hpp index cc81c072..7e59f593 100644 --- a/fossilize_external_replayer_windows.hpp +++ b/fossilize_external_replayer_windows.hpp @@ -442,8 +442,8 @@ bool ExternalReplayer::Impl::start(const ExternalReplayer::Options &options) char shm_name[256]; char shm_mutex_name[256]; - sprintf(shm_name, "fossilize-external-%lu-%d", GetCurrentProcessId(), shm_index.fetch_add(1, std::memory_order_relaxed)); - sprintf(shm_mutex_name, "fossilize-external-%lu-%d", GetCurrentProcessId(), shm_index.fetch_add(1, std::memory_order_relaxed)); + snprintf(shm_name, sizeof(shm_name), "fossilize-external-%lu-%d", GetCurrentProcessId(), shm_index.fetch_add(1, std::memory_order_relaxed)); + snprintf(shm_mutex_name, sizeof(shm_mutex_name), "fossilize-external-%lu-%d", GetCurrentProcessId(), shm_index.fetch_add(1, std::memory_order_relaxed)); mapping_handle = CreateFileMappingA(INVALID_HANDLE_VALUE, nullptr, PAGE_READWRITE, 0, (DWORD)shm_block_size, shm_name); if (!mapping_handle) @@ -563,7 +563,7 @@ bool ExternalReplayer::Impl::start(const ExternalReplayer::Options &options) cmdline += " --on-disk-replay-whitelist-mask "; char whitelist_hex[9]; - sprintf(whitelist_hex, "%x", options.on_disk_replay_whitelist_mask); + snprintf(whitelist_hex, sizeof(whitelist_hex), "%x", options.on_disk_replay_whitelist_mask); cmdline += whitelist_hex; } diff --git a/layer/instance.cpp b/layer/instance.cpp index bdde4253..9429dc32 100644 --- a/layer/instance.cpp +++ b/layer/instance.cpp @@ -382,7 +382,7 @@ StateRecorder *Instance::getStateRecorderForDevice(const VkPhysicalDevicePropert needsBucket = false; char hashString[17]; - sprintf(hashString, "%016" PRIx64, hash); + snprintf(hashString, sizeof(hashString), "%016" PRIx64, hash); // Try to normalize the path layouts for last use. // Without buckets: @@ -420,7 +420,7 @@ StateRecorder *Instance::getStateRecorderForDevice(const VkPhysicalDevicePropert { char bucketPath[17]; Hash bucketHash = infoFilter->get_bucket_hash(props, appInfo, device_pnext); - sprintf(bucketPath, "%016" PRIx64, bucketHash); + snprintf(bucketPath, sizeof(bucketPath), "%016" PRIx64, bucketHash); // For convenience. Makes filenames similar in top-level directory and bucket directories. auto basename = Path::basename(serializationPath); @@ -465,7 +465,7 @@ StateRecorder *Instance::getStateRecorderForDevice(const VkPhysicalDevicePropert { char uuidString[2 * VK_UUID_SIZE + 1]; for (unsigned i = 0; i < VK_UUID_SIZE; i++) - sprintf(uuidString + 2 * i, "%02x", identifierProps->shaderModuleIdentifierAlgorithmUUID[i]); + snprintf(uuidString + 2 * i, 2 * VK_UUID_SIZE + 1 - 2 * i, "%02x", identifierProps->shaderModuleIdentifierAlgorithmUUID[i]); std::string identifierDatabasePath = identifierPath; identifierDatabasePath += '.'; diff --git a/miniz/examples/example2.c b/miniz/examples/example2.c index eb0019b0..625f03bf 100755 --- a/miniz/examples/example2.c +++ b/miniz/examples/example2.c @@ -55,8 +55,8 @@ int main(int argc, char *argv[]) // Append a bunch of text files to the test archive for (i = (N - 1); i >= 0; --i) { - sprintf(archive_filename, "%u.txt", i); - sprintf(data, "%u %s %u", (N - 1) - i, s_pTest_str, i); + snprintf(archive_filename, sizeof(archive_filename), "%u.txt", i); + snprintf(data, sizeof(data), "%u %s %u", (N - 1) - i, s_pTest_str, i); // Add a new file to the archive. Note this is an IN-PLACE operation, so if it fails your archive is probably hosed (its central directory may not be complete) but it should be recoverable using zip -F or -FF. So use caution with this guy. // A more robust way to add a file to an archive would be to read it into memory, perform the operation, then write a new archive out to a temp file and then delete/rename the files. @@ -127,8 +127,8 @@ int main(int argc, char *argv[]) for (i = 0; i < N; i++) { - sprintf(archive_filename, "%u.txt", i); - sprintf(data, "%u %s %u", (N - 1) - i, s_pTest_str, i); + snprintf(archive_filename, sizeof(archive_filename), "%u.txt", i); + snprintf(data, sizeof(data), "%u %s %u", (N - 1) - i, s_pTest_str, i); // Try to extract all the files to the heap. p = mz_zip_reader_extract_file_to_heap(&zip_archive, archive_filename, &uncomp_size, 0);