-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sys/shell: correctly detect and handle long lines #10635
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First round. The fix is necessary. The implementation is a little hacky.
3fd3fc1
to
e3e756a
Compare
I force pushed because I more or less redid the second PR. Because readline is now returning the line length, it made more sense to use an index variable and not a pointer to access the buffer. I think code looks cleaner now (assertions look more expressive). |
e3e756a
to
90a4116
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added some comments on the reviews that dissapeared because of GH magic.
a7e7b15
to
b035c31
Compare
I rebased (due to #10630 being merged) and squashed the fixup. |
I would be a good idea to merge this considering people are wasting time in fixing the same bugs all over again (#11054 ) |
b035c31
to
61ae1ec
Compare
61ae1ec
to
bd8c993
Compare
I rebased on top of (the rebased) rawterm. Note that rawterm is not needed for this fix, but it makes testing easier. |
80e30e2
to
9f52bef
Compare
|
||
if (!res) { | ||
handle_input_line(shell_commands, line_buf); | ||
switch (res) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as there is no other use of res
could be replace with switch (readline(line_buf, len)) {
ebe823e
to
997341f
Compare
997341f
to
1a2a239
Compare
Ouch! I discovered I broke control-c handling when I rebased this and also that testing via expect would miss that bug. I'm working on fixing it. |
1a2a239
to
9e50b9b
Compare
The test for the line cancellation (ctrl-c) functionality was unable to detect error because of the way pexpect matches output. While working on the long line shell bug, a regression was about to be introduced because of this. This commit fixes the test by directly reading from the child process and expects an exact response. To make the test more robust, the newline handling was changed in native, where an extra empty line was being sent with each character.
Sorry for so many force-pushing- pexpect and the shell are conspiring against me. |
Add a command to retrieve buffer size and then force an extremely long line. This is failing right now because of a bug in the shell. The terminal was changed to socat, as pyterm messes up the I/O and makes testing impossible.
The numeric value for EOF is (-1). This caused the shell to return the same code when EOF was encountered and when the line lenght was exceeded. Additionally, if the line length is exceeded, the correct behaviour is to consume the remaining characters until the end of the line, to prevent the following line from containing (potentially dangerous) garbage.
@smlng I'm doing what I can trying to repair a code that is of the lowest standard. At the end I decided it needs more or complete rewrite (thus my "refactor" PRs) but first it is necessary to fix the bugs in the old code. There is no point trying to make this perfect or even good, because I'm building on bad foundations. |
Can be closed due to #13195 |
closing as needs rebase and is superseded by #13195 |
Contribution description
The numeric value for EOF is (-1). This caused the shell to return the same code when EOF was encountered and when the line lenght was exceeded. Additionally, if the line length is exceeded, the correct behaviour is to consume the remaining characters until the end of the line, to prevent the following line from containing (potentially dangerous) garbage.
Testing procedure
The first commit adds a test to
tests/shell
. It adds a command to retrieve buffer size and then forces an extremely long line. This is failing right now because of a bug in the shell.Murdock should be checking this, but you can do it locally by checkout both commits and running
In each one. The first one fails and the second succeeds.
I can switch the order of the commits if keeping a working history is important.
Issues/PRs references
Testing was made specially difficult because of #10634 .
Part of #12105