diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2011-06-02 01:22:57 -0700 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2011-06-02 01:22:57 -0700 |
commit | f797625a8ca7bc973b6943c6fce97f1e479a283d (patch) | |
tree | ea83bdbb5c3ef83b9142acbcf08776e386c85108 /lib | |
parent | 4008751468313f68b74ae3f1f1d3857e52f0062f (diff) | |
download | emacs-f797625a8ca7bc973b6943c6fce97f1e479a283d.tar.gz |
* lib/allocator.h, lib/careadlinkat.c: Merge from gnulib.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/allocator.h | 9 | ||||
-rw-r--r-- | lib/careadlinkat.c | 8 |
2 files changed, 12 insertions, 5 deletions
diff --git a/lib/allocator.h b/lib/allocator.h index 953117da83f..b8de95c0f50 100644 --- a/lib/allocator.h +++ b/lib/allocator.h @@ -45,10 +45,11 @@ struct allocator /* Call FREE to free memory, like 'free'. */ void (*free) (void *); - /* If nonnull, call DIE if MALLOC or REALLOC fails. DIE should not - return. DIE can be used by code that detects memory overflow - while calculating sizes to be passed to MALLOC or REALLOC. */ - void (*die) (void); + /* If nonnull, call DIE (SIZE) if MALLOC (SIZE) or REALLOC (..., + SIZE) fails. DIE should not return. SIZE should equal SIZE_MAX + if size_t overflow was detected while calculating sizes to be + passed to MALLOC or REALLOC. */ + void (*die) (size_t); }; /* An allocator using the stdlib functions and a null DIE function. */ diff --git a/lib/careadlinkat.c b/lib/careadlinkat.c index e2909c766d5..6e4aa1395ff 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; } |