diff options
author | Alex Richardson <Alexander.Richardson@cl.cam.ac.uk> | 2021-06-16 14:50:51 +0100 |
---|---|---|
committer | Alan Coopersmith <alan.coopersmith@oracle.com> | 2021-06-27 18:35:02 +0000 |
commit | 1d5bb760ee996927dd5dfa5b3c219b3d6ef63d11 (patch) | |
tree | 1071deeada809c585fc4789324e5fe787eedc049 /src/Callback.c | |
parent | f8c7069a46af185e0bfaa43d63d450c9a44787ba (diff) |
Fix InternalCallbackRec layout if pointers are bigger than 64 bits
When running `xeyes` via `SSH -X` on CHERI-RISC-V FreeBSD, I was getting
a Bus Error (unaligned store) in the `cl->callback = callback;` line of
_XtAddCallback. The `cl` variable (created using `ToList(icl)`) was only
aligned to 8 bytes, but for CHERI-RISC-V pointer-type loads and stores
require 16-byte alignment.
In order to fix this, I added a C99 flexible array member to
internalCallbackRec when compiling for C99 or newer. This ensures
that sizeof(InternalCallbackRec) is 16 (since it now includes the
required 12 byte padding up to the first XtCallbackRec). This also
ensures that alignof(InternalCallbackRec) is 16, but that doesn't
matter in this case since malloc() will always return a
sufficiently-aligned pointer.
I also changed ToList(p) to use the flexible array member directly
when compiling for C99. This is not a functional change since it
will evaluate to the same pointer, but it does add additional type
checking and ensures that only a `InternalCallbackRec *` can be
passed to the macro.
Signed-off-by: Alex Richardson <Alexander.Richardson@cl.cam.ac.uk>
Diffstat (limited to 'src/Callback.c')
-rw-r--r-- | src/Callback.c | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/src/Callback.c b/src/Callback.c index 0c4ef5c..fa18436 100644 --- a/src/Callback.c +++ b/src/Callback.c @@ -80,7 +80,11 @@ static _Xconst _XtString XtNxtRemoveAllCallback = "xtRemoveAllCallback"; static _Xconst _XtString XtNxtCallCallback = "xtCallCallback"; /* However it doesn't contain a final NULL record */ +#if __STDC_VERSION__ >= 199901L +#define ToList(p) ((p)->callbacks) +#else #define ToList(p) ((XtCallbackList) ((p)+1)) +#endif static InternalCallbackList * FetchInternalList(Widget widget, |