Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
SUSE:SLE-12-SP4:GA
openldap2-client.33990
0226-Change-malloc-to-use-calloc-to-prevent-mem...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 0226-Change-malloc-to-use-calloc-to-prevent-memory-reuse-.patch of Package openldap2-client.33990
From d6f4d4f6fea21d9e588371f077f0406499f1f1ac Mon Sep 17 00:00:00 2001 From: William Brown <wbrown@suse.de> Date: Wed, 11 May 2022 12:40:50 +1000 Subject: [PATCH] Change malloc to use calloc to prevent memory reuse corruption --- servers/slapd/sl_malloc.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/servers/slapd/sl_malloc.c b/servers/slapd/sl_malloc.c index d440acbf28..6f7e735f62 100644 --- a/servers/slapd/sl_malloc.c +++ b/servers/slapd/sl_malloc.c @@ -291,8 +291,8 @@ slap_sl_mem_detach( SET_MEMCTX(thrctx, NULL, 0); } -void * -slap_sl_malloc( +static void * +slap_sl_malloc_inner( ber_len_t size, void *ctx ) @@ -393,6 +393,12 @@ slap_sl_malloc( ((0UL|(t)-1) >>31>>31 > 1 ? ((t)1 <<32) - 1 : \ (0UL|(t)-1) >>31 ? 65535U : (0UL|(t)-1) >>15 ? 255U : 15U) +void * +slap_sl_malloc( ber_len_t size, void *ctx ) +{ + return slap_sl_calloc(1, size, ctx); +} + void * slap_sl_calloc( ber_len_t n, ber_len_t size, void *ctx ) { @@ -401,7 +407,7 @@ slap_sl_calloc( ber_len_t n, ber_len_t size, void *ctx ) /* The sqrt test is a slight optimization: often avoids the division */ if ((n | size) <= LIM_SQRT(ber_len_t) || n == 0 || total/n == size) { - newptr = slap_sl_malloc( total, ctx ); + newptr = slap_sl_malloc_inner( total, ctx ); memset( newptr, 0, n*size ); } else { Debug(LDAP_DEBUG_ANY, "slap_sl_calloc(%lu,%lu) out of range\n", @@ -420,7 +426,7 @@ slap_sl_realloc(void *ptr, ber_len_t size, void *ctx) void *newptr; if (ptr == NULL) - return slap_sl_malloc(size, ctx); + return slap_sl_malloc_inner(size, ctx); /* Not our memory? */ if (No_sl_malloc || !sh || ptr < sh->sh_base || ptr >= sh->sh_end) { @@ -467,7 +473,7 @@ slap_sl_realloc(void *ptr, ber_len_t size, void *ctx) /* Nowhere to grow, need to alloc and copy */ } else { /* Slight optimization of the final realloc variant */ - newptr = slap_sl_malloc(size-sizeof(ber_len_t), ctx); + newptr = slap_sl_malloc_inner(size-sizeof(ber_len_t), ctx); AC_MEMCPY(newptr, ptr, oldsize-sizeof(ber_len_t)); /* Not last block, can just mark old region as free */ nextp[-1] = oldsize; @@ -482,7 +488,7 @@ slap_sl_realloc(void *ptr, ber_len_t size, void *ctx) oldsize = size; } - newptr = slap_sl_malloc(size, ctx); + newptr = slap_sl_malloc_inner(size, ctx); AC_MEMCPY(newptr, ptr, oldsize); slap_sl_free(ptr, ctx); return newptr; -- 2.36.1
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor