Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libdfu: pointer aliasing issues #208

Closed
ybernat opened this issue Aug 30, 2017 · 2 comments
Closed

libdfu: pointer aliasing issues #208

ybernat opened this issue Aug 30, 2017 · 2 comments

Comments

@ybernat
Copy link
Contributor

ybernat commented Aug 30, 2017

Compiling with clang, the following warnings appear for libdfu:

../thunderbolt_sw_2-fwupd/libdfu/dfu-cipher-xtea.c:102:17: warning: cast from 'guint8 *' (aka 'unsigned char *') to 'guint32 *' (aka 'unsigned int *') increases required alignment from 1 to 4 [-Wcast-align]
        guint32 *tmp = (guint32 *) data;
                       ^~~~~~~~~~~~~~~~
../thunderbolt_sw_2-fwupd/libdfu/dfu-cipher-xtea.c:144:17: warning: cast from 'guint8 *' (aka 'unsigned char *') to 'guint32 *' (aka 'unsigned int *') increases required alignment from 1 to 4 [-Wcast-align]
        guint32 *tmp = (guint32 *) data;
                       ^~~~~~~~~~~~~~~~
@hughsie
Copy link
Member

hughsie commented Aug 30, 2017

Do you know how to fix this without copying the data buf to a new array? I guess the proper thing to do would be to allocate a guint32 array big enough to hold data and then to memcpy the data over, although that seems mighty inefficient.

hughsie added a commit that referenced this issue Aug 30, 2017
…e chunks

Originally found as unaligned data by Yehezkel Bernat, many thanks.

Fixes: #208
@ybernat
Copy link
Contributor Author

ybernat commented Aug 30, 2017

  1. Is it expected that the data argument will be aligned in a way suitable for uint32? If so, you can just validate it by testing the address (but I'm not sure how to get the alignment of a type before C11 unless it's available as GNU extension in gcc).
  2. Seems like may_alias attribute supported by gcc is relevant (I assume gcc generates a safe code in this case if needed, e.g. when compiling for ARM).
    https://gcc.gnu.org/onlinedocs/gcc-7.2.0/gcc/Common-Type-Attributes.html#Common-Type-Attributes

hughsie added a commit that referenced this issue Aug 30, 2017
…e chunks

Originally found as unaligned data by Yehezkel Bernat, many thanks.

Fixes: #208
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants