diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2011-06-02 01:15:18 -0700 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2011-06-02 01:15:18 -0700 |
commit | 686069051add46d5c552f4e34e005d49cad43529 (patch) | |
tree | 41a408d7cb790e64504d0114f606eb0454d15fa2 /lib/careadlinkat.c | |
parent | 63ce57e7e9fff1265da4e0a4d2639483c28b6b93 (diff) | |
download | gnulib-686069051add46d5c552f4e34e005d49cad43529.tar.gz |
allocator: 'die' routine is now given requested size
* lib/allocator.h (struct allocator.die): New size arg.
* lib/careadlinkat.c (careadlinkat): Pass size to 'die' function.
If the actual problem is an ssize_t limitation, not a size_t or
malloc failure, fail with errno==ENAMETOOLONG instead of calling 'die'.
Diffstat (limited to 'lib/careadlinkat.c')
-rw-r--r-- | lib/careadlinkat.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/lib/careadlinkat.c b/lib/careadlinkat.c index e2909c766d..6e4aa1395f 100644 --- a/lib/careadlinkat.c +++ b/lib/careadlinkat.c @@ -135,6 +135,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 +159,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 +171,7 @@ careadlinkat (int fd, char const *filename, while (buf); if (alloc->die) - alloc->die (); + alloc->die (buf_size); errno = ENOMEM; return NULL; } |