Skip Menu |

This queue is for tickets about the POSIX-2008 CPAN distribution.

Report information
The Basics
Id: 96644
Status: resolved
Priority: 0/
Queue: POSIX-2008

People
Owner: Nobody in particular
Requestors: yourst [...] yourst.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Buffer overflow in readlink() and readlinkat() due to failure to add null terminator
Date: Sun, 22 Jun 2014 19:32:51 -0700
To: bug-POSIX-2008 [...] rt.cpan.org
From: "Matt T. Yourst" <yourst [...] yourst.com>
I found a fairly serious bug in POSIX::2008's implementation of readlink() and readlinkat(). The underlying syscalls do not add any null terminator byte at the end of the output buffer, but _readlink50c() in 2008.XS also fails to add a null terminator before returning the result string to perl. This results in arbitrary memory contents being visible in the result returned to perl code by readlink() and readlinkat(). At the very least, this causes failures in any downstream code that attempts to access whatever filename (plus the erroneous garbage) was linked to. In theory it could also be a major security leak (depending on what was in the returned string before it was partially overwritten by readlink()), since it's basically the read-only equivalent of a buffer overflow. I've attached a patch for 2008.XS that fixes this (apply with 'patch -p1'), and also replaces the unnecessary choice between readlink() and readlinkat() syscalls with AT_FDCWD and readlinkat(). I'm not sure how this went unnoticed for this long, but I suspect it was probably because it's unusual to import readlink() from POSIX::2008 when there is already a built-in equivalent, plus readlinkat() is not used very often (which is unfortunate since it can really improve efficiency). Hopefully you can merge the attached patch to finally fix this bug... - Matt ------------------------------------------------------- Matt T. Yourst yourst@yourst.com -------------------------------------------------------

Message body is not shown because sender requested not to inline it.

Fixed in 0.04. BTW, your comment "symlinks can in theory contain literally any characters (including nulls)" is wrong. See for example W. Richard Stevens, "Advanced programming in the UNIX environment", 1.4 Files and Directories: "The only two characters that cannot appear in a filename are the slash character (/) and the null character."