OSDN Git Service

Fix alignment of buffer used for dm_ioctl.
authorDan Albert <danalbert@google.com>
Thu, 18 Dec 2014 18:00:55 +0000 (10:00 -0800)
committerDan Albert <danalbert@google.com>
Thu, 18 Dec 2014 18:24:23 +0000 (10:24 -0800)
Since the dm_ioctl struct was being allocated on the stack as a large
character array, it was getting character alignment rather than the
proper alignment for the struct. GCC had been getting away with this
so far, but it's undefined behavior that clang managed to expose.

Bug: 18736778
Change-Id: Ied275dfad7fcc41d712b2d02c8a185f499221f57

Android.mk
cryptfs.c

index f4ba3f3..f7e8170 100644 (file)
@@ -51,45 +51,49 @@ common_static_libraries := \
        libmincrypt \
        libbatteryservice
 
+vold_conlyflags := -std=c11
+vold_cflags := -Werror -Wall -Wno-missing-field-initializers
+
 include $(CLEAR_VARS)
 
 LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
 LOCAL_MODULE := libvold
-LOCAL_CLANG := false
+LOCAL_CLANG := true
 LOCAL_SRC_FILES := $(common_src_files)
 LOCAL_C_INCLUDES := $(common_c_includes)
 LOCAL_SHARED_LIBRARIES := $(common_shared_libraries)
 LOCAL_STATIC_LIBRARIES := $(common_static_libraries)
 LOCAL_MODULE_TAGS := eng tests
-LOCAL_CFLAGS := -Werror -Wall -Wno-missing-field-initializers
+LOCAL_CFLAGS := $(vold_cflags)
+LOCAL_CONLYFLAGS := $(vold_conlyflags)
 
-LOCAL_CXX_STL := libc++
 include $(BUILD_STATIC_LIBRARY)
 
 include $(CLEAR_VARS)
 
 LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
 LOCAL_MODULE:= vold
-LOCAL_CLANG := false
+LOCAL_CLANG := true
 LOCAL_SRC_FILES := \
        main.cpp \
        $(common_src_files)
 
 LOCAL_C_INCLUDES := $(common_c_includes)
-LOCAL_CFLAGS := -Werror -Wall -Wno-missing-field-initializers
+LOCAL_CFLAGS := $(vold_cflags)
+LOCAL_CONLYFLAGS := $(vold_conlyflags)
 LOCAL_SHARED_LIBRARIES := $(common_shared_libraries)
 LOCAL_STATIC_LIBRARIES := $(common_static_libraries)
 
-LOCAL_CXX_STL := libc++
 include $(BUILD_EXECUTABLE)
 
 include $(CLEAR_VARS)
 
 LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
-LOCAL_CLANG := false
+LOCAL_CLANG := true
 LOCAL_SRC_FILES:= vdc.c
 LOCAL_MODULE:= vdc
 LOCAL_SHARED_LIBRARIES := libcutils
-LOCAL_CFLAGS := -Werror -Wall -Wno-missing-field-initializers
+LOCAL_CFLAGS := $(vold_cflags)
+LOCAL_CONLYFLAGS := $(vold_conlyflags)
 
 include $(BUILD_EXECUTABLE)
index aefc606..aaa2b86 100644 (file)
--- a/cryptfs.c
+++ b/cryptfs.c
@@ -972,7 +972,7 @@ static int load_crypto_mapping_table(struct crypt_mnt_ftr *crypt_ftr, unsigned c
                                      char *real_blk_name, const char *name, int fd,
                                      char *extra_params)
 {
-  char buffer[DM_CRYPT_BUF_SIZE];
+  _Alignas(struct dm_ioctl) char buffer[DM_CRYPT_BUF_SIZE];
   struct dm_ioctl *io;
   struct dm_target_spec *tgt;
   char *crypt_params;