Skip to content
Memory corruption Advisory Advanced

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.

antonio-morales Follow

Originally disclosed on GitHub Security Lab

Under certain circumstances, an off-by-one heap overflow can occur in the commandretr function.

antonio-morales, on GitHub Security Lab

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.

More by antonio-morales

View all

45 more disclosed reports, best first.

More from GitHub Security Lab

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.