Commit fe6c507f authored by Philipp Stephani's avatar Philipp Stephani
Browse files

Make sure that ‘sdata’ objects in ‘sblock’ objects are aligned.

Issue found by Clang’s UBSan.

* src/alloc.c (GC_STRING_OVERRUN_COOKIE_SIZE): Increase to 8.
(string_overrun_cookie): Extend accordingly.
(GC_STRING_EXTRA): Ensure that it’s properly aligned for ‘sdata’.
(allocate_string_data): Verify that ‘sdata’ blocks remain aligned.
parent e08e0880
Pipeline #1459 failed with stage
in 6 minutes and 47 seconds
......@@ -21,6 +21,8 @@ along with GNU Emacs. If not, see <>. */
#include <config.h>
#include <errno.h>
#include <stdalign.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <limits.h> /* For CHAR_BIT. */
......@@ -1578,9 +1580,9 @@ static struct Lisp_String *string_free_list;
"cookie" after each allocated string data block, and check for the
presence of this cookie during GC. */
static char const string_overrun_cookie[GC_STRING_OVERRUN_COOKIE_SIZE] =
{ '\xde', '\xad', '\xbe', '\xef' };
{ '\xde', '\xad', '\xbe', '\xef', '\xde', '\xad', '\xbe', '\xef' };
......@@ -1616,6 +1618,11 @@ static char const string_overrun_cookie[GC_STRING_OVERRUN_COOKIE_SIZE] =
/* Make sure that allocating the extra bytes doesn't misalign
`sdata'. */
verify (GC_STRING_EXTRA % alignof (sdata) == 0);
/* Exact bound on the number of bytes in a string, not counting the
terminating NUL. A string cannot contain more bytes than
STRING_BYTES_BOUND, nor can it be so long that the size_t
......@@ -1875,6 +1882,7 @@ allocate_string_data (struct Lisp_String *s,
data->string = s;
b->next_free = (sdata *) ((char *) data + needed + GC_STRING_EXTRA);
eassert ((uintptr_t) (char *) b->next_free % alignof (sdata) == 0);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment