Stack-based buffer overflow in the comprexx function for ncompress 4.2.4 and earlier, when used in situations that cross security boundaries (such as FTP server), may allow remote attackers to execute arbitrary code via a long filename argument.
Report from Tavis Ormandy, Google Security Team:
An audit of ncompress version 4.2.4 uncovered a serious security flaw, this loop in decompress() (~1749, compress42.c) performs no bounds checking, allowing a specially crafted datastream to underflow a .bss buffer with attacker controlled data. Some research reveals that the lzw decompressors from gzip and openbsd (both derived from the same public domain implementation) have already corrected this flaw, however ncompress shipped by (at least) gentoo, debian, fedora and suse seem to still be vulnerable.
while ((cmpcodeint)code >= (cmpcodeint)256) { / Generate output characters in reverse order / --stackp = tabsuffixof(code); code = tabprefixof(code); }
In my test environment I've been able to successfully overwirte .got and .dtors with controlled data. The most simple testcase would be:
$ perl -e 'print "\x1f\x9d\x90","\x01"x"2048"' | compress -d
My suggested fix would be adding && stackp >= htabof(0) to the loop condition.