X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/e5b28a7aef4446e07fa6a74df1254caec5add54e..c902337068f52666425b7647e5aa43c621146e56:/lib/careadlinkat.c diff --git a/lib/careadlinkat.c b/lib/careadlinkat.c index 01883db9ce..e2c19d1c1f 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 @@ -22,8 +22,6 @@ #include "careadlinkat.h" -#include "allocator.h" - #include #include #include @@ -38,18 +36,7 @@ # define SSIZE_MAX ((ssize_t) (SIZE_MAX / 2)) #endif -#if ! HAVE_READLINKAT -/* Ignore FD. 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) -{ - (void) fd; - return readlink (filename, buffer, buffer_size); -} -#endif +#include "allocator.h" /* Assuming the current directory is FD, get the symbolic link value of FILENAME as a null-terminated string and put it into a buffer. @@ -131,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); @@ -154,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); @@ -161,7 +154,7 @@ careadlinkat (int fd, char const *filename, while (buf); if (alloc->die) - alloc->die (); + alloc->die (buf_size); errno = ENOMEM; return NULL; }