summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-01-25 00:13:54 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-01-25 00:13:54 +0100
commitb896d4b237760edd8aac8fd11240178a641fd968 (patch)
tree02e773ba83fd92e8f153c1412671cbc2b5eb2cbb
parentd7d78670c901ab97a45a3e346cc955826db412ae (diff)
downloadserenity-b896d4b237760edd8aac8fd11240178a641fd968.zip
PTY: Disallow infinite writing to slaves.
This way we don't buffer ungodly amounts of output in the kernel when doing e.g "cat /dev/random" on a PTY.
-rw-r--r--Kernel/MasterPTY.cpp5
-rw-r--r--Kernel/MasterPTY.h1
-rw-r--r--Kernel/SlavePTY.cpp4
3 files changed, 8 insertions, 2 deletions
diff --git a/Kernel/MasterPTY.cpp b/Kernel/MasterPTY.cpp
index 079f630afb..caacf08c95 100644
--- a/Kernel/MasterPTY.cpp
+++ b/Kernel/MasterPTY.cpp
@@ -45,3 +45,8 @@ void MasterPTY::on_slave_write(const byte* data, size_t size)
{
m_buffer.write(data, size);
}
+
+bool MasterPTY::can_write_from_slave() const
+{
+ return m_buffer.bytes_in_write_buffer() < 4096;
+}
diff --git a/Kernel/MasterPTY.h b/Kernel/MasterPTY.h
index c7ba83ba2b..cc375feab6 100644
--- a/Kernel/MasterPTY.h
+++ b/Kernel/MasterPTY.h
@@ -20,6 +20,7 @@ public:
unsigned index() const { return m_index; }
String pts_name() const;
void on_slave_write(const byte*, size_t);
+ bool can_write_from_slave() const;
private:
// ^CharacterDevice
diff --git a/Kernel/SlavePTY.cpp b/Kernel/SlavePTY.cpp
index c8fa110746..226be88b9c 100644
--- a/Kernel/SlavePTY.cpp
+++ b/Kernel/SlavePTY.cpp
@@ -31,7 +31,7 @@ void SlavePTY::on_tty_write(const byte* data, size_t size)
m_master.on_slave_write(data, size);
}
-bool SlavePTY::can_write(Process& process) const
+bool SlavePTY::can_write(Process&) const
{
- return m_master.can_write(process);
+ return m_master.can_write_from_slave();
}