diff options
Diffstat (limited to 'libexec/rtld-elf')
-rw-r--r-- | libexec/rtld-elf/ia64/reloc.c | 6 | ||||
-rw-r--r-- | libexec/rtld-elf/powerpc64/reloc.c | 2 | ||||
-rw-r--r-- | libexec/rtld-elf/rtld.c | 12 | ||||
-rw-r--r-- | libexec/rtld-elf/rtld.h | 4 | ||||
-rw-r--r-- | libexec/rtld-elf/xmalloc.c | 15 |
5 files changed, 20 insertions, 19 deletions
diff --git a/libexec/rtld-elf/ia64/reloc.c b/libexec/rtld-elf/ia64/reloc.c index 1afcecf..01e20b8 100644 --- a/libexec/rtld-elf/ia64/reloc.c +++ b/libexec/rtld-elf/ia64/reloc.c @@ -87,7 +87,7 @@ alloc_fptr(Elf_Addr target, Elf_Addr gp) struct fptr* fptr; if (next_fptr == last_fptr) { - current_chunk = malloc(sizeof(struct fptr_chunk)); + current_chunk = xmalloc(sizeof(struct fptr_chunk)); next_fptr = ¤t_chunk->fptrs[0]; last_fptr = ¤t_chunk->fptrs[FPTR_CHUNK_SIZE]; } @@ -116,9 +116,7 @@ alloc_fptrs(Obj_Entry *obj, bool mapped) if (fptrs == MAP_FAILED) fptrs = NULL; } else { - fptrs = malloc(fbytes); - if (fptrs != NULL) - memset(fptrs, 0, fbytes); + fptrs = xcalloc(1, fbytes); } /* diff --git a/libexec/rtld-elf/powerpc64/reloc.c b/libexec/rtld-elf/powerpc64/reloc.c index 46e2c62..92df83d 100644 --- a/libexec/rtld-elf/powerpc64/reloc.c +++ b/libexec/rtld-elf/powerpc64/reloc.c @@ -338,7 +338,7 @@ reloc_plt_object(Obj_Entry *obj, const Elf_Rela *rela) reloff = rela - obj->pltrela; if (obj->priv == NULL) - obj->priv = malloc(obj->pltrelasize); + obj->priv = xmalloc(obj->pltrelasize); glink = obj->priv + reloff*sizeof(Elf_Addr)*2; dbg(" reloc_plt_object: where=%p,reloff=%lx,glink=%p", (void *)where, reloff, glink); diff --git a/libexec/rtld-elf/rtld.c b/libexec/rtld-elf/rtld.c index f2ad554..4dac1c1 100644 --- a/libexec/rtld-elf/rtld.c +++ b/libexec/rtld-elf/rtld.c @@ -3733,7 +3733,7 @@ tls_get_addr_slow(Elf_Addr **dtvp, int index, size_t offset) /* Check dtv generation in case new modules have arrived */ if (dtv[0] != tls_dtv_generation) { wlock_acquire(rtld_bind_lock, &lockstate); - newdtv = calloc(1, (tls_max_index + 2) * sizeof(Elf_Addr)); + newdtv = xcalloc(tls_max_index + 2, sizeof(Elf_Addr)); to_copy = dtv[1]; if (to_copy > tls_max_index) to_copy = tls_max_index; @@ -3788,7 +3788,7 @@ allocate_tls(Obj_Entry *objs, void *oldtcb, size_t tcbsize, size_t tcbalign) return (oldtcb); assert(tcbsize >= TLS_TCB_SIZE); - tcb = calloc(1, tls_static_space - TLS_TCB_SIZE + tcbsize); + tcb = xcalloc(1, tls_static_space - TLS_TCB_SIZE + tcbsize); tls = (Elf_Addr **)(tcb + tcbsize - TLS_TCB_SIZE); if (oldtcb != NULL) { @@ -3804,7 +3804,7 @@ allocate_tls(Obj_Entry *objs, void *oldtcb, size_t tcbsize, size_t tcbalign) } } } else { - dtv = calloc(tls_max_index + 2, sizeof(Elf_Addr)); + dtv = xcalloc(tls_max_index + 2, sizeof(Elf_Addr)); tls[0] = dtv; dtv[0] = tls_dtv_generation; dtv[1] = tls_max_index; @@ -3868,8 +3868,8 @@ allocate_tls(Obj_Entry *objs, void *oldtls, size_t tcbsize, size_t tcbalign) size = round(tls_static_space, tcbalign); assert(tcbsize >= 2*sizeof(Elf_Addr)); - tls = calloc(1, size + tcbsize); - dtv = calloc(1, (tls_max_index + 2) * sizeof(Elf_Addr)); + tls = xcalloc(1, size + tcbsize); + dtv = xcalloc(tls_max_index + 2, sizeof(Elf_Addr)); segbase = (Elf_Addr)(tls + size); ((Elf_Addr*)segbase)[0] = segbase; @@ -4209,7 +4209,7 @@ rtld_verify_object_versions(Obj_Entry *obj) * way. */ obj->vernum = maxvernum + 1; - obj->vertab = calloc(obj->vernum, sizeof(Ver_Entry)); + obj->vertab = xcalloc(obj->vernum, sizeof(Ver_Entry)); vd = obj->verdef; while (vd != NULL) { diff --git a/libexec/rtld-elf/rtld.h b/libexec/rtld-elf/rtld.h index 2aabffe..2bf9518 100644 --- a/libexec/rtld-elf/rtld.h +++ b/libexec/rtld-elf/rtld.h @@ -58,7 +58,7 @@ #endif #define NEW(type) ((type *) xmalloc(sizeof(type))) -#define CNEW(type) ((type *) xcalloc(sizeof(type))) +#define CNEW(type) ((type *) xcalloc(1, sizeof(type))) /* We might as well do booleans like C++. */ typedef unsigned char bool; @@ -319,7 +319,7 @@ typedef struct Struct_SymLook { extern void _rtld_error(const char *, ...) __printflike(1, 2); extern const char *rtld_strerror(int); extern Obj_Entry *map_object(int, const char *, const struct stat *); -extern void *xcalloc(size_t); +extern void *xcalloc(size_t, size_t); extern void *xmalloc(size_t); extern char *xstrdup(const char *); extern Elf_Addr _GLOBAL_OFFSET_TABLE_[]; diff --git a/libexec/rtld-elf/xmalloc.c b/libexec/rtld-elf/xmalloc.c index 0d99225..3783685 100644 --- a/libexec/rtld-elf/xmalloc.c +++ b/libexec/rtld-elf/xmalloc.c @@ -32,14 +32,17 @@ #include "rtld.h" #include "rtld_printf.h" -void *xcalloc(size_t); -void *xmalloc(size_t); -char *xstrdup(const char *); - void * -xcalloc(size_t size) +xcalloc(size_t number, size_t size) { - return memset(xmalloc(size), 0, size); + void *p; + + p = calloc(number, size); + if (p == NULL) { + rtld_fdputstr(STDERR_FILENO, "Out of memory\n"); + _exit(1); + } + return (p); } void * |