diff options
| author | Paul Eggert | 2017-12-09 13:57:38 -0800 |
|---|---|---|
| committer | Paul Eggert | 2017-12-12 15:17:12 -0800 |
| commit | 4295050e1194af13afa26403dd3ebdff80824ae0 (patch) | |
| tree | 354002f3c84f4d8341bb07c5f68529f660a9a405 /src/gmalloc.c | |
| parent | 881abfc7fb55db2d00adf352100cc58a6a86c176 (diff) | |
| download | emacs-4295050e1194af13afa26403dd3ebdff80824ae0.tar.gz emacs-4295050e1194af13afa26403dd3ebdff80824ae0.zip | |
Narrow pointer bounds when appropriate
This typically occurs in a storage manager, where the caller
is expected to access only the newly-allocated object,
instead of using the returned value to access unrelated
parts of the heap.
* src/alloc.c (allocate_string, allocate_string_data)
(compact_small_strings, find_string_data_in_pure)
(sweep_strings, setup_on_free_list, allocate_vectorlike
(pure_alloc):
* src/bytecode.c (exec_byte_code):
* src/callint.c (Fcall_interactively):
* src/dispnew.c (scrolling):
* src/editfns.c (styled_format):
* src/frame.c (xrdb_get_resource, x_get_resource_string):
* src/fringe.c (Fdefine_fringe_bitmap):
* src/gmalloc.c (malloc, realloc, aligned_alloc):
Narrow pointer bounds when appropriate.
* src/alloc.c (SDATA_OF_STRING):
* src/lisp.h (make_lisp_symbol) [__CHKP__]:
Widen bounds here, though.
* src/bytecode.c, src/callint.c, src/dispnew.c, src/editfns.c:
* src/emacs.c, src/frame.c, src/fringe.c:
Include ptr-bounds.h.
* src/ptr-bounds.h (ptr_bounds_clip): New function.
Diffstat (limited to 'src/gmalloc.c')
| -rw-r--r-- | src/gmalloc.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/gmalloc.c b/src/gmalloc.c index 97ab76561f9..99cb967e539 100644 --- a/src/gmalloc.c +++ b/src/gmalloc.c | |||
| @@ -203,7 +203,8 @@ extern size_t _bytes_free; | |||
| 203 | 203 | ||
| 204 | /* Internal versions of `malloc', `realloc', and `free' | 204 | /* Internal versions of `malloc', `realloc', and `free' |
| 205 | used when these functions need to call each other. | 205 | used when these functions need to call each other. |
| 206 | They are the same but don't call the hooks. */ | 206 | They are the same but don't call the hooks |
| 207 | and don't bound the resulting pointers. */ | ||
| 207 | extern void *_malloc_internal (size_t); | 208 | extern void *_malloc_internal (size_t); |
| 208 | extern void *_realloc_internal (void *, size_t); | 209 | extern void *_realloc_internal (void *, size_t); |
| 209 | extern void _free_internal (void *); | 210 | extern void _free_internal (void *); |
| @@ -921,7 +922,8 @@ malloc (size_t size) | |||
| 921 | among multiple threads. We just leave it for compatibility with | 922 | among multiple threads. We just leave it for compatibility with |
| 922 | glibc malloc (i.e., assignments to gmalloc_hook) for now. */ | 923 | glibc malloc (i.e., assignments to gmalloc_hook) for now. */ |
| 923 | hook = gmalloc_hook; | 924 | hook = gmalloc_hook; |
| 924 | return (hook != NULL ? *hook : _malloc_internal) (size); | 925 | void *result = (hook ? hook : _malloc_internal) (size); |
| 926 | return ptr_bounds_clip (result, size); | ||
| 925 | } | 927 | } |
| 926 | 928 | ||
| 927 | #if !(defined (_LIBC) || defined (HYBRID_MALLOC)) | 929 | #if !(defined (_LIBC) || defined (HYBRID_MALLOC)) |
| @@ -1434,7 +1436,8 @@ realloc (void *ptr, size_t size) | |||
| 1434 | return NULL; | 1436 | return NULL; |
| 1435 | 1437 | ||
| 1436 | hook = grealloc_hook; | 1438 | hook = grealloc_hook; |
| 1437 | return (hook != NULL ? *hook : _realloc_internal) (ptr, size); | 1439 | void *result = (hook ? hook : _realloc_internal) (ptr, size); |
| 1440 | return ptr_bounds_clip (result, size); | ||
| 1438 | } | 1441 | } |
| 1439 | /* Copyright (C) 1991, 1992, 1994 Free Software Foundation, Inc. | 1442 | /* Copyright (C) 1991, 1992, 1994 Free Software Foundation, Inc. |
| 1440 | 1443 | ||
| @@ -1608,6 +1611,7 @@ aligned_alloc (size_t alignment, size_t size) | |||
| 1608 | { | 1611 | { |
| 1609 | l->exact = result; | 1612 | l->exact = result; |
| 1610 | result = l->aligned = (char *) result + adj; | 1613 | result = l->aligned = (char *) result + adj; |
| 1614 | result = ptr_bounds_clip (result, size); | ||
| 1611 | } | 1615 | } |
| 1612 | UNLOCK_ALIGNED_BLOCKS (); | 1616 | UNLOCK_ALIGNED_BLOCKS (); |
| 1613 | if (l == NULL) | 1617 | if (l == NULL) |