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

Fix FIFO on Windows not working with Windows linebreaks #9657

Merged
merged 1 commit into from
Feb 11, 2025

Conversation

Robyt3
Copy link
Member

@Robyt3 Robyt3 commented Feb 7, 2025

Carriage return \r characters were not properly ignored in Windows' FIFO implementation (named pipes), leading to incorrect commands being executed (including a trailing \r) which was causing some commands like rcon authentication and map changes to fail due to incorrect password/filename unless the arguments were escaped with quotes.

Checklist

  • Tested the change ingame
  • Provided screenshots if it is a visual change
  • Tested in combination with possibly related configuration options
  • Written a unit test (especially base/) or added coverage to integration test
  • Considered possible null pointers and out of bounds array indexing
  • Changed no physics that affect existing maps
  • Tested the change with ASan+UBSan or valgrind's memcheck (optional)

@Robyt3 Robyt3 requested a review from heinrich5991 February 7, 2025 16:02
@Robyt3
Copy link
Member Author

Robyt3 commented Feb 7, 2025

Necessary for #9493. (Well, probably not strictly, but it would require additional changes. From what I can tell, the fifo.write function will automatically translate \n to \r\n.)

pBuf[i] = '\0';
continue;
}
else if(pBuf[i] != '\n')
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps we could simply treat \r and \n the same, i.e. both as line endings? As I understand it, this PR would ignore everything between \r and \n.

Copy link
Member

@def- def- Feb 8, 2025

Choose a reason for hiding this comment

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

Then there are lots of empty lines on Windows. We should probably check that it's actually \r\n or \n\r and only then ignore them.

Copy link
Member Author

Choose a reason for hiding this comment

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

I changed it to be consistent with the behavior of CLineReader so only \n and \r\n will be considered as line breaks. Stray \r are not considered line breaks.

if(m_pBuffer[m_BufferPos] == '\0' || m_pBuffer[m_BufferPos] == '\n' || (m_pBuffer[m_BufferPos] == '\r' && m_pBuffer[m_BufferPos + 1] == '\n'))
{
if(m_pBuffer[m_BufferPos] == '\0')
{
m_ReadLastLine = true;
}
else
{
if(m_pBuffer[m_BufferPos] == '\r')
{
m_pBuffer[m_BufferPos] = '\0';
++m_BufferPos;
}
m_pBuffer[m_BufferPos] = '\0';
++m_BufferPos;
}

Carriage return `\r` characters were not properly ignored in Windows' FIFO implementation (named pipes), leading to incorrect commands being executed (including a trailing `\r`) which was causing some commands like rcon authentication and map changes to fail due to incorrect password/filename unless the arguments were escaped with quotes.
@Robyt3 Robyt3 force-pushed the Windows-Fifo-Newline-Fix branch from 69b3f0d to f500600 Compare February 8, 2025 15:34
@Robyt3 Robyt3 requested a review from heinrich5991 February 11, 2025 20:17
Copy link
Member

@heinrich5991 heinrich5991 left a comment

Choose a reason for hiding this comment

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

Thanks!

@heinrich5991 heinrich5991 added this pull request to the merge queue Feb 11, 2025
Merged via the queue into ddnet:master with commit cdf69a6 Feb 11, 2025
17 checks passed
@Robyt3 Robyt3 deleted the Windows-Fifo-Newline-Fix branch February 11, 2025 23:15
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.

3 participants