X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fcareadlinkat.c;h=e2c19d1c1f1749d77d44ca54c1ce595ba7b621e4;hb=c2b08ae26cdc70a3acf7d1bc15bc77c92bbcc97c;hp=e2909c766d5f1969d42b415499f90139e8d9f7aa;hpb=bdfd8afae05965555600eb43d661d4c7686ebd68;p=gnulib.git diff --git a/lib/careadlinkat.c b/lib/careadlinkat.c index e2909c766..e2c19d1c1 100644 --- a/lib/careadlinkat.c +++ b/lib/careadlinkat.c @@ -1,6 +1,6 @@ /* Read symbolic links into a buffer without size limitation, relative to fd. - Copyright (C) 2001, 2003-2004, 2007, 2009-2011 Free Software Foundation, + Copyright (C) 2001, 2003-2004, 2007, 2009-2013 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify @@ -24,7 +24,6 @@ #include #include -#include #include #include @@ -39,22 +38,6 @@ #include "allocator.h" -#if ! HAVE_READLINKAT -/* Get the symbolic link value of FILENAME and put it into BUFFER, with - size BUFFER_SIZE. This function acts like readlink but has - readlinkat's signature. */ -ssize_t -careadlinkatcwd (int fd, char const *filename, char *buffer, - size_t buffer_size) -{ - /* FD must be AT_FDCWD here, otherwise the caller is using this - function in contexts for which it was not meant for. */ - if (fd != AT_FDCWD) - abort (); - return readlink (filename, buffer, buffer_size); -} -#endif - /* Assuming the current directory is FD, get the symbolic link value of FILENAME as a null-terminated string and put it into a buffer. If FD is AT_FDCWD, FILENAME is interpreted relative to the current @@ -135,6 +118,7 @@ careadlinkat (int fd, char const *filename, if (buf == stack_buf) { char *b = (char *) alloc->allocate (link_size); + buf_size = link_size; if (! b) break; memcpy (b, buf, link_size); @@ -158,6 +142,11 @@ careadlinkat (int fd, char const *filename, buf_size *= 2; else if (buf_size < buf_size_max) buf_size = buf_size_max; + else if (buf_size_max < SIZE_MAX) + { + errno = ENAMETOOLONG; + return NULL; + } else break; buf = (char *) alloc->allocate (buf_size); @@ -165,7 +154,7 @@ careadlinkat (int fd, char const *filename, while (buf); if (alloc->die) - alloc->die (); + alloc->die (buf_size); errno = ENOMEM; return NULL; }