Skip to content
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

Attempting to fix issue #29 #31

Merged
merged 5 commits into from
Jun 30, 2019
Merged

Attempting to fix issue #29 #31

merged 5 commits into from
Jun 30, 2019

Conversation

f-prime
Copy link
Owner

@f-prime f-prime commented Jun 29, 2019

@00-matt This PR is attempting to fix the issue discussed #23 (comment)

What I am doing is reading the this->last_command variable before it is sent to process_command and splitting it at \r\n and sending everything before the new line characters.

What I am worried about is that after the loop is done I am sending what is left of the command variable which could be only a fragment of the original block of text for example

pig in a cage when fragmented could become ig in a cage leading to false indices. I haven't been able to produce this issue when testing but I wanted to get a second set of eyes on the code before I merged it.

@00-matt
Copy link
Contributor

00-matt commented Jun 29, 2019

I don't think that this is correct. When the text becomes fragmented, the start of the command gets lost (i.e. SEARCH or INDEX). Try pasting the following into telnet: https://pastebin.com/BLkVsiNs

You get around 96 "Invalid command" responses, and 3 for "Text has been indexed".

I think it's because currently, the leftover gets thrown away. It should be kept instead of dfree()-ing it and resetting it to dempty().

@f-prime
Copy link
Owner Author

f-prime commented Jun 29, 2019

Yeah, you’re right. I rushed this fix a bit.

I will update this PR hopefully today at some point with the correct solution.

@f-prime
Copy link
Owner Author

f-prime commented Jun 30, 2019

Okay, just pushed the fix for #29 and did some more thorough testing. It seems to be working now properly. Printing the commands as they enter process_command, they no longer appear fragmented like they did with the original fix I made.

@f-prime f-prime marked this pull request as ready for review June 30, 2019 03:47
Copy link
Contributor

@00-matt 00-matt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to have fixed the issue now :)

if(should_close) {
close(i);
FD_CLR(i, &master_fds);
dfree(connection_infos[i].last_command);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should break from the loop, otherwise we'll try to write to a socket that has been closed, and try to access a string that has been freed.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, I added the break in this if statement. Should be good to go now.

@f-prime f-prime merged commit 2abe5d2 into master Jun 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants