GHSL-2020-001: Off-by-one heap overflow in Bftpd
The command_retr function in Bftpd uses a while loop that treats a read error (-1) as true, causing an off-by-one heap write when buffer[-1] is set to null. An attacker could trigger this to corrupt heap memory with a single null byte.
Originally disclosed on GitHub Security Lab
Under certain circumstances, an off-by-one heap overflow can occur in the commandretr function.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely, the code fails to check for a negative return value from read, treating -1 as a successful read length.
Impact
Heap memory corruption with a single nul byte, rated medium-low severity.
What the attacker needed
Trigger a read error in command_retr
The fix
The vendor published a fix.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
In C, a loop condition checks if a value is non-zero. The read function returns -1 on error, which is non-zero, so the loop continues even though no data was read. Then the code writes a null byte just before the buffer, corrupting memory.
What is Memory corruption?
Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.