diff options
author | Andreas Kling <kling@serenityos.org> | 2020-04-01 11:24:10 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-04-01 11:25:53 +0200 |
commit | 296f87fa7fb0c4c7e8a85143b9bc6273722902fc (patch) | |
tree | d7892de535c04b6a61cbd01ab2a4035c833d793a /Libraries/LibLine | |
parent | 9ba9bba529c905c89b52e91c70b4ffeadf2f561e (diff) | |
download | serenity-296f87fa7fb0c4c7e8a85143b9bc6273722902fc.zip |
LibLine: Fix Shell crashing (due to write() EFAULT) on <tab><tab>
Use a StringBuilder instead of blindly passing a bunch of potentially
empty/null strings to the kernel. StringBuilder is more lenient and
generally more pleasant to use anyway.
Diffstat (limited to 'Libraries/LibLine')
-rw-r--r-- | Libraries/LibLine/Editor.cpp | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/Libraries/LibLine/Editor.cpp b/Libraries/LibLine/Editor.cpp index 9a2ff2c70e..e5363b148f 100644 --- a/Libraries/LibLine/Editor.cpp +++ b/Libraries/LibLine/Editor.cpp @@ -25,10 +25,10 @@ */ #include "Editor.h" +#include <AK/StringBuilder.h> #include <ctype.h> #include <stdio.h> #include <sys/ioctl.h> -#include <sys/uio.h> #include <unistd.h> namespace Line { @@ -323,16 +323,14 @@ String Editor::get_line(const String& prompt) num_printed += fprintf(stderr, "%-*s", static_cast<int>(longest_suggestion_length) + 2, suggestion.characters()); } - putchar('\n'); - struct iovec iov[] = { - { const_cast<char*>(prompt.characters()), prompt.length() }, - { m_buffer.data(), m_cursor }, - { m_buffer.data() + m_cursor, m_buffer.size() - m_cursor } - }; - if (writev(STDOUT_FILENO, iov, 3)) { - perror("writev"); - ASSERT_NOT_REACHED(); - } + StringBuilder builder; + builder.append('\n'); + builder.append(prompt); + builder.append(m_buffer.data(), m_cursor); + builder.append(m_buffer.data() + m_cursor, m_buffer.size() - m_cursor); + fputs(builder.to_string().characters(), stdout); + fflush(stdout); + m_cursor = m_buffer.size(); } |