text icon indicating copy to clipboard operation
text copied to clipboard

Fixed off by one for writeBlocksRaw

Open BebeSparkelSparkel opened this issue 1 year ago • 8 comments

closes #587

BebeSparkelSparkel avatar Apr 28 '24 17:04 BebeSparkelSparkel

Is it possible to add a regression test?

Bodigrim avatar Apr 28 '24 17:04 Bodigrim

It may be possible, but I am unsure how to. This is a case of the last character in the buffer not being used because the bounds check was copy pasted from the above write* functions that have the possibility of writing two characters CRLF.

BebeSparkelSparkel avatar Apr 28 '24 21:04 BebeSparkelSparkel

Would anything in the current test suite break if we put n - 10 instead of n / n + 1? Do we have any tests in this area at all?

Bodigrim avatar Apr 28 '24 21:04 Bodigrim

All tests pass with n - 10

BebeSparkelSparkel avatar Apr 29 '24 23:04 BebeSparkelSparkel

I don't know how to test for buffer overflow unless we can add a test buffer type that checks for that.

BebeSparkelSparkel avatar Apr 29 '24 23:04 BebeSparkelSparkel

We might not catch this in regular builds but we can test this by inserting a debug assertion (enabled by -DASSERTS under the -fdeveloper cabal flag) to ensure that writeCharBuf is within bounds.

Lysxia avatar Apr 30 '24 08:04 Lysxia

@Lysxia Good idea. I have added the bounds assertion to a wrapped writeCharBuf

BebeSparkelSparkel avatar Apr 30 '24 17:04 BebeSparkelSparkel

@Bodigrim Anything else that needs to be done?

BebeSparkelSparkel avatar May 21 '24 19:05 BebeSparkelSparkel

Thanks!

Bodigrim avatar May 29 '24 21:05 Bodigrim