From b6afe1f0cecd1025afcc99771acc9580b4079691 Mon Sep 17 00:00:00 2001 From: Ben Wiederhake Date: Sun, 16 Aug 2020 07:51:56 +0200 Subject: [PATCH] Kernel: Prefer snprintf over sprintf --- Kernel/FileSystem/ProcFS.cpp | 10 +++++----- Kernel/TTY/SlavePTY.cpp | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Kernel/FileSystem/ProcFS.cpp b/Kernel/FileSystem/ProcFS.cpp index b7d306e17d..dfd4b7b078 100644 --- a/Kernel/FileSystem/ProcFS.cpp +++ b/Kernel/FileSystem/ProcFS.cpp @@ -688,8 +688,8 @@ static Optional procfs$pid_root(InodeIdentifier identifier) static Optional procfs$self(InodeIdentifier) { char buffer[16]; - sprintf(buffer, "%d", Process::current()->pid().value()); - return KBuffer::copy((const u8*)buffer, strlen(buffer)); + int written = snprintf(buffer, sizeof(buffer), "%d", Process::current()->pid().value()); + return KBuffer::copy((const u8*)buffer, static_cast(written)); } Optional procfs$mm(InodeIdentifier) @@ -1272,7 +1272,7 @@ KResult ProcFSInode::traverse_as_directory(Functionfor_each_thread([&](Thread& thread) -> IterationDecision { int tid = thread.tid().value(); char name[16]; - size_t name_length = (size_t)sprintf(name, "%d", tid); + size_t name_length = (size_t)snprintf(name, sizeof(name), "%d", tid); callback({ { name, name_length }, to_identifier_with_stack(fsid(), tid), 0 }); return IterationDecision::Continue; }); diff --git a/Kernel/TTY/SlavePTY.cpp b/Kernel/TTY/SlavePTY.cpp index f4ba079188..dd18963596 100644 --- a/Kernel/TTY/SlavePTY.cpp +++ b/Kernel/TTY/SlavePTY.cpp @@ -38,7 +38,7 @@ SlavePTY::SlavePTY(MasterPTY& master, unsigned index) , m_master(master) , m_index(index) { - sprintf(m_tty_name, "/dev/pts/%u", m_index); + snprintf(m_tty_name, sizeof(m_tty_name), "/dev/pts/%u", m_index); auto process = Process::current(); set_uid(process->uid()); set_gid(process->gid());